我有以下型号
Business has many Categories through Categorizations
Category has many Businesses through Categorizations
Business has many Estates through Localizations
Estate has many Businesses through Localizations
我如何找到某个地产的所有业务类别?
@categories =查找某个地产业务的所有类别
答案 0 :(得分:1)
必须有一种更简单的方法,但您可以随时尝试:
@estate = Estate.find(1)
@estate.businesses.map {|business| business.categories}.flatten
或
@estate = Estate.find(1)
@categories = Categories.where(id: @estate.businesses.pluck(:id))