Advertisement
Guest User

Untitled

a guest
Jan 27th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. stud = Student.create(:student_id => 1, :first_name => 'Jos', :last_name => 'Norton', :email => 'ss.norton@gmail.com', :birthday => '12/05/1995', :subjects => 'English', :username => 'samnorton05', :password => 'Grace02112')
  2.  
  3. ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :enrolled_subjects in model Student
  4.  
  5. class Student < ApplicationRecord
  6.  
  7. has_many :subjects, through: :enrolled_subjects
  8. has_many :teachers, through: :enrolled_subjects
  9.  
  10. def teacher_names
  11. self.teachers.map(&:name).join(", ")
  12. end
  13.  
  14. has_many :admin_users
  15. has_secure_password
  16. self.primary_key = :student_id
  17.  
  18.  
  19. scope :newest_first, lambda { order("created_at ASC") }
  20. scope :oldest_first, lambda { order("created_at DESC") }
  21. # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
  22.  
  23. end
  24.  
  25. class Teacher < ApplicationRecord
  26.  
  27. has_many :subjects, through: :enrolled_subjects
  28. has_many :students, through: :enrolled_subjects
  29. has_many :admin_users
  30. has_secure_password
  31.  
  32. scope :newest_first, lambda { order("created_at ASC") }
  33. scope :oldest_first, lambda { order("created_at DESC") }
  34. # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
  35. end
  36.  
  37. class Subject < ApplicationRecord
  38.  
  39. has_many :students, through: :enrolled_subjects
  40. has_many :teachers, through: :enrolled_subjects
  41. has_many :admin_users
  42.  
  43. # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
  44.  
  45. end
  46.  
  47. class EnrolledSubject < ApplicationRecord
  48. belongs_to :student
  49. belongs_to :subject
  50. belongs_to :teacher
  51. end
  52.  
  53. class AdminUser < ApplicationRecord
  54.  
  55. has_secure_password
  56.  
  57. scope :newest_first, lambda { order("created_at ASC") }
  58. scope :oldest_first, lambda { order("created_at DESC") }
  59. # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement