Reputation: 282
I am wondering if it is possible to have the following situation: I have a person object that has both an attribute called email and a foreign key called email which is realized as a has_many relationship. The latter is supposed to contain not only the primary email but also secondary ones. Would this cause conflict when I invoke @person.email? What would be the standard way to work around this? Thanks.
Upvotes: 0
Views: 115
Reputation: 8954
Create a secound field that could be used as a foreign key and then in the associated model add :foreign_key => 'your_foreign_key'
as aparameter to the existing association like this:
has_many :email_addresses, :class_name => 'ClassName', :foreign_key => 'your_foreign_key'
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html <-- Documentation about that.
Upvotes: 1