1
我有我的模型以下关系:把一个条件在许多一对多查询用ActiveRecord
class Show < ActiveRecord::Base
has_many :service_shows
has_many :services, :through => :service_shows
end
class Service < ActiveRecord::Base
has_many :service_shows
has_many :shows, :through => :service_shows
end
class ServiceShow < ActiveRecord::Base
belongs_to :show
belongs_to :service
end
我想回去查询所有节目为给定的服务,有rec_status ='A',但是我的ActiveRecord技能只有三天左右的时间,所以我没有那么好。如果我理解正确,我可以简单地调用service.shows并筛选返回的列表,但我只想从数据库中检索我需要的记录 - 我宁愿不浪费处理器时间和记录上的记录,不想要。
谢谢!