I have 3 tables (Freebie, Company, FreebieCompany) and FreebieCompany is the intermediary table. 2 tables (Freebie, Company) use has_many association and is being connected by the middle table. I can access the Company table to get the freebies but not Freebies to Companies.
class Company < ApplicationRecord
has_many :freebie_companies
has_many :freebies, through: :freebie_companies
end
class Freebie < ApplicationRecord
has_many :freebie_companies
has_many :companies, through: :freebie_companies
class FreebieCompany < ApplicationRecord
belongs_to :freebie
belongs_to :company
end
FreebieCompany have both company_id and freebie_id. I can access the Freebies of a certain company, but not the Companies of a certain Freebie.
I did rake db:reset, drop, create, migrate, setup and db:schema:load but nothing really solved the problem. I double checked the migration version and all tables are listed on the schema.
Maybe another perspective can help me find the solution to this. Every time I try to access the companies, it gives me the error below.
> freebie.companies
*``` ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "freebie_companies" does not exist) LINE 1: ...ompanies". FROM "companies" INNER JOIN "freebi...
It's my first time to post here, and I've been using my whole day to find the answer to this one.
Any help is very appreciated. Thank you so much!