私は鉄道サイトを建設していて、協会に問題を抱えています。基本的に私は次のものを持っています:
class Publication < ActiveRecord::Base
belongs_to :category
has_one :site, :through => :category
named_scope :on_site, lambda {|s| {:include => [:site], :conditions => ['sites.slug != ?', 's']}}
end
class Category
belongs_to :site
has_many :publications
end
class Site
has_many :categories
has_many :publications, :through => :categories, :foreign_key => 'category_id'
end
Publication.first.site
最初の出版物のサイトを作成site.first.publications
し、同様に作成します。
問題はon_site
名前付きスコープにあり、次のようなエラーが発生します。Publication.on_site('s')
Mysql::Error: Unknown column 'categories.category_id' in 'on clause': SELECT
`publications`.`id` AS t0_r0, `publications`.`shoot_id` AS t0_r1,
`publications`.`category_id` AS t0_r2, `publications`.`title` AS t0_r3,
`publications`.`slug` AS t0_r4, `publications`.`publish_on` AS t0_r5,
`publications`.`created_at` AS t0_r6, `publications`.`updated_at` AS t0_r7,
`publications`.`description` AS t0_r8, `publications`.`media_base_path` AS t0_r9,
`sites`.`id` AS t1_r0, `sites`.`name` AS t1_r1, `sites`.`created_at` AS t1_r2,
`sites`.`updated_at` AS t1_r3, `sites`.`slug` AS t1_r4, `sites`.`description` AS t1_r5,
`sites`.`dhd_merch_id` AS t1_r6, `sites`.`members_area_url` AS t1_r7 FROM `publications`
LEFT OUTER JOIN `categories` ON (`publications`.`id` = `categories`.`category_id`)
LEFT OUTER JOIN `sites` ON (`sites`.`id` = `categories`.`site_id`) WHERE (sites.slug != 's')
私はその結合がpublications.category_id=categorys.idである必要があります、私が間違っていることについて何か考えはありますか?