ruby on rails - Eager loading with conditions -


The new style of eager load uses many queries to load the association. Is it possible to add conditions to those extra curious loading queries? For example

bakery.fund (: all ,: included = & gt;: beaker)

will produce such an anxious loading query:

Select bakers . FROM bakers WHERE ( bakers .bakery_id IN (1,2,3,4,5)) <

Update: To make it clear (maybe), I want to repeat that query. AR (without SQL):

SELECT * FROM bakeries LEFT JOIN bakers

code> I was hoping to be able to modify the second curious loaded SQL statement: < / P>

Select bakers . * To bakers WHERE ( beaker .bakery_id IN (1,2,3,4,5) and bakers .hat = 'on')

Is it possible, or should I use SQL? Just looking for "Rail" way to it. :)

OK, do you want to change specifically related queries?

You can certainly do something like this:

  Bakery. Search (: all ,: included = & gt;: beaker, terms = & gt; ["bakers.something =?", True])  

If we had a bit more information , Then there may be a better way to do this. Depending on what you are looking for, you can see it from named_scope , which you can unify, like:

  bakery.bakers Available  

named_scope is very clean.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -