[Nitro] Og: Custom selects
Michael Neumann
mneumann at ntecs.de
Thu Jun 16 10:01:08 EDT 2005
Am Thursday 16 June 2005 14:51 schrieb George Moschovitis:
> > Would be nice to have something like this:
> >
> > Customer.select {|s| s.category == 'Good' && s.name.like('Maier%') }
> >
> > This would create the SQL automatically for us:
> >
> > "SELECT * FROM #{Customer.table} WHERE category = 'Good' and name like
> > 'Maier%'"
>
> Hello Michael,
>
> this looks nice but I have no idea how to actually convert the block
> to an sql string. Any tips?
Take a look at the Criteria module on RAA. It's quite simple to implement. You
simply call the block with a builder object. The builder object then
intercepts the method calls (e.g. #category, #==) and builds SQL from this.
Eventually, the block returns the builder object which holds the SQL string.
Regards,
Michael
More information about the Nitro-general
mailing list