daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## Course model
  2. class Course < ActiveRecord::Base
  3.  
  4.   has_many :registrations
  5.   has_many :orders, :through => :registrations, :uniq => true, :include => :user
  6. ...
  7. ## Registration model
  8. class Registration < ActiveRecord::Base
  9. belongs_to :course
  10. belongs_to :order
  11.  
  12. ## Order model
  13. class Order < ActiveRecord::Base
  14.  
  15.   has_many :registrations
  16.   has_many :courses, :through => :registrations
  17.   belongs_to :user
  18.  
  19. ## User model
  20. class User < ActiveRecord::Base
  21.   attr_accessor :password_confirmation
  22.  
  23.   has_many :orders
  24.   has_and_belongs_to_many :roles
  25.   has_many :registrations, :through => :orders,
  26.     :uniq => true,
  27.     :include => :course
  28.  
  29. ## Error
  30. >> Course.find :all, :select => 'distinct courses.*', :joins => {:registrations => {:orders => :user}}
  31. ActiveRecord::ConfigurationError: Association named 'orders' was not found; perhaps you misspelled it?
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top