【发布时间】:2021-08-24 23:28:20
【问题描述】:
我有两个具有 belongs_to 和 has_many 关系的模型。 BreedCycle 具有breed_start_date 日期时间属性。我想做的是通过最新(最后创建的)品种周期的breed_start_date 属性订购boxes。长话短说,我的目标是编写查询,通过breed_cycles.breed_start_date 属性为盒子和订单盒子提取所有最新的品种循环。 breed_start_date 也可以为零,所以我需要 NULLS LAST 选项。非常感谢任何帮助(文档链接、示例等)。
class Box < ApplicationRecord
has_many :breed_cycles
end
class BreedCycle < ApplicationRecord
belongs_to :box
end
【问题讨论】: