У меня есть два класса:
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>