Can you please try this way? student_project = StudentProject.new(student_id: 10, project_id: 10, submission_date: Date.today + 30.days) student_project.valid? If this returns false, then please try to see the errors by running: student_project.errors.full_messages
@@APPSIMPACTAcademy i followed the lecture and in the project model there are only associations present class Project < ApplicationRecord has_many :student_projects has_many :students, through: :student_projects end
Superb content buddy! Really appreciate your hard work 🙌
excellent work brother
How do one access the students project submission date
Can you explain build method
indian guy
When I try creating a StudentProject
the transaction gets rolled back
not sure why
StudentProject.create(student_id: 10, project_id: 10, submission_date: Date.today + 30.days)
TRANSACTION (0.1ms) begin transaction
Student Load (0.1ms) SELECT "students".* FROM "students" WHERE "students"."id" = ? LIMIT ? [["id", 10], ["LIMIT", 1]]
Project Load (0.0ms) SELECT "projects".* FROM "projects" WHERE "projects"."id" = ? LIMIT ? [["id", 10], ["LIMIT", 1]]
TRANSACTION (0.0ms) rollback transaction
Can you please try this way?
student_project = StudentProject.new(student_id: 10, project_id: 10, submission_date: Date.today + 30.days)
student_project.valid?
If this returns false, then please try to see the errors by running:
student_project.errors.full_messages
let me know if this works for you
@@APPSIMPACTAcademy i am getting this
irb(main):022:0> student_project.errors.full_messages
=> ["Project must exist"]
@@vigneshwarsathyanarayanan you need to check if the project model has some instances or not
@@APPSIMPACTAcademy i followed the lecture and in the project model there are only associations present
class Project < ApplicationRecord
has_many :student_projects
has_many :students, through: :student_projects
end