Q on ActiveRecord syntax

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

Ike wrote:

class Customer < ActiveRecord::Base
belongs_to: associate :foreign_key => “associatekey1”
belongs_to: associate :foreign_key => “associatekey2”
end

On 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).

On Oct 31, 2006, at 2:16 PM, Ike wrote:

This doesn’t work – but my question is how SHOULD the syntax for
specifying

The 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 S. : Web D.
Work : http://jystewart.net
Play : http://james.anthropiccollective.org