0

is_leaderRails アプリケーションでは、関連付けテーブルの名前を付けた新しい列を追加する必要がありました。

関連テーブルの関係は次のとおりです。

has_and_belongs_to_many :analysis_responses, :join_table => "analysis_responses_participants"

以下は、参加者の詳細がデータベースに保存されたコードです。

organization.people.create(participant)

participant次の値を持っています

name: Test User
position: 
birthdate: 
id: 
lead: "1"

先頭の値が 1 の場合、is_leader列の値は1特定のレコードのものである必要があります。

is_leaderその関連テーブルの値をレールに保存する方法を知りたかった

ありがとう

4

1 に答える 1

1

結合テーブルに属性を保存する必要がある場合は、HABTMの代わりに結合モデルを使用する必要があります。

class Organization
  has_many :analysis_responses
  has_many :people, through: :analysis_responses
end

class AnalysisResponse
  belongs_to :organization
  belongs_to :person
end

class Person
  has_many :analysis_responses
  has_many :organizations, through: :analysis_reponses
end
于 2012-12-05T06:42:48.407 に答える