私は次の:has_many :through
関係を持っています。
協会
class Profile < ActiveRecord::Base
has_many :teams
has_many :projects, :class_name => "Project", :through => :teams
has_many :leads, :class_name => "Projects"
class Project < ActiveRecord::Base
has_many :teams
has_many :developers, :class_name => "Profile", :through => :teams
belongs_to :lead, :class_name => "Profile", :foreign_key => "developer_lead"
class Team < ActiveRecord::Base
belongs_to :developer, :class_name => "Profile"
belongs_to :project
プロファイル プロジェクトを取得しようとすると、関係がチーム テーブルで正しいキーを使用しません。
レールC
1.9.3p194 :001 > Profile.first.projects
Profile Load (0.2ms) SELECT "profiles".* FROM "profiles" LIMIT 1
Project Load (0.2ms) SELECT "projects".* FROM "projects" INNER JOIN "teams" ON "projects"."id" = "teams "."project_id" WHERE "チーム"."profile_id" = 1
使用する必要があります"teams"."developer_id" = 1
:foreign_key => "developer_id"
Profile モデルと Project モデルの両方でa を使用してみましたが、何も機能しないようです。
私が行ってきたモデルへの変更は何の効果も得ていないように感じますが、変更するたびに Rails コンソールを再起動しています。
スキーマ
create_table "profiles", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "projects", :force => true do |t|
t.integer "developer_lead"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "teams", :id => false, :force => true do |t|
t.integer "developer_id"
t.integer "project_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end