【发布时间】:2022-09-24 06:37:16
【问题描述】:
我有 3 张表(Freebie、Company、FreebieCompany),FreebieCompany 是中间表。 2张桌子(免费赠品,公司)使用有很多关联,并由中间表连接。我可以访问公司表以获取免费赠品,但不能访问公司的赠品。
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 有 company_id 和 freebie_id。 我可以访问某个公司的赠品,但不能访问某个赠品的公司。
我确实 rake db:reset、drop、create、migrate、setup 和 db:schema:load 但没有真正解决问题。我仔细检查了迁移版本,所有表都列在架构中。
也许另一种观点可以帮助我找到解决方案。每次我尝试访问这些公司时,都会出现以下错误。
> freebie.companies
*``` ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: 关系 \"freebie_companies\" 不存在) 第 1 行:...公司\"。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!
标签: ruby-on-rails