我正在将 rails3 应用程序升级到 3.2.6 我对已弃用的带有选项的 default_scope 有一些问题。
我有几个模型 Campaigns 和 Sites 通过campaign_sites 建立了多对多的关系。
class Campaign < ActiveRecord::Base
has_many :campaign_sites, :dependent => :destroy
....
end
class Site < ActiveRecord::Base
has_many :campaign_sites, :dependent => :destroy
has_many :campaigns, :through => :campaign_sites
...
end
class CampaignSite < ActiveRecord::Base
default_scope :include => [:campaign, :site], :order => :'sites.name'
belongs_to :campaign, :touch => true
belongs_to :site, :touch => true
...
end
这在 rails 3.0.10 上运行良好,但在升级到 3.2.6 后,我在这一行中收到以下 mysql 错误。
default_scope :include => [:campaign, :site], :order => :'sites.name'
Mysql2::Error: Unknown column 'sites.name' in 'order clause': SELECT `campaigns`.* FROM`campaigns` INNER JOIN `campaign_sites` ON `campaigns`.`id` = `campaign_sites`.`campaign_id` WHERE `campaign_sites`.`site_id` = 11377 ORDER BY campaigns.name, sites.name