我有一个数据模型 - SeasonTeams
,其关系如下:
has_many :linked_team_constraints, class_name: 'LinkedTeamConstraints', dependent: :destroy
然后我有LinkedTeamConstraints
模型如下:
belongs_to :season_team, primary_key: :_id
现在,当我在destroy
上致电SeasonTeam
时 - 从而摧毁LinkedTeamConstraint
- 我收到错误column linked_team_constraints.season_team_id does not exist
。我做有两个标有season_team_id_1
和season_team_id_2
的其他列。如何建立has_many关系,以便查询linked_team_constraints.season_team_id_1
或..._id_2
而不是...season_team_id
。
会是这样的:
has_many :linked_team_constraints... {where("_id == ?", linked_team_constraints.season_team_id_1 || linked_team_constraints.season_team_id_2)}
?
答案 0 :(得分:1)
您需要为关系指定yarn install
,并为每个键指定单独的关系。像:
foreign_key