mari...@gmail.com
unread,Apr 2, 2013, 3:39:06 AM4/2/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongo...@googlegroups.com
I'm trying to think of a possible mongomapper implementation for some model structure I want to create.
I have the following model classes: DeviceType, MasterTemplate, ChildTemplate.
To avoid confusion, only think of id's with DeviceType and child templates.
What I would like to have in MasterTemplate is a key that looks like this:
config_types = { config_type (String) => { DeviceType => ChildTemplates [ ] } }
As you can see, it's some kind of hash whose key is a String, and the value is a nested hash that has a DeviceType as key and an array of ChildTemplates as a value.
I would do something like this if the value of the nested array was just something ordinary like a String or an integer:
class MasterTemplate
include MongoMapper::Document
plugin MongoMapper::Plugins::IdentityMap
many :config_types
end
class ConfigType
include MongoMapper::EmbeddedDocument
plugin MongoMapper::Plugins::IdentityMap
key :name, String
key :devices, Hash
many :device_types, :in => :devices
end
It should also be noted that ChildTemplates contain many DeviceTypes. That means it should not be an embedded document, since two different classes need to reference it.
Help is much appreciated, let me know if you need more information.