【发布时间】:2016-03-11 20:37:16
【问题描述】:
我刚刚添加了一个新模型Intent 来保存有关想要购买我们产品和服务的用户的信息。
所以我将Product、Service 和User 的ID 保存在此表intent 中。
我创建了一个迁移来引用 Intent 中的外键,然后添加了以下关联
belongs_to :user
has_one :product
has_one :service
我希望 Rails 在 Intent 中搜索 product_id 和 service_id,但情况正好相反:
Mysql2::Error:“where 子句”中的未知列“products.intent_id”: ...
我该如何解决?我是否选择了错误的关联类型?
【问题讨论】:
-
为什么不属于产品/服务?为什么has_one?
标签: ruby-on-rails ruby-on-rails-4 rails-activerecord