David Kahn
2010-Dec-09 15:53 UTC
Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
I am getting this error on an rspec test: undefined method `loaded?'' for #<Array:0x126a4c> When I call: Practice.includes("practice_members").all Practice has_many :practice_members PracticeMember belongs_to :practice Practice.all returns: [#<Practice id: 6, name: "Practice One", created_at: "2010-12-09 15:40:46", updated_at: "2010-12-09 15:40:46">] PracticeMember.all returns: #<PracticeMember id: 9, practice_id: 6, name_last: "Aaaaz", name_first: "Aaaba", name_middle: "Aaabb", created_at: "2010-12-09 15:40:46", updated_at: "2010-12-09 15:40:46">, #<PracticeMember id: 10, practice_id: 6, name_last: "Aaabc", name_first: "Aaabd", name_middle: "Aaabe", created_at: "2010-12-09 15:40:46", updated_at: "2010-12-09 15:40:46">] So the association on practice_id is correct on both practice members. It is unclear to me why this should be failing... am I missing something? Thanks, David -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ar Chron
2010-Dec-09 16:16 UTC
Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
David Kahn wrote in post #967449:> I am getting this error on an rspec test: > undefined method `loaded?'' for #<Array:0x126a4c> > > When I call: > Practice.includes("practice_members").all >You aren''t testing what you think you are... .all returns an array even if it only finds a single instance, and at last check, the Array class does not have a loaded? method. Should your test be using some other method, perhaps empty? -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Dec-09 17:07 UTC
Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
On Thu, Dec 9, 2010 at 10:16 AM, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> David Kahn wrote in post #967449: > > I am getting this error on an rspec test: > > undefined method `loaded?'' for #<Array:0x126a4c> > > > > When I call: > > Practice.includes("practice_members").all > > > > You aren''t testing what you think you are... > > .all returns an array even if it only finds a single instance, and at > last check, the Array class does not have a loaded? method. > > Should your test be using some other method, perhaps empty? >I think I see what you are saying, but I am expecting an array --- I am just asking for array#size. Method and test are copied below. The failing line is at the end of the test. The first line of the test calls the same method but it passes. I am not calling array#loaded, something in Rails must be doing so, which is where I am stuck: class Practice < ActiveRecord::Base def self.practice_members # global roster, no Demo Practice members included if PracticeMember.all.size>0 Practice.includes("practice_members").where("name<>''Demo Practice''").all else return [] end end end it "can get global practice member roster not including Demo Practice" do assert_equal Practice.practice_members.size, 0 # this passes fine practice_member = Factory.create(:practice_member) practice_member.practice_id = @practice.id practice_member.save practice_member = Factory.create(:practice_member) practice_member.practice_id = @practice.id practice_member.save assert_equal Practice.practice_members.size, 2 # this fails ... and note that Practice.all returns one record with id of "6" and PracticeMember.all returns two records with practice_id of "6" end> > -- > Posted via http://www.ruby-forum.com/. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Dec-09 17:20 UTC
Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
On 9 December 2010 17:07, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> > > On Thu, Dec 9, 2010 at 10:16 AM, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> David Kahn wrote in post #967449: >> > I am getting this error on an rspec test: >> > undefined method `loaded?'' for #<Array:0x126a4c> >> > >> > When I call: >> > Practice.includes("practice_members").all >> > >> >> You aren''t testing what you think you are... >> >> .all returns an array even if it only finds a single instance, and at >> last check, the Array class does not have a loaded? method. >> >> Should your test be using some other method, perhaps empty? > > I think I see what you are saying, but I am expecting an array --- I am just > asking for array#size. Method and test are copied below. The failing line > is at the end of the test. The first line of the test calls the same method > but it passes. I am not calling array#loaded, something in Rails must be > doing so, which is where I am stuck: > > class Practice < ActiveRecord::Base > def self.practice_membersIs it ok to provide a class method practice_members when there is already an instance method practice_members? Colin> # global roster, no Demo Practice members included > if PracticeMember.all.size>0 > Practice.includes("practice_members").where("name<>''Demo > Practice''").all > else > return [] > end > end > end > > > it "can get global practice member roster not including Demo Practice" do > assert_equal Practice.practice_members.size, 0 # this passes fine > > practice_member = Factory.create(:practice_member) > practice_member.practice_id = @practice.id > practice_member.save > practice_member = Factory.create(:practice_member) > practice_member.practice_id = @practice.id > practice_member.save > > assert_equal Practice.practice_members.size, 2 # this fails ... and note > that Practice.all returns one record with id of "6" and PracticeMember.all > returns two records with practice_id of "6" > end >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
David Kahn
2010-Dec-09 17:30 UTC
Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
On Thu, Dec 9, 2010 at 11:20 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 9 December 2010 17:07, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > > > > > > On Thu, Dec 9, 2010 at 10:16 AM, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> > >> David Kahn wrote in post #967449: > >> > I am getting this error on an rspec test: > >> > undefined method `loaded?'' for #<Array:0x126a4c> > >> > > >> > When I call: > >> > Practice.includes("practice_members").all > >> > > >> > >> You aren''t testing what you think you are... > >> > >> .all returns an array even if it only finds a single instance, and at > >> last check, the Array class does not have a loaded? method. > >> > >> Should your test be using some other method, perhaps empty? > > > > I think I see what you are saying, but I am expecting an array --- I am > just > > asking for array#size. Method and test are copied below. The failing > line > > is at the end of the test. The first line of the test calls the same > method > > but it passes. I am not calling array#loaded, something in Rails must be > > doing so, which is where I am stuck: > > > > class Practice < ActiveRecord::Base > > def self.practice_members > > Is it ok to provide a class method practice_members when there is > already an instance method practice_members? >From my understanding they are apples and oranges. But anyway I tried out changing PracticeMember.practice_members to PracticeMember.global_practice_members but still get the same error. By the way as far as documentation and explaining myself, I am a bit confused about the conventions for explaining class methods: I know that I can explain instance methods like: PracticeMember#practice_members --- is this correct, that this would refer to the instance and not the class method? But how do I explain the self.practice_members method? Would it be PracticeMember::practice_members (this looks wrong)> > Colin > > > # global roster, no Demo Practice members included > > if PracticeMember.all.size>0 > > Practice.includes("practice_members").where("name<>''Demo > > Practice''").all > > else > > return [] > > end > > end > > end > > > > > > it "can get global practice member roster not including Demo Practice" > do > > assert_equal Practice.practice_members.size, 0 # this passes fine > > > > practice_member = Factory.create(:practice_member) > > practice_member.practice_id = @practice.id > > practice_member.save > > practice_member = Factory.create(:practice_member) > > practice_member.practice_id = @practice.id > > practice_member.save > > > > assert_equal Practice.practice_members.size, 2 # this fails ... and > note > > that Practice.all returns one record with id of "6" and > PracticeMember.all > > returns two records with practice_id of "6" > > end > > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Dec-09 17:36 UTC
Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
On 9 December 2010 17:30, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> > > On Thu, Dec 9, 2010 at 11:20 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 9 December 2010 17:07, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: >> > >> > >> > On Thu, Dec 9, 2010 at 10:16 AM, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> >> >> David Kahn wrote in post #967449: >> >> > I am getting this error on an rspec test: >> >> > undefined method `loaded?'' for #<Array:0x126a4c> >> >> > >> >> > When I call: >> >> > Practice.includes("practice_members").all >> >> > >> >> >> >> You aren''t testing what you think you are... >> >> >> >> .all returns an array even if it only finds a single instance, and at >> >> last check, the Array class does not have a loaded? method. >> >> >> >> Should your test be using some other method, perhaps empty? >> > >> > I think I see what you are saying, but I am expecting an array --- I am >> > just >> > asking for array#size. Method and test are copied below. The failing >> > line >> > is at the end of the test. The first line of the test calls the same >> > method >> > but it passes. I am not calling array#loaded, something in Rails must be >> > doing so, which is where I am stuck: >> > >> > class Practice < ActiveRecord::Base >> > def self.practice_members >> >> Is it ok to provide a class method practice_members when there is >> already an instance method practice_members? > > From my understanding they are apples and oranges. But anyway I tried out > changing PracticeMember.practice_members to > PracticeMember.global_practice_members but still get the same error.I thought it might be worth trying. I wonder whether the stack trace might give someone a clue.> > By the way as far as documentation and explaining myself, I am a bit > confused about the conventions for explaining class methods: > > I know that I can explain instance methods like: > PracticeMember#practice_members --- is this correct, that this would refer > to the instance and not the class method? > > But how do I explain the self.practice_members method? Would it be > PracticeMember::practice_members (this looks wrong)Good questions. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
David Kahn
2010-Dec-09 22:15 UTC
Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
On Thu, Dec 9, 2010 at 11:36 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 9 December 2010 17:30, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > > > > > > On Thu, Dec 9, 2010 at 11:20 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > >> > >> On 9 December 2010 17:07, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > >> > > >> > > >> > On Thu, Dec 9, 2010 at 10:16 AM, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: > >> >> > >> >> David Kahn wrote in post #967449: > >> >> > I am getting this error on an rspec test: > >> >> > undefined method `loaded?'' for #<Array:0x126a4c> > >> >> > > >> >> > When I call: > >> >> > Practice.includes("practice_members").all > >> >> > > >> >> > >> >> You aren''t testing what you think you are... > >> >> > >> >> .all returns an array even if it only finds a single instance, and at > >> >> last check, the Array class does not have a loaded? method. > >> >> > >> >> Should your test be using some other method, perhaps empty? > >> > > >> > I think I see what you are saying, but I am expecting an array --- I > am > >> > just > >> > asking for array#size. Method and test are copied below. The failing > >> > line > >> > is at the end of the test. The first line of the test calls the same > >> > method > >> > but it passes. I am not calling array#loaded, something in Rails must > be > >> > doing so, which is where I am stuck: > >> > > >> > class Practice < ActiveRecord::Base > >> > def self.practice_members > >> > >> Is it ok to provide a class method practice_members when there is > >> already an instance method practice_members? > > > > From my understanding they are apples and oranges. But anyway I tried out > > changing PracticeMember.practice_members to > > PracticeMember.global_practice_members but still get the same error. > > I thought it might be worth trying. I wonder whether the stack trace > might give someone a clue. >Yeah... well this is a$$ kicking... now the weirdest part is I have an almost identical relation between Practice and User as I do between Practice and PracticeMember models, and Practice.includes("users").all .... give me love but Practice.includes("practice_members").all Tells me what I can do with my practice members... (does the backtrace below give anyone some idea).. so I know the issues is I am blind to something and not a problem with AR or Rails (is it ever?): ruby-1.9.2-p0 > Practice.includes("practice_members").all NoMethodError: undefined method `loaded?'' for #<Array:0x272aef0> from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:237:in `preload_has_many_association'' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:121:in `block in preload_one_association'' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:115:in `each'' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:115:in `preload_one_association'' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:92:in `preload_associations'' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/relation.rb:68:in `block in to_a'' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/relation.rb:68:in `each'' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/relation.rb:68:in `to_a'' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:143:in `all'' from (irb):65 from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'' from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'' from script/rails:6:in `require'' from script/rails:6:in `<main>'' Meanwhile I will continue to stare at the obvious :) David> > > > > By the way as far as documentation and explaining myself, I am a bit > > confused about the conventions for explaining class methods: > > > > I know that I can explain instance methods like: > > PracticeMember#practice_members --- is this correct, that this would > refer > > to the instance and not the class method? > > > > But how do I explain the self.practice_members method? Would it be > > PracticeMember::practice_members (this looks wrong) > > Good questions. > > Colin > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Dec-09 22:26 UTC
[SOLVED] Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
On Thu, Dec 9, 2010 at 4:15 PM, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org>wrote:> > > On Thu, Dec 9, 2010 at 11:36 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 9 December 2010 17:30, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: >> > >> > >> > On Thu, Dec 9, 2010 at 11:20 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> >> wrote: >> >> >> >> On 9 December 2010 17:07, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> >> wrote: >> >> > >> >> > >> >> > On Thu, Dec 9, 2010 at 10:16 AM, Ar Chron <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> >> wrote: >> >> >> >> >> >> David Kahn wrote in post #967449: >> >> >> > I am getting this error on an rspec test: >> >> >> > undefined method `loaded?'' for #<Array:0x126a4c> >> >> >> > >> >> >> > When I call: >> >> >> > Practice.includes("practice_members").all >> >> >> > >> >> >> >> >> >> You aren''t testing what you think you are... >> >> >> >> >> >> .all returns an array even if it only finds a single instance, and >> at >> >> >> last check, the Array class does not have a loaded? method. >> >> >> >> >> >> Should your test be using some other method, perhaps empty? >> >> > >> >> > I think I see what you are saying, but I am expecting an array --- I >> am >> >> > just >> >> > asking for array#size. Method and test are copied below. The failing >> >> > line >> >> > is at the end of the test. The first line of the test calls the same >> >> > method >> >> > but it passes. I am not calling array#loaded, something in Rails must >> be >> >> > doing so, which is where I am stuck: >> >> > >> >> > class Practice < ActiveRecord::Base >> >> > def self.practice_members >> >> >> >> Is it ok to provide a class method practice_members when there is >> >> already an instance method practice_members? >> > >> > From my understanding they are apples and oranges. But anyway I tried >> out >> > changing PracticeMember.practice_members to >> > PracticeMember.global_practice_members but still get the same error. >> >> I thought it might be worth trying. I wonder whether the stack trace >> might give someone a clue. >> > > Yeah... well this is a$$ kicking... now the weirdest part is I have an > almost identical relation between Practice and User as I do between Practice > and PracticeMember models, and > > Practice.includes("users").all > > .... give me love > > but > > > Practice.includes("practice_members").all > > Tells me what I can do with my practice members... (does the backtrace > below give anyone some idea).. so I know the issues is I am blind to > something and not a problem with AR or Rails (is it ever?): > > ruby-1.9.2-p0 > Practice.includes("practice_members").all > NoMethodError: undefined method `loaded?'' for #<Array:0x272aef0> > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:237:in > `preload_has_many_association'' > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:121:in > `block in preload_one_association'' > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:115:in > `each'' > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:115:in > `preload_one_association'' > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/association_preload.rb:92:in > `preload_associations'' > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/relation.rb:68:in > `block in to_a'' > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/relation.rb:68:in > `each'' > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/relation.rb:68:in > `to_a'' > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:143:in > `all'' > from (irb):65 > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in > `start'' > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in > `start'' > from /Users/DK/.rvm/gems/ruby-1.9.2-p0@wavelineup3/gems/railties-3.0.3/lib/rails/commands.rb:23:in > `<top (required)>'' > from script/rails:6:in `require'' > from script/rails:6:in `<main>'' > > > Meanwhile I will continue to stare at the obvious :) >Well doing this seemed to work. I am finding the hard way that I should ***always*** use the model name and not plural on the has_many. I had "has_many :practice_members" .... which seems like something that Rails at least tolerated in 2x and seems to accept in 3x *but* is just a false sense of security. Was it always that the has_many should be singular and I just created my own superstition? Anyhow, when I change it to "has_many :practice_member" Then I get my love: Practice.includes("practice_member").where("name<>''Demo Practice''").all => [#<Practice id: 2, name: "Davids Practice", created_at: "2010-12-09 21:44:32", updated_at: "2010-12-09 21:44:32">, #<Practice id: 3, name: "Donny''s Practice", created_at: "2010-12-09 21:52:37", updated_at: "2010-12-09 21:52:37">] So there. David> > David > > >> >> > >> > By the way as far as documentation and explaining myself, I am a bit >> > confused about the conventions for explaining class methods: >> > >> > I know that I can explain instance methods like: >> > PracticeMember#practice_members --- is this correct, that this would >> refer >> > to the instance and not the class method? >> > >> > But how do I explain the self.practice_members method? Would it be >> > PracticeMember::practice_members (this looks wrong) >> >> Good questions. >> >> Colin >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-09 22:41 UTC
Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c
David Kahn wrote in post #967538: [...]> I am finding the hard way that I should ***always*** use the model name > and > not plural on the has_many. > > I had "has_many :practice_members" .... which seems like something that > Rails at least tolerated in 2x and seems to accept in 3x *but* is just a > false sense of security. Was it always that the has_many should be > singular > and I just created my own superstition?No. has_many should always be plural. According to the docs, this has not changed in Rails 3. Have you been playing around with your inflector methods?> > Anyhow, when I change it to "has_many :practice_member" > > Then I get my love: > > Practice.includes("practice_member").where("name<>''Demo Practice''").all > => [#<Practice id: 2, name: "Davids Practice", created_at: "2010-12-09 > 21:44:32", updated_at: "2010-12-09 21:44:32">, #<Practice id: 3, name: > "Donny''s Practice", created_at: "2010-12-09 21:52:37", updated_at: > "2010-12-09 21:52:37">] > > So there.That makes no sense. has_many :singular shouldn''t even work.> > > DavidBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Dec-09 22:47 UTC
Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c
On Thu, Dec 9, 2010 at 4:41 PM, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> David Kahn wrote in post #967538: > [...] > > I am finding the hard way that I should ***always*** use the model name > > and > > not plural on the has_many. > > > > I had "has_many :practice_members" .... which seems like something that > > Rails at least tolerated in 2x and seems to accept in 3x *but* is just a > > false sense of security. Was it always that the has_many should be > > singular > > and I just created my own superstition? > > No. has_many should always be plural. According to the docs, this has > not changed in Rails 3. > > Have you been playing around with your inflector methods? >nope... generally never touch these> > > > > Anyhow, when I change it to "has_many :practice_member" > > > > Then I get my love: > > > > Practice.includes("practice_member").where("name<>''Demo Practice''").all > > => [#<Practice id: 2, name: "Davids Practice", created_at: "2010-12-09 > > 21:44:32", updated_at: "2010-12-09 21:44:32">, #<Practice id: 3, name: > > "Donny''s Practice", created_at: "2010-12-09 21:52:37", updated_at: > > "2010-12-09 21:52:37">] > > > > So there. > > That makes no sense. has_many :singular shouldn''t even work. >I know! Well, in Larry David''s words, at this point "Whatever works". I know that''s not a good answer, and now I have a new supersition: has_many >> NO plurals.> > > > > > > David > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-09 22:54 UTC
Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c
David Kahn wrote in post #967544:> On Thu, Dec 9, 2010 at 4:41 PM, Marnen Laibow-Koser > <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: > >> > and I just created my own superstition? >> >> No. has_many should always be plural. According to the docs, this has >> not changed in Rails 3. >> >> Have you been playing around with your inflector methods? >> > > nope... generally never touch these > > >> > "2010-12-09 21:52:37">] >> > >> > So there. >> >> That makes no sense. has_many :singular shouldn''t even work. >> > > I know! Well, in Larry David''s words, at this point "Whatever works". I > know > that''s not a good answer, and now I have a new supersition: has_many >> > NO > plurals.Superstitions have no place in software development. You know as well as I do that you need to find out what''s really going wrong... Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Dec-09 23:12 UTC
Re: Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c
On Thu, Dec 9, 2010 at 4:54 PM, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> David Kahn wrote in post #967544: > > On Thu, Dec 9, 2010 at 4:41 PM, Marnen Laibow-Koser > > <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: > > > >> > and I just created my own superstition? > >> > >> No. has_many should always be plural. According to the docs, this has > >> not changed in Rails 3. > >> > >> Have you been playing around with your inflector methods? > >> > > > > nope... generally never touch these > > > > > >> > "2010-12-09 21:52:37">] > >> > > >> > So there. > >> > >> That makes no sense. has_many :singular shouldn''t even work. > >> > > > > I know! Well, in Larry David''s words, at this point "Whatever works". I > > know > > that''s not a good answer, and now I have a new supersition: has_many >> > > NO > > plurals. > > Superstitions have no place in software development. You know as well > as I do that you need to find out what''s really going wrong... >Um... Im just in a gigantic skinner box most of the time> > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > -- > Posted via http://www.ruby-forum.com/. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Dec-10 09:56 UTC
Re: [SOLVED] Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
On 9 December 2010 22:26, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> [...] > Well doing this seemed to work. > > I am finding the hard way that I should ***always*** use the model name and > not plural on the has_many. > > I had "has_many :practice_members" .... which seems like something that > Rails at least tolerated in 2x and seems to accept in 3x *but* is just a > false sense of security. Was it always that the has_many should be singular > and I just created my own superstition?No, it should definitely be plural.> > Anyhow, when I change it to "has_many :practice_member" > > Then I get my love: > > Practice.includes("practice_member").where("name<>''Demo Practice''").all > => [#<Practice id: 2, name: "Davids Practice", created_at: "2010-12-09 > 21:44:32", updated_at: "2010-12-09 21:44:32">, #<Practice id: 3, name: > "Donny''s Practice", created_at: "2010-12-09 21:52:37", updated_at: > "2010-12-09 21:52:37">]Well I believe that it should not work like that. Perhaps you have found a bug. I haven''t used includes on Rails 3 yet, but I notice that the examples I can find use the symbol in the includes call, so Practice.includes(:practice_members) It might be worth trying that. Colin Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
David Kahn
2010-Dec-10 14:12 UTC
Re: [SOLVED] Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
On Fri, Dec 10, 2010 at 3:56 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 9 December 2010 22:26, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > > [...] > > Well doing this seemed to work. > > > > I am finding the hard way that I should ***always*** use the model name > and > > not plural on the has_many. > > > > I had "has_many :practice_members" .... which seems like something that > > Rails at least tolerated in 2x and seems to accept in 3x *but* is just a > > false sense of security. Was it always that the has_many should be > singular > > and I just created my own superstition? > > No, it should definitely be plural. >Ok, it is weird enough for me to spend some more time... possibly I am doing something wrong in two places and what I have is like a double negative or "two wrongs making a right".... I''ll report back.> > > > > Anyhow, when I change it to "has_many :practice_member" > > > > Then I get my love: > > > > Practice.includes("practice_member").where("name<>''Demo Practice''").all > > => [#<Practice id: 2, name: "Davids Practice", created_at: "2010-12-09 > > 21:44:32", updated_at: "2010-12-09 21:44:32">, #<Practice id: 3, name: > > "Donny''s Practice", created_at: "2010-12-09 21:52:37", updated_at: > > "2010-12-09 21:52:37">] > > Well I believe that it should not work like that. Perhaps you have found a > bug. > > I haven''t used includes on Rails 3 yet, but I notice that the examples > I can find use the symbol in the includes call, so > Practice.includes(:practice_members) > It might be worth trying that. > > Colin > > Colin > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Dec-10 15:49 UTC
Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
On Dec 10, 2:12 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> > Ok, it is weird enough for me to spend some more time... possibly I am doing > something wrong in two places and what I have is like a double negative or > "two wrongs making a right".... I''ll report back.Something is resulting in you having an array where you should have an association proxy. This would happen if you had an instance method you wrote with the same name as one of your associations (so changing the name of the association would change what''s happening because it would eliminate that collision) Fred> > > > > > > > Anyhow, when I change it to "has_many :practice_member" > > > > Then I get my love: > > > > Practice.includes("practice_member").where("name<>''Demo Practice''").all > > > => [#<Practice id: 2, name: "Davids Practice", created_at: "2010-12-09 > > > 21:44:32", updated_at: "2010-12-09 21:44:32">, #<Practice id: 3, name: > > > "Donny''s Practice", created_at: "2010-12-09 21:52:37", updated_at: > > > "2010-12-09 21:52:37">] > > > Well I believe that it should not work like that. Perhaps you have found a > > bug. > > > I haven''t used includes on Rails 3 yet, but I notice that the examples > > I can find use the symbol in the includes call, so > > Practice.includes(:practice_members) > > It might be worth trying that. > > > Colin > > > Colin > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib e@googlegroups.com> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
David Kahn
2010-Dec-10 22:21 UTC
Re: Re: Rails 3 Active Record query returns "undefined method `loaded?'' for #<Array:0x126a4c>"
On Fri, Dec 10, 2010 at 9:49 AM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Dec 10, 2:12 pm, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > > > > Ok, it is weird enough for me to spend some more time... possibly I am > doing > > something wrong in two places and what I have is like a double negative > or > > "two wrongs making a right".... I''ll report back. > > Something is resulting in you having an array where you should have an > association proxy. This would happen if you had an instance method you > wrote with the same name as one of your associations (so changing the > name of the association would change what''s happening because it would > eliminate that collision) > >Thanks, I think you are right. What I did was move the method to a more appropriate model in addition to renaming. I had tried renaming yesterday but maybe I missed something.> Fred > > > > > > > > > > > > > > > > Anyhow, when I change it to "has_many :practice_member" > > > > > > Then I get my love: > > > > > > Practice.includes("practice_member").where("name<>''Demo > Practice''").all > > > > => [#<Practice id: 2, name: "Davids Practice", created_at: > "2010-12-09 > > > > 21:44:32", updated_at: "2010-12-09 21:44:32">, #<Practice id: 3, > name: > > > > "Donny''s Practice", created_at: "2010-12-09 21:52:37", updated_at: > > > > "2010-12-09 21:52:37">] > > > > > Well I believe that it should not work like that. Perhaps you have > found a > > > bug. > > > > > I haven''t used includes on Rails 3 yet, but I notice that the examples > > > I can find use the symbol in the includes call, so > > > Practice.includes(:practice_members) > > > It might be worth trying that. > > > > > Colin > > > > > Colin > > > > > -- > > > 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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.