You should use HABTM for collaborators and has_many
for founders, not the other way around.
The reason is the relationship between collaborators and apps is many-to-many, while the relationship between founders and apps is one-to-many.
/app/models/app.rb
Class App < ActiveRecord::Base
belongs_to :founder, :class_name => 'Developer'
has_and_belongs_to_many :collaborators, :class_name => 'Developer'
end
/app/models/developer.rb
Class Developer < ActiveRecord::Base
has_many :apps, :foreign_key => :founder_id
has_and_belongs_to_many :apps, :foreign_key => :collaborator_id
end
As for your second question, this is how you can add a collaborator to an app:
app.collaborators << developer
Where app
is an object of the App
class and developer
is an object of the Developer
class.