Hi all, Struggling with the case of one type with two refs to another type: Type has_many :attributes Attribute belongs_to :owner, :foreign_key => "owner_id", :class_name = "Type" has_one :type When I type.attributes << attribute it goes in the owner_id column. I can''t find any examples of this on the web, looking for any hints. Thanks, Todd --~--~---------~--~----~------------~-------~--~----~ 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 Apr 9, 4:06 pm, Todd Chambery <todd.chamb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > Struggling with the case of one type with two refs to another type: > > Type > has_many :attributes > > Attribute > belongs_to :owner, :foreign_key => "owner_id", :class_name = "Type" > has_one :type > > When I > > type.attributes << attribute > > it goes in the owner_id column.!!! This should say: "it goes in the type_id column" !!!> I can''t find any examples of this on the web, looking for any hints. > > Thanks, > > Todd--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Todd Chambery wrote:> !!! This should say: "it goes in the type_id > column" !!!You need to tell the has_many relationship about the foreign key, too: has_many :attributes, :foreign_key => :owner_id It''s one of the quirks of Rails, unfortunately. Also, I''d be wary of using "Type" for anything to do with an ActiveRecord model. If you start getting strange errors, then have a look here: http://wiki.rubyonrails.org/rails/pages/ReservedWords -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Yeah, type is used by Single Table Inheritance. Julian Learn Ruby on Rails! Check out the FREE VIDS (for a limited time) VIDEO #3 out NOW! http://sensei.zenunit.com/ On 10/04/2008, at 6:30 AM, Mark Bush wrote:> > Todd Chambery wrote: >> !!! This should say: "it goes in the type_id >> column" !!! > > You need to tell the has_many relationship about the foreign key, too: > > has_many :attributes, :foreign_key => :owner_id > > It''s one of the quirks of Rails, unfortunately. > > Also, I''d be wary of using "Type" for anything to do with an > ActiveRecord model. If you start getting strange errors, then have a > look here: > > http://wiki.rubyonrails.org/rails/pages/ReservedWords > > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Thank you, thank you (both)! Changed my names to Entity and Attrib (I think attribute is also reserved). Never would have figured out the :foreign_key business on my own. Thanks again, Todd On Apr 9, 7:45 pm, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote:> Yeah, type is used by Single Table Inheritance. > > Julian > > Learn Ruby on Rails! Check out the FREE VIDS (for a limited time) > VIDEO #3 out NOW!http://sensei.zenunit.com/ > > On 10/04/2008, at 6:30 AM, Mark Bush wrote: > > > > > Todd Chambery wrote: > >> !!! This should say: "it goes in the type_id > >> column" !!! > > > You need to tell the has_many relationship about the foreign key, too: > > > has_many :attributes, :foreign_key => :owner_id > > > It''s one of the quirks of Rails, unfortunately. > > > Also, I''d be wary of using "Type" for anything to do with an > > ActiveRecord model. If you start getting strange errors, then have a > > look here: > > >http://wiki.rubyonrails.org/rails/pages/ReservedWords > > > -- > > Posted viahttp://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-/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 -~----------~----~----~----~------~----~------~--~---