Topic: Two Foreign Keys within one table, referencing the same table
I have a properties table that references the users table. So far, no problem. However, there are two types of users that can have a relationship to each property: an owner and an agent (in charge of the sale). At present, I have a setup like this:
So the Property class looks like this:
class Property < ActiveRecord::Base
belongs_to :user, :foreign_key => "agent_id"
belongs_to :user, :foreign_key => "owner_id"
And the User class:
class User < ActiveRecord::Base
I want to be able to use the method
But my current setup doesn't activate this method, so I have to establish the link by hand. Is there a way to enable the has_many relationship when the FK is a duplicate of another, pointing to the same table?