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

在类别显示操作中,我有

def show
  @category = Category.find(params[:id])
  @estate = Estate.find(current_user.estate_id)
  @businesses = @estate.businesses
end

明显的问题是,无论它属于哪个类别,它都会退回所有企业的遗产。我试图添加一个 .where("category_id = ?", @category_id) 但我得到 column does not exist 错误

4

1 回答 1

1

由于它似乎有效,这里再次提出建议作为答案:)

@businesses = @estate.businesses.joins(:categories).where(categories: {id: @category.id})
于 2013-11-11T13:06:56.120 回答