I use sanitize_sql all the time.  But that's not what I meant.  Let me
illustrate:

Product.get_sql_of {Product.find(:conditions => 'cost < 3')}
# => 'SELECT * FROM products WHERE cost < 3'

It's easy for that case, but for complicated finders, and especially
custom finder methods (eg Product.find_on_sale), it can be very
helpful, if you want to make more powerful queries and reports.

An rough example might be taking a method Product.find_on_sale and
writing a metaquery to let us know who bought any of those items, or
some stats on the top selling all items.

On May 18, 5:06 pm, Hongli Lai <[EMAIL PROTECTED]> wrote:
> On May 18, 10:04 pm, "S. Robert James" <[EMAIL PROTECTED]> wrote:
>
> > A lot of plugins would be easier if there was a way, instead of
> > executing a find, to get the SQL it would use as a String (or perhaps
> > an array of a string and bind variables).
>
> > This would make it easier to do a lot of powerful queries at the
> > database, while still taking advantage of Rails' to manage the basic
> > structure.  Make it easier to DRY up some of those tough finder
> > methods.
>
> > Any way of doing this?  What are others' thoughts about the utility of
> > this?
>
> I've been working on ActiveRecord patches this week so I know a bit
> about its internals. The function you want is
> ActiveRecord::Base.sanitize_sql(). Given a find()-condition-like
> parameter (such as ['foo = ?', bar], {:foo => :bar}, and things like
> that) it will return a piece of SQL.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to