【发布时间】:2016-07-14 18:03:52
【问题描述】:
我在驱动表中定义了 has_one 关系
has_one :current_haul
它与运输表相关联。
以及 hauls table 和 drivers table,他们都有organization_id。
我想申请这样的条件
select *
from drivers
join hauls on drivers.organization_id=hauls.organization_id
and drivers.current_haul_id= hauls.id
我可以把这个条件放在has_one修饰符中吗?
【问题讨论】:
-
你检查过Active Record Associations docs吗?为了使其成为动态条件,您可以使用 this SO answer 中所示的 lambda。
标签: ruby-on-rails ruby-on-rails-4