Rails - has_many有不同的列名?

时间:2018-03-21 14:49:38

标签: ruby-on-rails ruby relationship

我有一个数据模型 - 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_1season_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)}

1 个答案:

答案 0 :(得分:1)

您需要为关系指定yarn install,并为每个键指定单独的关系。像:

foreign_key