Elegantly selecting attributes from has_many :through join models in Rails

前端 未结 4 632
春和景丽
春和景丽 2021-02-06 14:51

I\'m wondering what the easiest/most elegant way of selecting attributes from join models in has_many :through associations is.

Lets say we have Items, Catalogs, and Cat

4条回答
  •  余生分开走
    2021-02-06 15:10

    Just adding answer so that it might help others

    CatalogItem.joins(:item, :catalog).
      where(items: { id: 4 }).pluck(:position).first
    

提交回复
热议问题