Hi all, I''m trying to use STI (single table inheritance) with has_many :through, and I''m getting a NameError: uninitialized constant. Details below. Presumably I''ve set up the relationship incorrectly? Any help would be greatly appreciated! I have the following models: class Activity < ActiveRecord::Base has_many :memberships has_many :members, :through => :memberships class Branch < Activity class Member < ActiveRecord::Base has_many :memberships has_many :activities, :through => :memberships class Memberships < ActiveRecord::Base belongs_to :members belongs_to :activities I''m trying to run the following test (the activity fixture I''m testing is a branch): class ActivityTest < Test::Unit::TestCase fixtures :activities, :members, :memberships # Replace this with your real tests. def test_has_member assert_equal activities(:bristol).members.empty?, false end end and it''s failing with: NameError: uninitialized constant Activity::Membership --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-Apr-07 00:45 UTC
Re: STI and has_many :through not playing nicely
Tom Taylor wrote:> class Memberships < ActiveRecord::Base > > belongs_to :members > belongs_to :activitiesYou want belongs_to :member belongs_to :activity -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 7 Apr, 01:45, Mark Reginald James <m...-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> You want > > belongs_to :member > belongs_to :activityThanks Mark, but I still get the same error. Any more suggestions? Cheers, Tom --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mark Reginald James
2007-Apr-07 09:24 UTC
Re: STI and has_many :through not playing nicely
Tom Taylor wrote:> On 7 Apr, 01:45, Mark Reginald James <m...-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote: >> You want >> >> belongs_to :member >> belongs_to :activity > > Thanks Mark, but I still get the same error. Any more suggestions?Yes, it should also be "class Membership" rather than "class Memberships". -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ 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 7 Apr, 10:24, Mark Reginald James <m...-bzGI/hKkdgQnC9Muvcwxkw@public.gmane.org> wrote:> Yes, it should also be "class Membership" rather than "class Memberships".Thanks, but alas, the same result... Cheers, Tom --~--~---------~--~----~------------~-------~--~----~ 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 7 Apr, 10:35, "Tom Taylor" <scrap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks, but alas, the same result...The full stack trace is: 1) Error: test_has_member(ActivityTest): NameError: uninitialized constant Activity::Membership /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/ dependencies.rb:477:in `const_missing'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ base.rb:1360:in `compute_type'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ reflection.rb:125:in `klass'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ reflection.rb:177:in `source_reflection'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ reflection.rb:177:in `source_reflection'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ reflection.rb:186:in `check_validity!'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ associations/has_many_through_association.rb:6:in `initialize'' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/ associations.rb:934:in `members'' ./test/unit/activity_test.rb:7:in `test_has_member'' --~--~---------~--~----~------------~-------~--~----~ 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 7 Apr, 10:39, "Tom Taylor" <scrap...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The full stack trace is:Doh! I hadn''t renamed memberships.rb to membership.rb. All fixed, thanks Mark! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---