檢索具有指定特徵集的所有獨特場所的最有效方法是什麼?從Rails 4關聯模型檢索信息
在控制器中,我有:
@venues = Venue.all
@venues = @venues.features.where('feature.id == ' 1).distinct
下面是我的模型定義:
class Neighborhood < ActiveRecord::Base
has_many :venues
end
class Venue < ActiveRecord::Base
belongs_to :neighborhood
has_many :features
end
class FeatureType < ActiveRecord::Base
has_many :features
end
class Feature < ActiveRecord::Base
belongs_to :venue
belongs_to :feature_type
end
好點,Messick;不過,我確實在循環中有代碼(請參閱編輯的問題以獲取更多代碼)。出於某種原因,鐵軌不會選擇「id」字段。思考? – Vee
我編輯了這個問題放回原來的文本,所以我們的答案是有道理的。 – messick