The application I'm working on is going to allow for the import of contacts from a variety of services. It will be possible to send invitations to these contacts. These contacts can then come to the site and sign up to become users.
In order to avoid the validations and other such nonsense that is placed on my user model, I have created a Contact model. This means that we're dealing with a contact model, a user model, and a join table that links Users to either contacts or other users:
class Contact < ActiveRecord::Base
has_many :user_contacts, :as => :contactable
has_many :users, :through => :user_contacts
end
class UserContact < ActiveRecord::Base
belongs_to :contactable, :polymorphic => true
belongs_to :user
end
And this terrifying abomination:
class User < ActiveRecord::Base
has_many :user_contacts
has_many :contactable_contacts, :foreign_key => 'contactable_id', :class_name => 'UserContact', :as => :contactable
has_many :contactables, :through => :user_contacts
end
I'm going to just make two join tables for now, but I really feel like this behavior shouldn't be all that difficult to pull off. Can anyone offer me any feedback?
Thanks in advance.