1

In my class, I want to include multiple modules. Each module can define its own property to persist in couchDB.

Here is an example:

module Owner
 property :name
end

module Animal
 property :type
end

class Cat
 include Owner
 include Animal
end

This doesn't work. I got this error: "undefined method `property'". I tried added CouchRest::Model::Embeddable but it won't work for module either. All the examples I am seeing are extending from CouchRest::Model::Base. However, I won't be able to use this approach because Ruby doesn't support multiple inheritance.

I won't be able to change the underlying JSON format. My desired format is {"name":"tom","type":"cat"}.

Any help would be appreciated. Thanks!

PokerIncome.com
  • 1,708
  • 2
  • 19
  • 30

1 Answers1

0

According to http://www.couchrest.info/model/embedding.html I think your example would be:

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
DataRiot
  • 476
  • 3
  • 8
  • Thanks for the idea! This doesn't seem to work for me. I won't be able to change the underlying JSON format. My desired format is {"name":"tom","type":"cat"}. Your code would generate a format of {"owner":{"name":"tom"}, "animal":{"type":"cat"}} – PokerIncome.com Nov 10 '11 at 01:13