Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Como usar a consulta de junção para 4 tabelas em trilhos


Tente isto:
ItemCode.joins(item_point: {item: :product_category}).where(product_category: {id: 1})

Deixe-me simplificar a junção de tabelas :

# item_code belongs_to item_point
ItemCode.joins(:item_point) 

# ItemPoint has_many item_codes & belongs_to item
ItemPoint.joins(:item_codes, :item) 
# ItemCode belongs_to item_point, item_point belongs_to item
ItemCode.joins(item_point: :item) 

# ItemCode belongs_to item_point, item_point belongs_to item, item belongs_to product_category 
ItemCode.joins(item_point: {item: :product_category})