我有这些模型简化:(Rails 3中)联合两个查询到一个
class Game::Champ < ActiveRecord::Base
has_one :contract, :class_name => "Game::ChampTeamContract", :dependent => :destroy
has_one :team, :through => :contract
# Attributes: :avg => integer
end
#
class Game::Team < ActiveRecord::Base
has_many :contracts, :class_name => "Game::ChampTeamContract", :dependent => :destroy
has_many :champs, :through => :contracts
end
#
class Game::ChampTeamContract < ActiveRecord::Base
belongs_to :champ
belongs_to :team
# Attributes: :expired => bool, :under_negotiation => bool
end
#
所以,我想在这里做的是找到所有游戏::香榭丽说没有游戏:: ChampTeamContract任何或者已经,但(是不是:under_negociation或是:或过期),由Champ.avg ASC排序
我还挺停留在使用两个查询,concating结果和排序它。我希望有一个更好的方式,以更多的“Railish”
UPDATE:只是增加了一个约束有关:过期
这仍然是两个查询。 – idlefingers 2010-12-21 19:55:57
对不起,我正在阅读你的问题,因为你辞去了写作两个查询并连接结果的问题。 – Shane 2011-01-10 21:04:57