简体   繁体   English

删除联接表记录时出错

[英]Error deleting a join table record

I have a join table named favorites . 我有一个名为favorites的联接表。 It doesn't have a single auto incrementing id. 它没有单个自动递增ID。 It uses both user_id and doctor_id . 它同时使用user_iddoctor_id

My issue is when trying to delete this record. 我的问题是尝试删除此记录时。 On Rails 5.0 and 5.1 it throws the following error. 在Rails 5.0和5.1上,它将引发以下错误。

favorite = Favorite.first
=> #<Favorite:0x007fe8b1546bf8 user_id: 3, doctor_id: 2, created_at: Wed, 19 Apr 2017 03:37:10 UTC +00:00, updated_at: Wed, 19 Apr 2017 03:37:10 UTC +00:00>
favorite.delete
NoMethodError: undefined method `to_sym' for nil:NilClass

Am I supposed to be deleting this record some other way or is this a bug? 我是否应该以其他方式删除此记录,或者这是一个错误?

This is a known rails issue. 这是一个已知的rails问题。 You can find out more detail here . 您可以在此处找到更多详细信息

You have to add primary key in intermediate table check here 你必须在中间表检查添加主键在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM