这是我现在的情况:
Adword has_many pages
page belongs_to Adword
现在我想放置另一个广告提供商,这也将生成页面。所以,理想情况下我想以某种方式说类似的话(这就是我迷失的地方):
AdProvider has_many pages
page belongs_to AdProvider
AdProvider 可以是 Adwords、X、Y - 在 Rails 中处理此类情况的正确方法是什么?现在,我在页面中只有一个 adword_id 属性,但会有一些页面不与 Adword 关联,而是与另一个广告提供商关联。
最佳答案
来自文档:
With polymorphic associations, a model can belong to more than one other model, on a single association. For example, you might have a picture model that belongs to either an employee model or a product model.
关于ruby-on-rails - Modelwhichbelongs_to可以是几个模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22052712/