I have many, many relationships between the dossiers and the contact, and therefore they have the has_and_belongs_to_many relationship:
class Dossier < ActiveRecord::Base has_and_belongs_to_many :contacts
and
class Contact < ActiveRecord::Base has_and_belongs_to_many :dossiers
In the display method of the Dossiers controller, I have the following:
@dossier = current_user.company.dossiers.find(params[:id]) @dossier_contacts = @dossier.contacts
But when I request a show view, I get an error message:
SQLite3::SQLException: no such table: contacts_dossiers: SELECT COUNT(*) FROM "contacts" INNER JOIN "contacts_dossiers" ON "contacts"."id" = "contacts_dossiers"."contact_id" WHERE "contacts_dossiers"."dossier_id" = 1
The view is as follows:
<li><%= I18n.t :dossier_nr_contacts %></li><li><%= @dossier_contacts.count.to_s %></li>
I think I have established the relationship correctly, the table exists, but now I don’t understand why it gives an error. Any clues?
Edit: migration I did:
class CreateDossiersContactsJoinTable < ActiveRecord::Migration def up create_table :dossiers_contacts, :id => false do |t| t.integer :dossier_id t.integer :contact_id end end def self.down drop_table :dossiers_contacts end end
source share