Rails - 删除交集表 habtm 中的单个记录
我有一个 habtm 关系(作业 <指派候选人>候选人)
我希望能够从作业中删除一名候选人。 这是到目前为止我的代码
@assignment = Assignment.find(:first,
:joins => :candidates,
:select => "assignments_candidates.*",
:conditions => ["assignments_candidates.candidate_id = ? AND assignments_candidates.assignment_id = ?",
params[:candidate_id], params[:assignment_id]]
)
@assignment.destroy
目前我认为这只是破坏对象而不是交集表中的记录
有什么想法吗?
谢谢,亚历克斯
I have a habtm relationship (assignments < assignments_candidates > candidates)
I want to be able to delete one candidate off an assignment.
here is my code so far
@assignment = Assignment.find(:first,
:joins => :candidates,
:select => "assignments_candidates.*",
:conditions => ["assignments_candidates.candidate_id = ? AND assignments_candidates.assignment_id = ?",
params[:candidate_id], params[:assignment_id]]
)
@assignment.destroy
At the moment all i think this does is destroy the object not the record in the intersection table
any ideas ?
Thanks, Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是我的做法,以供将来参考。
Here is how I did it for future reference.
您是否添加了
:dependent =>; :destroy
限定符到关联模型的has_many
(或has_and_belongs_to_many
)关系?Have you added a
:dependent => :destroy
qualifier to thehas_many
(orhas_and_belongs_to_many
) relationships the associated models?