【发布时间】:2019-08-04 19:46:32
【问题描述】:
我有两个班级:
class Customer
has_many :packages
end
class Package
belongs_to :customer
end
如何进行这样的查询?
Customer.includes(:packages).where(packages: 'expires_at < Date.current')
通过控制台的示例测试,我得到了它:Customer Load (26.0ms) SELECT "customers".* FROM "customers" INNER JOIN "packages" ON "packages"."customer_id" = "customers"."id" WHERE (packages.expires_at < '2019-03-13') LIMIT $1 [["LIMIT", 11]]
Traceback (most recent call last):
ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR: operator does not exist: integer = uuid)
LINE 1: ...INNER JOIN "packages" ON "packages"."customer_id" = "custome...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT "customers".* FROM "customers" INNER JOIN "packages" ON "packages"."customer_id" = "customers"."id" WHERE (packages.expires_at < '2019-03-13') LIMIT $1
irb(main):003:0>
【问题讨论】:
-
已解决。我的客户迁移是
create_table :customers, id: :uuid do |t|,我添加了一个类型::uuid,如下:create_table :customers, id: :uuid, type: :uuid do |t|
标签: ruby-on-rails ruby postgresql rails-activerecord