samedi 12 mars 2016

SQLite3 error in rails SQLite3::SQLException: no such column

I am making a rails app where a user can post courses and also subscribe to courses.My model files are:
user.rb:

class User < ActiveRecord::Base
  has_many :courses, dependent: :destroy
  has_many :coursejoins, dependent: :destroy
  has_many :learnables, through: :coursejoins, class_name: "Course"
  has_many :comments, dependent: :destroy
  ...
end

course.rb:

class Course < ActiveRecord::Base
  belongs_to :user
  belongs_to :category
  has_many :coursejoins, dependent: :destroy
  has_many :students, through: :coursejoins, class_name: "User"
  has_many :documents, dependent: :destroy
  has_many :comments, dependent: :destroy
  ...
end

coursejoin.rb:

class Coursejoin < ActiveRecord::Base
  belongs_to :learnable, :class_name => "Course"
  belongs_to :student, :class_name => "User"
end


The coursejoin model is like a relation between a course and a user.
When I try to do @course.students, i get error:



    SELECT "users".* FROM "users" INNER JOIN "coursejoins" ON "users"."id" = "coursejoins"."student_id" WHERE "coursejoins"."course_id" = ?  [[nil, 1]]
    ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: coursejoins.course_id: SELECT "users".* FROM "users" INNER JOIN "coursejoins" ON "users"."id" = "coursejoins"."student_id" WHERE "coursejoins"."course_id" = ?


I don't know SQL much so i am not able to decipher the error.
I looked at questions with similar error but none seemed related.
I have been stuck with this for two days.
How do i fix this?

Aucun commentaire:

Enregistrer un commentaire