Hi, Found a simple example breaking on moving to 2.2 from 2.0. This example illustrates the usage of nested :include finder options. class Book < ActiveRecord::Base has_many :distributors end class Distributor < ActiveRecord::Base belongs_to :book has_many :agents end class Agent < ActiveRecord::Base belongs_to :distributor has_many :shops end class Shop < ActiveRecord::Base belongs_to :agent end Schema - http://pastie.org/426261 def test_should_load_avatars shop_1= Shop.create! shop_2= Shop.create! book= Book.create!(:distributors => [Distributor.create!(:agents=> [Agent.create!(:shops => [shop_2, shop_2])])]) loaded_version = Book.find(book.id, :include => [:distributors => {:agents => :shops}], :order => ''shops.id'') assert(loaded_version.distributors.first.agents.first.shops.size =2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 end On some investigation, I found that the query fired was correct, but Rails was unable to instantiate the ''shops'' collection properly. Any help on this issue would be appreciated. Thanks --~--~---------~--~----~------------~-------~--~----~ 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
2009-Mar-25 09:04 UTC
Re: ActiveRecord: Nested :include erroneous behavior
On Mar 25, 5:19 am, Akshay Rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> def test_should_load_avatars > shop_1= Shop.create! > shop_2= Shop.create! > book= Book.create!(:distributors => [Distributor.create!(:agents=> > [Agent.create!(:shops => [shop_2, shop_2])])]) > > loaded_version = Book.find(book.id, :include => [:distributors => > {:agents => :shops}], :order => ''shops.id'') > > assert(loaded_version.distributors.first.agents.first.shops.size => 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > end > > On some investigation, I found that the query fired was correct, but > Rails was unable to instantiate the ''shops'' collection properly. >The problem is not to do with the nested-ness of the includes but because you have an agent with the same shop twice (the line in question that removes duplicates is http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297adec0ae3/activerecord/lib/active_record/associations.rb#L1781 Fred> Any help on this issue would be appreciated. > > Thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
akshay.rawat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Mar-25 13:45 UTC
Re: ActiveRecord: Nested :include erroneous behavior
Bad paste. The problem again. Looks like it is a problem only when there is a has_one relationship. class Book < ActiveRecord::Base has_one :distributor end class Distributor < ActiveRecord::Base belongs_to :book has_many :agents end class Agent < ActiveRecord::Base belongs_to :distributor has_many :shops end class Shop < ActiveRecord::Base belongs_to :agent end Schema - http://pastie.org/426261 def test_should_load_avatars shop_1= Shop.create! shop_2= Shop.create! book= Book.create!(:distributor => Distributor.create!(:agents=> [Agent.create!(:shops => [shop_1, shop_2])])) loaded_version = Book.find(book.id, :include => [:distributor => {:agents => :shops}], :order => ''shops.id'') assert(loaded_version.distributor.agents.first.shops.size == 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 end This fails on Rails 2.2.2. Any help on this would be much appreciated, Akshay On Mar 25, 2009 4:04am, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 25, 5:19 am, Akshay Rawat akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > def test_should_load_avatars> > shop_1= Shop.create!> > shop_2= Shop.create!> > book= Book.create!(:distributors => [Distributor.create!(:agents=>> > [Agent.create!(:shops => [shop_2, shop_2])])])> >> > loaded_version = Book.find(book.id, :include => [:distributors =>> > {:agents => :shops}], :order => ''shops.id'')> >> > assert(loaded_version.distributors.first.agents.first.shops.size = > > 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2> > end> >> > On some investigation, I found that the query fired was correct, but> > Rails was unable to instantiate the ''shops'' collection properly.> >> The problem is not to do with the nested-ness of the includes but> because you have an agent with the same shop twice (the line in> question that removes duplicates is> http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297adec0ae3/activerecord/lib/active_record/associations.rb#L1781> Fred> > Any help on this issue would be appreciated.> >> > Thanks>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Created a ticket for this issue at - http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2341 On Wed, Mar 25, 2009 at 9:45 AM, <akshay.rawat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Bad paste. The problem again. Looks like it is a problem only when there is > a has_one relationship. > > class Book < ActiveRecord::Base > has_one :distributor > end > > class Distributor < ActiveRecord::Base > belongs_to :book > has_many :agents > end > > class Agent < ActiveRecord::Base > belongs_to :distributor > has_many :shops > end > > class Shop < ActiveRecord::Base > belongs_to :agent > end > > Schema - http://pastie.org/426261 > > def test_should_load_avatars > shop_1= Shop.create! > shop_2= Shop.create! > book= Book.create!(:distributor => Distributor.create!(:agents=> > [Agent.create!(:shops => [shop_1, shop_2])])) > > > loaded_version = Book.find(book.id, :include => [:distributor => {:agents > => :shops}], :order => ''shops.id'') > > assert(loaded_version.distributor.agents.first.shops.size == 2) > #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > end > > This fails on Rails 2.2.2. > Any help on this would be much appreciated, > Akshay > > On Mar 25, 2009 4:04am, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > > > > > > > > > On Mar 25, 5:19 am, Akshay Rawat akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > def test_should_load_avatars > > > > > shop_1= Shop.create! > > > > > shop_2= Shop.create! > > > > > book= Book.create!(:distributors => [Distributor.create!(:agents=> > > > > > [Agent.create!(:shops => [shop_2, shop_2])])]) > > > > > > > > > > loaded_version = Book.find(book.id, :include => [:distributors => > > > > > {:agents => :shops}], :order => ''shops.id'') > > > > > > > > > > assert(loaded_version.distributors.first.agents.first.shops.size => > > > > 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > > > > > end > > > > > > > > > > On some investigation, I found that the query fired was correct, but > > > > > Rails was unable to instantiate the ''shops'' collection properly. > > > > > > > > > The problem is not to do with the nested-ness of the includes but > > > > because you have an agent with the same shop twice (the line in > > > > question that removes duplicates is > > > > > http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297adec0ae3/activerecord/lib/active_record/associations.rb#L1781 > > > > > > > > Fred > > > > > > > > > Any help on this issue would be appreciated. > > > > > > > > > > Thanks > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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
2009-Mar-25 18:05 UTC
Re: ActiveRecord: Nested :include erroneous behavior
On Mar 25, 1:45 pm, akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Bad paste. The problem again. Looks like it is a problem only when there is > a has_one relationship. >Do you need all these models/associations or is there a small test case that fails ? Fred> class Book < ActiveRecord::Base > has_one :distributor > end > > class Distributor < ActiveRecord::Base > belongs_to :book > has_many :agents > end > > class Agent < ActiveRecord::Base > belongs_to :distributor > has_many :shops > end > > class Shop < ActiveRecord::Base > belongs_to :agent > end > > Schema -http://pastie.org/426261 > > def test_should_load_avatars > shop_1= Shop.create! > shop_2= Shop.create! > book= Book.create!(:distributor => Distributor.create!(:agents=> > [Agent.create!(:shops => [shop_1, shop_2])])) > > loaded_version = Book.find(book.id, :include => [:distributor => {:agents > => :shops}], :order => ''shops.id'') > > assert(loaded_version.distributor.agents.first.shops.size == 2) > #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > end > > This fails on Rails 2.2.2. > Any help on this would be much appreciated, > Akshay > > On Mar 25, 2009 4:04am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Mar 25, 5:19 am, Akshay Rawat akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > def test_should_load_avatars > > > shop_1= Shop.create! > > > shop_2= Shop.create! > > > book= Book.create!(:distributors => [Distributor.create!(:agents=> > > > [Agent.create!(:shops => [shop_2, shop_2])])]) > > > > loaded_version = Book.find(book.id, :include => [:distributors => > > > {:agents => :shops}], :order => ''shops.id'') > > > > assert(loaded_version.distributors.first.agents.first.shops.size => > > 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > > > end > > > > On some investigation, I found that the query fired was correct, but > > > Rails was unable to instantiate the ''shops'' collection properly. > > > The problem is not to do with the nested-ness of the includes but > > because you have an agent with the same shop twice (the line in > > question that removes duplicates is > >http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297ad... > > Fred > > > Any help on this issue would be appreciated. > > > > Thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for looking at it.A one file test - http://pastie.org/426840 Another thing I saw was that the that test passes when :include is replaced with :joins. On Wed, Mar 25, 2009 at 2:05 PM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Mar 25, 1:45 pm, akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > Bad paste. The problem again. Looks like it is a problem only when there > is > > a has_one relationship. > > > Do you need all these models/associations or is there a small test > case that fails ? > > Fred > > class Book < ActiveRecord::Base > > has_one :distributor > > end > > > > class Distributor < ActiveRecord::Base > > belongs_to :book > > has_many :agents > > end > > > > class Agent < ActiveRecord::Base > > belongs_to :distributor > > has_many :shops > > end > > > > class Shop < ActiveRecord::Base > > belongs_to :agent > > end > > > > Schema -http://pastie.org/426261 > > > > def test_should_load_avatars > > shop_1= Shop.create! > > shop_2= Shop.create! > > book= Book.create!(:distributor => Distributor.create!(:agents=> > > [Agent.create!(:shops => [shop_1, shop_2])])) > > > > loaded_version = Book.find(book.id, :include => [:distributor => > {:agents > > => :shops}], :order => ''shops.id'') > > > > assert(loaded_version.distributor.agents.first.shops.size == 2) > > #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > > end > > > > This fails on Rails 2.2.2. > > Any help on this would be much appreciated, > > Akshay > > > > On Mar 25, 2009 4:04am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On Mar 25, 5:19 am, Akshay Rawat akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > def test_should_load_avatars > > > > shop_1= Shop.create! > > > > shop_2= Shop.create! > > > > book= Book.create!(:distributors => [Distributor.create!(:agents=> > > > > [Agent.create!(:shops => [shop_2, shop_2])])]) > > > > > > loaded_version = Book.find(book.id, :include => [:distributors => > > > > {:agents => :shops}], :order => ''shops.id'') > > > > > > assert(loaded_version.distributors.first.agents.first.shops.size => > > > 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > > > > end > > > > > > On some investigation, I found that the query fired was correct, but > > > > Rails was unable to instantiate the ''shops'' collection properly. > > > > > The problem is not to do with the nested-ness of the includes but > > > because you have an agent with the same shop twice (the line in > > > question that removes duplicates is > > >http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297ad. > .. > > > Fred > > > > Any help on this issue would be appreciated. > > > > > > Thanks > > >--~--~---------~--~----~------------~-------~--~----~ 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
2009-Mar-25 18:49 UTC
Re: ActiveRecord: Nested :include erroneous behavior
On Mar 25, 6:39 pm, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for looking at it.A one file test -http://pastie.org/426840 > > Another thing I saw was that the that test passes when :include is replaced > with :joins.Not surprising - in that case the association isn''t eager loaded at all. If it passes without the order clause then you''ve narrowed it down to the joins based include mechanism. Fred> > On Wed, Mar 25, 2009 at 2:05 PM, Frederick Cheung < > > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Mar 25, 1:45 pm, akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > Bad paste. The problem again. Looks like it is a problem only when there > > is > > > a has_one relationship. > > > Do you need all these models/associations or is there a small test > > case that fails ? > > > Fred > > > class Book < ActiveRecord::Base > > > has_one :distributor > > > end > > > > class Distributor < ActiveRecord::Base > > > belongs_to :book > > > has_many :agents > > > end > > > > class Agent < ActiveRecord::Base > > > belongs_to :distributor > > > has_many :shops > > > end > > > > class Shop < ActiveRecord::Base > > > belongs_to :agent > > > end > > > > Schema -http://pastie.org/426261 > > > > def test_should_load_avatars > > > shop_1= Shop.create! > > > shop_2= Shop.create! > > > book= Book.create!(:distributor => Distributor.create!(:agents=> > > > [Agent.create!(:shops => [shop_1, shop_2])])) > > > > loaded_version = Book.find(book.id, :include => [:distributor => > > {:agents > > > => :shops}], :order => ''shops.id'') > > > > assert(loaded_version.distributor.agents.first.shops.size == 2) > > > #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > > > end > > > > This fails on Rails 2.2.2. > > > Any help on this would be much appreciated, > > > Akshay > > > > On Mar 25, 2009 4:04am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > > On Mar 25, 5:19 am, Akshay Rawat akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > def test_should_load_avatars > > > > > shop_1= Shop.create! > > > > > shop_2= Shop.create! > > > > > book= Book.create!(:distributors => [Distributor.create!(:agents=> > > > > > [Agent.create!(:shops => [shop_2, shop_2])])]) > > > > > > loaded_version = Book.find(book.id, :include => [:distributors => > > > > > {:agents => :shops}], :order => ''shops.id'') > > > > > > assert(loaded_version.distributors.first.agents.first.shops.size => > > > > 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > > > > > end > > > > > > On some investigation, I found that the query fired was correct, but > > > > > Rails was unable to instantiate the ''shops'' collection properly. > > > > > The problem is not to do with the nested-ness of the includes but > > > > because you have an agent with the same shop twice (the line in > > > > question that removes duplicates is > > > >http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297ad. > > .. > > > > Fred > > > > > Any help on this issue would be appreciated. > > > > > > Thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yup, it passes without the :order option, indicating that there is a problem with the join based mechanism. Thanks On Wed, Mar 25, 2009 at 2:49 PM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Mar 25, 6:39 pm, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Thanks for looking at it.A one file test -http://pastie.org/426840 > > > > Another thing I saw was that the that test passes when :include is > replaced > > with :joins. > > Not surprising - in that case the association isn''t eager loaded at > all. If it passes without the order clause then you''ve narrowed it > down to the joins based include mechanism. > > Fred > > > > On Wed, Mar 25, 2009 at 2:05 PM, Frederick Cheung < > > > > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Mar 25, 1:45 pm, akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > > Bad paste. The problem again. Looks like it is a problem only when > there > > > is > > > > a has_one relationship. > > > > > Do you need all these models/associations or is there a small test > > > case that fails ? > > > > > Fred > > > > class Book < ActiveRecord::Base > > > > has_one :distributor > > > > end > > > > > > class Distributor < ActiveRecord::Base > > > > belongs_to :book > > > > has_many :agents > > > > end > > > > > > class Agent < ActiveRecord::Base > > > > belongs_to :distributor > > > > has_many :shops > > > > end > > > > > > class Shop < ActiveRecord::Base > > > > belongs_to :agent > > > > end > > > > > > Schema -http://pastie.org/426261 > > > > > > def test_should_load_avatars > > > > shop_1= Shop.create! > > > > shop_2= Shop.create! > > > > book= Book.create!(:distributor => Distributor.create!(:agents=> > > > > [Agent.create!(:shops => [shop_1, shop_2])])) > > > > > > loaded_version = Book.find(book.id, :include => [:distributor => > > > {:agents > > > > => :shops}], :order => ''shops.id'') > > > > > > assert(loaded_version.distributor.agents.first.shops.size == 2) > > > > #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > > > > end > > > > > > This fails on Rails 2.2.2. > > > > Any help on this would be much appreciated, > > > > Akshay > > > > > > On Mar 25, 2009 4:04am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > > > > wrote: > > > > > > > On Mar 25, 5:19 am, Akshay Rawat akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > def test_should_load_avatars > > > > > > shop_1= Shop.create! > > > > > > shop_2= Shop.create! > > > > > > book= Book.create!(:distributors => > [Distributor.create!(:agents=> > > > > > > [Agent.create!(:shops => [shop_2, shop_2])])]) > > > > > > > > loaded_version = Book.find(book.id, :include => [:distributors > => > > > > > > {:agents => :shops}], :order => ''shops.id'') > > > > > > > > assert(loaded_version.distributors.first.agents.first.shops.size > => > > > > > 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > > > > > > end > > > > > > > > On some investigation, I found that the query fired was correct, > but > > > > > > Rails was unable to instantiate the ''shops'' collection properly. > > > > > > > The problem is not to do with the nested-ness of the includes but > > > > > because you have an agent with the same shop twice (the line in > > > > > question that removes duplicates is > > > > > > http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297ad. > > > .. > > > > > Fred > > > > > > Any help on this issue would be appreciated. > > > > > > > > Thanks > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
So is this a valid Rails bug ? Should I create a ticket for it on Lighthouse ? On Wed, Mar 25, 2009 at 3:02 PM, akshay rawat <akshay.rawat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Yup, it passes without the :order option, indicating that there is a > problem with the join based mechanism. Thanks > > > On Wed, Mar 25, 2009 at 2:49 PM, Frederick Cheung < > frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> >> >> On Mar 25, 6:39 pm, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Thanks for looking at it.A one file test -http://pastie.org/426840 >> > >> > Another thing I saw was that the that test passes when :include is >> replaced >> > with :joins. >> >> Not surprising - in that case the association isn''t eager loaded at >> all. If it passes without the order clause then you''ve narrowed it >> down to the joins based include mechanism. >> >> Fred >> > >> > On Wed, Mar 25, 2009 at 2:05 PM, Frederick Cheung < >> > >> > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> > > On Mar 25, 1:45 pm, akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >> > > > Bad paste. The problem again. Looks like it is a problem only when >> there >> > > is >> > > > a has_one relationship. >> > >> > > Do you need all these models/associations or is there a small test >> > > case that fails ? >> > >> > > Fred >> > > > class Book < ActiveRecord::Base >> > > > has_one :distributor >> > > > end >> > >> > > > class Distributor < ActiveRecord::Base >> > > > belongs_to :book >> > > > has_many :agents >> > > > end >> > >> > > > class Agent < ActiveRecord::Base >> > > > belongs_to :distributor >> > > > has_many :shops >> > > > end >> > >> > > > class Shop < ActiveRecord::Base >> > > > belongs_to :agent >> > > > end >> > >> > > > Schema -http://pastie.org/426261 >> > >> > > > def test_should_load_avatars >> > > > shop_1= Shop.create! >> > > > shop_2= Shop.create! >> > > > book= Book.create!(:distributor => Distributor.create!(:agents=> >> > > > [Agent.create!(:shops => [shop_1, shop_2])])) >> > >> > > > loaded_version = Book.find(book.id, :include => [:distributor => >> > > {:agents >> > > > => :shops}], :order => ''shops.id'') >> > >> > > > assert(loaded_version.distributor.agents.first.shops.size == 2) >> > > > #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 >> > > > end >> > >> > > > This fails on Rails 2.2.2. >> > > > Any help on this would be much appreciated, >> > > > Akshay >> > >> > > > On Mar 25, 2009 4:04am, Frederick Cheung < >> frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> > > wrote: >> > >> > > > > On Mar 25, 5:19 am, Akshay Rawat akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > > > > > def test_should_load_avatars >> > > > > > shop_1= Shop.create! >> > > > > > shop_2= Shop.create! >> > > > > > book= Book.create!(:distributors => >> [Distributor.create!(:agents=> >> > > > > > [Agent.create!(:shops => [shop_2, shop_2])])]) >> > >> > > > > > loaded_version = Book.find(book.id, :include => [:distributors >> => >> > > > > > {:agents => :shops}], :order => ''shops.id'') >> > >> > > > > > assert(loaded_version.distributors.first.agents.first.shops.size >> =>> > > > > > 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 >> > > > > > end >> > >> > > > > > On some investigation, I found that the query fired was correct, >> but >> > > > > > Rails was unable to instantiate the ''shops'' collection properly. >> > >> > > > > The problem is not to do with the nested-ness of the includes but >> > > > > because you have an agent with the same shop twice (the line in >> > > > > question that removes duplicates is >> > > > > >> http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297ad. >> > > .. >> > > > > Fred >> > > > > > Any help on this issue would be appreciated. >> > >> > > > > > Thanks >> >> >> >--~--~---------~--~----~------------~-------~--~----~ 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
2009-Mar-25 22:24 UTC
Re: ActiveRecord: Nested :include erroneous behavior
On Mar 25, 10:01 pm, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So is this a valid Rails bug ? Should I create a ticket for it on Lighthouse > ?Seems like you already have :-). I''d definitely check against 2.3.2 - I remember there being a fix for a :include bug somewhere. Fred> > On Wed, Mar 25, 2009 at 3:02 PM, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > > > Yup, it passes without the :order option, indicating that there is a > > problem with the join based mechanism. Thanks > > > On Wed, Mar 25, 2009 at 2:49 PM, Frederick Cheung < > > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> On Mar 25, 6:39 pm, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > Thanks for looking at it.A one file test -http://pastie.org/426840 > > >> > Another thing I saw was that the that test passes when :include is > >> replaced > >> > with :joins. > > >> Not surprising - in that case the association isn''t eager loaded at > >> all. If it passes without the order clause then you''ve narrowed it > >> down to the joins based include mechanism. > > >> Fred > > >> > On Wed, Mar 25, 2009 at 2:05 PM, Frederick Cheung < > > >> > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > > On Mar 25, 1:45 pm, akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > >> > > > Bad paste. The problem again. Looks like it is a problem only when > >> there > >> > > is > >> > > > a has_one relationship. > > >> > > Do you need all these models/associations or is there a small test > >> > > case that fails ? > > >> > > Fred > >> > > > class Book < ActiveRecord::Base > >> > > > has_one :distributor > >> > > > end > > >> > > > class Distributor < ActiveRecord::Base > >> > > > belongs_to :book > >> > > > has_many :agents > >> > > > end > > >> > > > class Agent < ActiveRecord::Base > >> > > > belongs_to :distributor > >> > > > has_many :shops > >> > > > end > > >> > > > class Shop < ActiveRecord::Base > >> > > > belongs_to :agent > >> > > > end > > >> > > > Schema -http://pastie.org/426261 > > >> > > > def test_should_load_avatars > >> > > > shop_1= Shop.create! > >> > > > shop_2= Shop.create! > >> > > > book= Book.create!(:distributor => Distributor.create!(:agents=> > >> > > > [Agent.create!(:shops => [shop_1, shop_2])])) > > >> > > > loaded_version = Book.find(book.id, :include => [:distributor => > >> > > {:agents > >> > > > => :shops}], :order => ''shops.id'') > > >> > > > assert(loaded_version.distributor.agents.first.shops.size == 2) > >> > > > #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > >> > > > end > > >> > > > This fails on Rails 2.2.2. > >> > > > Any help on this would be much appreciated, > >> > > > Akshay > > >> > > > On Mar 25, 2009 4:04am, Frederick Cheung < > >> frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> > > wrote: > > >> > > > > On Mar 25, 5:19 am, Akshay Rawat akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > > > > > def test_should_load_avatars > >> > > > > > shop_1= Shop.create! > >> > > > > > shop_2= Shop.create! > >> > > > > > book= Book.create!(:distributors => > >> [Distributor.create!(:agents=> > >> > > > > > [Agent.create!(:shops => [shop_2, shop_2])])]) > > >> > > > > > loaded_version = Book.find(book.id, :include => [:distributors > >> => > >> > > > > > {:agents => :shops}], :order => ''shops.id'') > > >> > > > > > assert(loaded_version.distributors.first.agents.first.shops.size > >> => >> > > > > > 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > >> > > > > > end > > >> > > > > > On some investigation, I found that the query fired was correct, > >> but > >> > > > > > Rails was unable to instantiate the ''shops'' collection properly. > > >> > > > > The problem is not to do with the nested-ness of the includes but > >> > > > > because you have an agent with the same shop twice (the line in > >> > > > > question that removes duplicates is > > >>http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297ad. > >> > > .. > >> > > > > Fred > >> > > > > > Any help on this issue would be appreciated. > > >> > > > > > Thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Just checked, this test fails on Rails 2.3.2 too. Thanks for looking into it. On Wed, Mar 25, 2009 at 6:24 PM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Mar 25, 10:01 pm, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > So is this a valid Rails bug ? Should I create a ticket for it on > Lighthouse > > ? > > Seems like you already have :-). I''d definitely check against 2.3.2 - > I remember there being a fix for a :include bug somewhere. > > Fred > > > > On Wed, Mar 25, 2009 at 3:02 PM, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > >wrote: > > > > > Yup, it passes without the :order option, indicating that there is a > > > problem with the join based mechanism. Thanks > > > > > On Wed, Mar 25, 2009 at 2:49 PM, Frederick Cheung < > > > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > >> On Mar 25, 6:39 pm, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > Thanks for looking at it.A one file test -http://pastie.org/426840 > > > > >> > Another thing I saw was that the that test passes when :include is > > >> replaced > > >> > with :joins. > > > > >> Not surprising - in that case the association isn''t eager loaded at > > >> all. If it passes without the order clause then you''ve narrowed it > > >> down to the joins based include mechanism. > > > > >> Fred > > > > >> > On Wed, Mar 25, 2009 at 2:05 PM, Frederick Cheung < > > > > >> > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > >> > > On Mar 25, 1:45 pm, akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > >> > > > Bad paste. The problem again. Looks like it is a problem only > when > > >> there > > >> > > is > > >> > > > a has_one relationship. > > > > >> > > Do you need all these models/associations or is there a small test > > >> > > case that fails ? > > > > >> > > Fred > > >> > > > class Book < ActiveRecord::Base > > >> > > > has_one :distributor > > >> > > > end > > > > >> > > > class Distributor < ActiveRecord::Base > > >> > > > belongs_to :book > > >> > > > has_many :agents > > >> > > > end > > > > >> > > > class Agent < ActiveRecord::Base > > >> > > > belongs_to :distributor > > >> > > > has_many :shops > > >> > > > end > > > > >> > > > class Shop < ActiveRecord::Base > > >> > > > belongs_to :agent > > >> > > > end > > > > >> > > > Schema -http://pastie.org/426261 > > > > >> > > > def test_should_load_avatars > > >> > > > shop_1= Shop.create! > > >> > > > shop_2= Shop.create! > > >> > > > book= Book.create!(:distributor => Distributor.create!(:agents=> > > >> > > > [Agent.create!(:shops => [shop_1, shop_2])])) > > > > >> > > > loaded_version = Book.find(book.id, :include => [:distributor > => > > >> > > {:agents > > >> > > > => :shops}], :order => ''shops.id'') > > > > >> > > > assert(loaded_version.distributor.agents.first.shops.size == 2) > > >> > > > #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 > > >> > > > end > > > > >> > > > This fails on Rails 2.2.2. > > >> > > > Any help on this would be much appreciated, > > >> > > > Akshay > > > > >> > > > On Mar 25, 2009 4:04am, Frederick Cheung < > > >> frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > >> > > wrote: > > > > >> > > > > On Mar 25, 5:19 am, Akshay Rawat akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > >> > > > > > def test_should_load_avatars > > >> > > > > > shop_1= Shop.create! > > >> > > > > > shop_2= Shop.create! > > >> > > > > > book= Book.create!(:distributors => > > >> [Distributor.create!(:agents=> > > >> > > > > > [Agent.create!(:shops => [shop_2, shop_2])])]) > > > > >> > > > > > loaded_version = Book.find(book.id, :include => > [:distributors > > >> => > > >> > > > > > {:agents => :shops}], :order => ''shops.id'') > > > > >> > > > > > > assert(loaded_version.distributors.first.agents.first.shops.size > > >> => > >> > > > > > 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF > 2 > > >> > > > > > end > > > > >> > > > > > On some investigation, I found that the query fired was > correct, > > >> but > > >> > > > > > Rails was unable to instantiate the ''shops'' collection > properly. > > > > >> > > > > The problem is not to do with the nested-ness of the includes > but > > >> > > > > because you have an agent with the same shop twice (the line > in > > >> > > > > question that removes duplicates is > > > > >>http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297ad. > > >> > > .. > > >> > > > > Fred > > >> > > > > > Any help on this issue would be appreciated. > > > > >> > > > > > Thanks > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The ticket is at https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2341-nested-finder-include-option-with-has_one#ticket-2341-4 Not sure how the ticket assignment thing works ;) Thanks On Wed, Mar 25, 2009 at 6:43 PM, akshay rawat <akshay.rawat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Just checked, this test fails on Rails 2.3.2 too. > Thanks for looking into it. > > > On Wed, Mar 25, 2009 at 6:24 PM, Frederick Cheung < > frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> >> >> On Mar 25, 10:01 pm, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > So is this a valid Rails bug ? Should I create a ticket for it on >> Lighthouse >> > ? >> >> Seems like you already have :-). I''d definitely check against 2.3.2 - >> I remember there being a fix for a :include bug somewhere. >> >> Fred >> > >> > On Wed, Mar 25, 2009 at 3:02 PM, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >> >wrote: >> > >> > > Yup, it passes without the :order option, indicating that there is a >> > > problem with the join based mechanism. Thanks >> > >> > > On Wed, Mar 25, 2009 at 2:49 PM, Frederick Cheung < >> > > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> > >> On Mar 25, 6:39 pm, akshay rawat <akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> > Thanks for looking at it.A one file test -http://pastie.org/426840 >> > >> > >> > Another thing I saw was that the that test passes when :include is >> > >> replaced >> > >> > with :joins. >> > >> > >> Not surprising - in that case the association isn''t eager loaded at >> > >> all. If it passes without the order clause then you''ve narrowed it >> > >> down to the joins based include mechanism. >> > >> > >> Fred >> > >> > >> > On Wed, Mar 25, 2009 at 2:05 PM, Frederick Cheung < >> > >> > >> > frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > >> > >> > > On Mar 25, 1:45 pm, akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >> > >> > > > Bad paste. The problem again. Looks like it is a problem only >> when >> > >> there >> > >> > > is >> > >> > > > a has_one relationship. >> > >> > >> > > Do you need all these models/associations or is there a small >> test >> > >> > > case that fails ? >> > >> > >> > > Fred >> > >> > > > class Book < ActiveRecord::Base >> > >> > > > has_one :distributor >> > >> > > > end >> > >> > >> > > > class Distributor < ActiveRecord::Base >> > >> > > > belongs_to :book >> > >> > > > has_many :agents >> > >> > > > end >> > >> > >> > > > class Agent < ActiveRecord::Base >> > >> > > > belongs_to :distributor >> > >> > > > has_many :shops >> > >> > > > end >> > >> > >> > > > class Shop < ActiveRecord::Base >> > >> > > > belongs_to :agent >> > >> > > > end >> > >> > >> > > > Schema -http://pastie.org/426261 >> > >> > >> > > > def test_should_load_avatars >> > >> > > > shop_1= Shop.create! >> > >> > > > shop_2= Shop.create! >> > >> > > > book= Book.create!(:distributor => >> Distributor.create!(:agents=> >> > >> > > > [Agent.create!(:shops => [shop_1, shop_2])])) >> > >> > >> > > > loaded_version = Book.find(book.id, :include => [:distributor >> => >> > >> > > {:agents >> > >> > > > => :shops}], :order => ''shops.id'') >> > >> > >> > > > assert(loaded_version.distributor.agents.first.shops.size == 2) >> > >> > > > #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD OF 2 >> > >> > > > end >> > >> > >> > > > This fails on Rails 2.2.2. >> > >> > > > Any help on this would be much appreciated, >> > >> > > > Akshay >> > >> > >> > > > On Mar 25, 2009 4:04am, Frederick Cheung < >> > >> frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> > >> > > wrote: >> > >> > >> > > > > On Mar 25, 5:19 am, Akshay Rawat akshay.ra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> wrote: >> > >> > > > > > def test_should_load_avatars >> > >> > > > > > shop_1= Shop.create! >> > >> > > > > > shop_2= Shop.create! >> > >> > > > > > book= Book.create!(:distributors => >> > >> [Distributor.create!(:agents=> >> > >> > > > > > [Agent.create!(:shops => [shop_2, shop_2])])]) >> > >> > >> > > > > > loaded_version = Book.find(book.id, :include => >> [:distributors >> > >> => >> > >> > > > > > {:agents => :shops}], :order => ''shops.id'') >> > >> > >> > > > > > >> assert(loaded_version.distributors.first.agents.first.shops.size >> > >> =>> > >> > > > > > 2) #THIS ASSERTION FAILS WITH SHOPS.SIZE BEING 1, INSTEAD >> OF 2 >> > >> > > > > > end >> > >> > >> > > > > > On some investigation, I found that the query fired was >> correct, >> > >> but >> > >> > > > > > Rails was unable to instantiate the ''shops'' collection >> properly. >> > >> > >> > > > > The problem is not to do with the nested-ness of the includes >> but >> > >> > > > > because you have an agent with the same shop twice (the line >> in >> > >> > > > > question that removes duplicates is >> > >> > >>http://github.com/rails/rails/blob/f97832b1e4406a76d268a96b521d2297ad >> . >> > >> > > .. >> > >> > > > > Fred >> > >> > > > > > Any help on this issue would be appreciated. >> > >> > >> > > > > > Thanks >> >> >> >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---