【发布时间】:2015-10-08 22:45:36
【问题描述】:
物流和租赁请求通过 TypeLogistic 表相互关联。我不小心创建了一个错误的 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"."" = $1
^
【问题讨论】:
-
为什么不直接
TypeLogistic.find_by(rental_request_id: 200).destroy? -
嗯,这看起来像是 AREL 错误,除非您的架构发生了真正奇怪的事情。
-
所以...我搞砸了?有没有其他方法可以解决这个问题?
标签: ruby-on-rails ruby activerecord has-many-through