Difficult design decision, would like some help

16 views
Skip to first unread message

mari...@gmail.com

unread,
Apr 2, 2013, 3:39:06 AM4/2/13
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.

Reply all
Reply to author
Forward
0 new messages