In my model, if I have a field, that contains the id to another table, twice (like, primary associate and a secondary associate) I am specifying this as class Customer < ActiveRecord::Base belongs_to: associate :foreign_key => "associatekey1" belongs_to: associate :foreign_key => "associatekey2" end This doesn''t work -- but my question is how SHOULD the syntax for specifying this look? Thanks, Ralph --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ike wrote:> class Customer < ActiveRecord::Base > belongs_to: associate :foreign_key => "associatekey1" > belongs_to: associate :foreign_key => "associatekey2" > endOn the ruby-talk mailing list (where this question originated), Ike has stated that his belongs_to lines above are actually typos due to a from-memory manual re-typing of the code. The assumption is that s/he is using the correct syntax (properly placed colons and commas). --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Oct 31, 2006, at 2:16 PM, Ike wrote:> In my model, if I have a field, that contains the id to another > table, twice > (like, primary associate and a secondary associate) I am specifying > this as > > class Customer < ActiveRecord::Base > belongs_to: associate :foreign_key => "associatekey1" > belongs_to: associate :foreign_key => "associatekey2" > end > > This doesn''t work -- but my question is how SHOULD the syntax for > specifyingThe colons should appear at the start of the association name (the name is a symbol) rather than after belongs_to, you need a comma between the two arguments to belongs_to, and the two associations should have different names. class Customer < ActiveRecord::Base belongs_to :primary_associate, :foreign_key => "associatekey1" belongs_to :secondary_associate, :foreign_key => "associatekey2" end Take a look at the documentation for belongs_to at: http://rails.rubyonrails.org/classes/ActiveRecord/Associations/ ClassMethods.html#M000532 James. -- James Stewart : Web Developer Work : http://jystewart.net Play : http://james.anthropiccollective.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---