Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有2个模型。有项目和类别。他们彼此有 has_many 关联。加入表调用 categories_items 并且没有模型。默认情况下,它具有 item_id、category_id 和时间戳。
目标是向此连接表添加额外的字段。如果我只是通过迁移将字段添加到此表中,我该如何访问它?
通过创建一个连接模型并定义一个
has_many :items, through: <model>
关系。有关详细信息,请参阅Ruby on Rails 指南。