0

所以我基本上有 3 个应用程序需要捆绑在一起(通过使用引擎)。一个公共网站、一个销售点和一个经理(管理另外两个)。我想创建一个“产品”模型,其中包含与葡萄酒无关的所有产品细节。然后我想要一个扩展 Product 的“Wine”模型。在数据库中,我有两张表……产品和葡萄酒。wines 表将仅具有特定于 wine 的属性和将其链接到相应产品表条目的 product_id。

我知道如何在没有一个模型扩展另一个模型的情况下执行此操作(通过 belongs_to 和 has_*),但我不明白如何将其作为模型扩展。

使用 Rails 3.2.11

产品.rb

class Product < ActiveRecord::Base
    ...stuff goes in here
end

Wine.rb

class Wine < Product
    ...how do I ensure that the products table attributes and the wines table attributes are separately updated/created/etc.????
end
4

1 回答 1

0

citier gem 支持多表继承,就像您描述的那样

本文还有一个关于如何在没有 gem 的情况下设置多表继承的教程。

于 2013-02-14T21:37:36.767 回答