ActiveRecord destroy has_many :through record from relational table

ActiveRecord destroy has_many :through record from relational table

物流和租赁请求通过 TypeLogistic table 属于彼此。我不小心创建了一个错误的 TypeLogistic,所以现在有两个:

TypeLogistic.where(rental_request_id:200).where(logistic_id:130)
=> #<ActiveRecord::Relation [#<TypeLogistic rental_request_id: 200, logistic_id: 130, type_of_logistics: nil>, #<TypeLogistic rental_request_id: 200, logistic_id: 130, type_of_logistics: "delivery">]>

如何销毁第一个?尝试了下面的 运行,没有用

TypeLogistic.where(rental_request_id:200).where(logistic_id:130).first.destroy
PG::Error: ERROR:  zero-length delimited identifier at or near """"
LINE 1: DELETE FROM "type_logistics" WHERE "type_logistics"."" = 
                                                            ^

错误被抛出是因为 TypeLogistic 连接 table 没有主键。顺便说一句,这是它出现的默认设置,因为我按照说明创建了连接 table 而没有改变任何东西。

详细信息在这里:Rails Devise PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"

解决方案?添加主键,请参阅下面的答案:

Add Id column in a migration