Guest User

Untitled

a guest
Jun 18th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. class Publication < ActiveRecord::Base
  2. belongs_to :category
  3. has_one :site, :through => :category
  4. named_scope :on_site, lambda {|s| {:include => [:site], :conditions => ['sites.slug != ?', 's']}}
  5. end
  6. class Category
  7. belongs_to :site
  8. has_many :publications
  9. end
  10. class Site
  11. has_many :categories
  12. has_many :publications, :through => :categories, :foreign_key => 'category_id'
  13. end
  14.  
  15. Mysql::Error: Unknown column 'categories.category_id' in 'on clause': SELECT
  16. `publications`.`id` AS t0_r0, `publications`.`shoot_id` AS t0_r1,
  17. `publications`.`category_id` AS t0_r2, `publications`.`title` AS t0_r3,
  18. `publications`.`slug` AS t0_r4, `publications`.`publish_on` AS t0_r5,
  19. `publications`.`created_at` AS t0_r6, `publications`.`updated_at` AS t0_r7,
  20. `publications`.`description` AS t0_r8, `publications`.`media_base_path` AS t0_r9,
  21. `sites`.`id` AS t1_r0, `sites`.`name` AS t1_r1, `sites`.`created_at` AS t1_r2,
  22. `sites`.`updated_at` AS t1_r3, `sites`.`slug` AS t1_r4, `sites`.`description` AS t1_r5,
  23. `sites`.`dhd_merch_id` AS t1_r6, `sites`.`members_area_url` AS t1_r7 FROM `publications`
  24. LEFT OUTER JOIN `categories` ON (`publications`.`id` = `categories`.`category_id`)
  25. LEFT OUTER JOIN `sites` ON (`sites`.`id` = `categories`.`site_id`) WHERE (sites.slug != 's')
  26.  
  27. LEFT OUTER JOIN `categories` ON (`publications`.`id` = `categories`.`category_id`)
  28.  
  29. has_many :publications, :through => :categories, :foreign_key => 'category_id'
  30.  
  31. class Publication < ActiveRecord::Base
  32. belongs_to :category
  33. #has_one :site, :through => :category
  34. named_scope :on_site, lambda {|s| {:include => { :category => :site }, :conditions => ['sites.slug != ?', s]}}
  35. end
  36.  
  37. named_scope :on_site, lambda {|s| {:joins =>
  38. ['LEFT OUTER JOIN `categories` ON (`publications`.`category_id` = `categories`.`id`) ',
  39. 'LEFT OUTER JOIN `sites` ON (`sites`.`id` = `categories`.`site_id`)'],
  40. :conditions => ['sites.slug = ?', s]}}
Add Comment
Please, Sign In to add comment