I have a polymorphic association: my user model can be of type 'student' or of type 'employer'. I am trying to set up a has_and_belongs_to_many association between the student model and another model called the 'project' model. When I try to call:
controller:
@my_projects = current_user.projects
view:
<% @my_projects.where(state: :posting).each do |project| %>
<%= project.students %><br>
<% end %>
I am told:
PG::UndefinedTable: ERROR: relation "projects_users" does not exist
I have defined a table called "projects_students" though, which i think should work. I don't want to have a "project_users" table because the table is only for students, not for employers. How do I fix this? Here are my models:
class Student < User
has_and_belongs_to_many :projects
end
-
class Project < ActiveRecord::Base
has_and_belongs_to_many :students
end