mardi 4 août 2015

How do I specify the join table on a has_many through association?

I have a users table (admin_users) a join table (UserCompanies) and a companies table (Companies), each has an active record model (AdminUser, TableModule::UserCompany, TableModule::Company). I want to do something like the following:

AdminUser.first.companies

But, my attempts so far are not working, I'm assuming because I need to specify the table names, model names, or key names, but I don't know how that works with a has_many through relationship. Here is my best attempt at defining it so far:

class AdminUser < ActiveRecord::Base
    has_many :companies, through: :user_company, source: "TableModule::UserCompany"
end

How do I properly specify this relationship?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire