Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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')
- ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :enrolled_subjects in model Student
- class Student < ApplicationRecord
- has_many :subjects, through: :enrolled_subjects
- has_many :teachers, through: :enrolled_subjects
- def teacher_names
- self.teachers.map(&:name).join(", ")
- end
- has_many :admin_users
- has_secure_password
- self.primary_key = :student_id
- scope :newest_first, lambda { order("created_at ASC") }
- scope :oldest_first, lambda { order("created_at DESC") }
- # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
- end
- class Teacher < ApplicationRecord
- has_many :subjects, through: :enrolled_subjects
- has_many :students, through: :enrolled_subjects
- has_many :admin_users
- has_secure_password
- scope :newest_first, lambda { order("created_at ASC") }
- scope :oldest_first, lambda { order("created_at DESC") }
- # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
- end
- class Subject < ApplicationRecord
- has_many :students, through: :enrolled_subjects
- has_many :teachers, through: :enrolled_subjects
- has_many :admin_users
- # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
- end
- class EnrolledSubject < ApplicationRecord
- belongs_to :student
- belongs_to :subject
- belongs_to :teacher
- end
- class AdminUser < ApplicationRecord
- has_secure_password
- scope :newest_first, lambda { order("created_at ASC") }
- scope :oldest_first, lambda { order("created_at DESC") }
- # scope :search, lambda { |query| where(["name LIKE ?", "%#{query}%"])}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement