ruby - Rails active record query with multiple associations -
i have tables called users
, orders
, , delivery_times
linked using following relationship.
for table user
:
belongs_to :orders
for table orders
:
belongs_to :delivery_times
i want write query on table users using condition on table delivery_times shown:
user.includes(order: :delivery_time).where("delivery_times.start < ?",time.now)
pg::undefinedtable: error: missing from-clause entry table "delivery_times"
however error. can use ror orm make query work using includes, though know there solution using joins?
you need join kind of query, since need joint knowledge of delivery_times
table , users
table.
what includes
decides between preload
, eager_load
automatically , tries take better one. in case eager_load
; have article.
for error get, guess yould result starting users
, not user
:
user.includes(order: :delivery_time).where("delivery_times.start < ?",time.now)
everything else seems correct me.
Comments
Post a Comment