我有一个Item可以是ItemType. 有ItemType一个attribute要么true要么false。
Class Item
belongs_to :item_type
end
Class ItemType
has_many :items
end
目前,我只是x以通常的方式抓取最后一个对象:
latest_items = Item.last(x)
现在,我需要返回一个列表,x Items其中列出ItemType了attributeset to的位置true,如下所示(伪代码):
latest_items = Item.last(x).where(Item.item_type.attribute = "true")
这在 Rails 中很容易实现吗?似乎它应该是直截了当的,但我正在四处寻找,无法找到解决方案