Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For the first question about the schema and adding items autonomously you might consider using <code>dm-is-tree</code> for your <code>Deviceclass</code> it'll do a lot of the work for you. Below is an example of creating an item and 'later on' adding associated items.</p> <pre><code>require 'rubygems' require 'data_mapper' require 'dm-is-tree' # setup DataMapper::Logger.new($stdout, :debug) DataMapper.setup(:default, 'sqlite::memory:') # models class Deviceclass include DataMapper::Resource property :id, Serial property :hw_id, String, :unique =&gt; true property :name, String property :updated_at, DateTime property :created_at, DateTime is :tree, :order =&gt; :name has n, :devices end class Device include DataMapper::Resource property :id, Serial property :device_class_id, Integer property :name, String property :updated_at, DateTime property :created_at, DateTime belongs_to :deviceclass, :required =&gt; false end # go! DataMapper.finalize DataMapper.auto_upgrade! # make the root deviceclass parent = Deviceclass.create(:name =&gt; "Root") # later on make a child child = Deviceclass.create(:name =&gt; "Child") # and add it to the parent parent.children &lt;&lt; child # again later, create some devices d1 = Device.create(:name =&gt; "D1") d2 = Device.create(:name =&gt; "D2") # add them parent.devices &lt;&lt; d1 child.devices &lt;&lt; d2 # get stuffs puts parent.children puts child.root puts parent.devices puts child.devices </code></pre> <p>I'm not sure it's a good idea to use validation to generate missing Deviceclasses. If the initial data is not constantly changing I'd run a seed script on startup. You can use something like <a href="https://github.com/datamapper/dm-sweatshop" rel="nofollow">dm-sweatshop</a> to seed the db.</p> <p>I think I need a few more details on #3 do you want a default name for a Deviceclass (you can add <code>:default =&gt; 'foo'</code>) which you might know as you are using <code>:default</code> already! :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload