【问题标题】:Rails 'multiple inheritance' model- ActiveRecord object with a property which is another class?Rails“多重继承”模型-具有另一个类的属性的ActiveRecord对象?
【发布时间】:2015-06-23 15:17:27
【问题描述】:

我可能要求错了。我想要的是一个扩展类 ActiveMerchant::Shipping::Location 的模型,但也保存在数据库中,并具有其他整洁的活动记录关联,如多个员工、工作日时间表等。

我知道我不能从多个类继承 - 创建具有 ActiveMerchant::Shipping::Location 属性和方法以及其他 ActiveRecord 属性和关联的 Location 类的最佳方法是什么?

【问题讨论】:

    标签: ruby-on-rails oop activerecord model activemerchant


    【解决方案1】:

    您可以从 ActiveMerchant::Shipping::Location 继承并包含 ActiveModel::Model 和/或您想要的其他 ActiveRecord 模块。

    【讨论】:

    • 所以应该是:类 WarehouseLocation / 扩展 ActiveMerchant::Shipping::Location / 包括 ActiveRecord::Base ?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    相关资源
    最近更新 更多