users、projects、project_editor_links の合計 3 つのテーブルが必要です。
あなたの移行:
create_table :users do |t|
# user stuff
end
create_table :projects do |t|
t.references :user
# project stuff
end
create_table :project_editor_links |t|
t.references :user
t.references :project
end
コマンドラインから最後のテーブルを生成するには:
rails g migration project_editor_links project:references user:references
モデルは次のようになります。
class User < ActiveRecord::Base
has_many :projects
has_many :project_editor_links
has_many :edited_projects, :through => :project_editor_links
end
class Project < ActiveRecord::Base
belongs_to :user
has_many :project_editor_links
has_many :editors, :through => :project_editor_links
end
class ProjectEditorLinks < ActiveRecord::Base
belongs_to :editor, :class_name => 'User', :foreign_key => :user_id
belongs_to :edited_project, :class_name => 'Project', :foreign_key => :project_id
end