1

我有以下型号

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 = 查找某个房地产企业的所有类别

4

1 回答 1

1

必须有一个更简单的方法,但你总是可以试试这个:

@estate = Estate.find(1)

@estate.businesses.map {|business| business.categories}.flatten

或者

@estate = Estate.find(1)

@categories = Categories.where(id: @estate.businesses.pluck(:id))
于 2013-11-11T08:36:02.207 回答