Elegantly selecting attributes from has_many :through join models in Rails

前端 未结 4 630
春和景丽
春和景丽 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:08

    Why don't You just

    @item = Item.find(4)
    position = @item.catalog_items.first.position
    

    why do you go through catalogs? It doesn't make any sense to me since you are looking for first ANY catalog!?

提交回复
热议问题