I have this simple model with orders and products. Orders looks like this: class Order < ActiveRecord::Base has_many :orders_products, :foreign_key => :order_id has_many :products, :through => :orders_products has_many :priority_products, :through => :orders_products, :source => :product, :conditions => { "orders_products.priority" => true } end The :condition on :priority_products is cause problems for me. It worked fine in Rails 2.0.2, but breaks in Rails 2.1.1 when putting the relation in a :include clause: orders = Order.find(:all, :include => :priority_products) This result in PostgreSQL saying: missing FROM-clause entry for table "orders_products" for this malformed query: SELECT * FROM "products" WHERE ("products"."id" IN (1,2,3) AND ("orders_products"."priority" = ''t'')) Full working example: http://pastie.org/299592 Is this something that should work, or am I making some mistake? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 24, 12:36 pm, Lars Christensen <lar...-FAevfmC8fLL3w1pmW36iTg@public.gmane.org> wrote:> I have this simple model with orders and products. Orders looks like > this: > > class Order < ActiveRecord::Base > has_many :orders_products, :foreign_key => :order_id > has_many :products, :through => :orders_products > has_many :priority_products, :through => :orders_products, :source > => :product, :conditions => { "orders_products.priority" => true } > end > > The :condition on :priority_products is cause problems for me. It > worked fine in Rails 2.0.2, but breaks in Rails 2.1.1 when putting the > relation in a :include clause: > > orders = Order.find(:all, :include => :priority_products)This is a problem with 2.1''s implementation of eager loading. You should be able to force a fallback to the old code by adding something like :conditions => "some trivial condition on the priority_products or orders_products table") Fred> > This result in PostgreSQL saying: missing FROM-clause entry for table > "orders_products" > > for this malformed query: > > SELECT * FROM "products" WHERE ("products"."id" IN (1,2,3) AND > ("orders_products"."priority" = ''t'')) > > Full working example:http://pastie.org/299592 > > Is this something that should work, or am I making some mistake?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > orders = Order.find(:all, :include => :priority_products) > > This is a problem with 2.1''s implementation of eager loading. You > should be able to force a fallback to the old code by adding something > like :conditions => "some trivial condition on the priority_products > or orders_products table")Thanks, this sovled the immediate problem. Will I need this workaround with future version of Rails or is it something being looked at? Rgds, Lars --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Oct 2008, at 14:45, Lars Christensen wrote:> >>> orders = Order.find(:all, :include => :priority_products) >> >> This is a problem with 2.1''s implementation of eager loading. You >> should be able to force a fallback to the old code by adding >> something >> like :conditions => "some trivial condition on the priority_products >> or orders_products table") > > Thanks, this sovled the immediate problem. Will I need this workaround > with future version of Rails or is it something being looked at? >I don''t think 2.2 will be any different. I did have plans to look at it but got side tracked and didn''t get it finished. Fred> Rgds, > Lars > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> > I don''t think 2.2 will be any different. I did have plans to look at > it but got side tracked and didn''t get it finished.Does anyone know if there are any plans to allow conditions to be specified that are applied to the ON clause of a join ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 28 Oct 2008, at 13:44, Andrew Porter wrote:> > Frederick Cheung wrote: >> >> I don''t think 2.2 will be any different. I did have plans to look at >> it but got side tracked and didn''t get it finished. > > Does anyone know if there are any plans to allow conditions to be > specified that are applied to the ON clause of a join ?you can do that anyway - :joins accepts arbitrary sql fragments. Fred> > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---