在我的班上,我想要包含多个模块。每个模块都可以 定义自己的属性以在couchDB中保留。
以下是一个例子:
module Owner
property :name
end
module Animal
property :type
end
class Cat
include Owner
include Animal
end
这不起作用。我收到了这个错误:“未定义的方法`属性'”。 我尝试添加CouchRest :: Model :: Embeddable但它不适用 模块要么。我看到的所有例子都在延伸 CouchRest ::型号::基地。但是,我将无法使用这种方法 因为Ruby不支持多重继承。
我将无法更改基础JSON格式。我想要的格式是{“name”:“tom”,“type”:“cat”}。
任何帮助将不胜感激。谢谢!
答案 0 :(得分:0)
根据http://www.couchrest.info/model/embedding.html我认为你的例子是:
class Owner < CouchRest::Model::Base
include CouchRest::Model::Embeddable
property :name
end
class Animal < CouchRest::Model::Base
include CouchRest::Model::Embeddable
property :type
end
class Cat
property :owner, Owner
property :animal, Animal
end