Defining a field containing an array of objects using CouchTypes

21 views
Skip to first unread message

Andru Vallance

unread,
Jul 15, 2013, 12:00:45 PM7/15/13
to ka...@googlegroups.com
Hello,
I'm looking for some advice on using CouchTypes.  I'm writing a small garden tracking app which keep track of plantings in a garden. Each planting has multiple actions. These actions exist only within the scope of the planting. The same pattern is repeated for harvests and observations. Accordingly, I've sketched out the following document schema (I've greyed out parts of the schema irrelevant to this question)

{
   "_id": "6edde3e99053a9ce2a660a9ea91d34d8",
   "_rev": "3-577c45c66468cbb45e1f38e3b011bf38",
   "user": "andru",
   "type": "planting",
   "place": "6edde3e99053a9ce2a660a9ea91d4193",
   "plant": "Mustard Greens",
   "actions": [
       {
           "type": "sowed",
           "date": "2013-04-05 10:00:00",
           "notes": "Was a really hot, dry day."
       },
       {
           "type": "thinned",
           "date": "2013-04-05 10:00:00",
           "notes": "Thinned out and transplanted the thinnings."
       }
   ],
   "harvest": {
       "began": "2013-05-27",
       "ended": "2013-07-20",
       "harvests": [
           {
               "date": "2013-06-06",
               "yield": "10",
               "unit": "heads",
               "notes": "Heads were a bit on the small side"
           }
       ]
   },
   "observations": [
       {
           "date": "2013-06-12",
           "notes": "First seedlings popped their heads up"
       },
       {
           "date": "2013-06-20",
           "notes": "Argh! Total flea beetle massacre!"
       }
   ]
}

How is this best achieved with CouchType fields? Looking over the source I can't see anything obvious I should use to allow an array with arbitrary objects, let alone an array of objects with some form of schema control.

I'd prefer to avoid using an EmbeddedList here, unless there are good reasons for that I'm missing, as the data in these objects is only relevant to this planting, and creating them as separate objects seems like an unnecessary schema complication.

Andru

R.J. Steinert

unread,
Jul 16, 2013, 3:30:06 PM7/16/13
to ka...@googlegroups.com
Andru,
That's quite a deep schema.  I might normalize that into different documents types which would be easier on any form generating code and perhaps easier to understand in your own code as to avoid giant form submit handlers.  Something like...

Season (this being the parent document  that the other types reference)
Planting (what you have as "actions")
Harvest
Observation

I don't have any experience with CouchTypes but Backbone Forms (https://github.com/powmedia/backbone-forms) works really well for me since I organize all my Javascript apps using Backbone.js. I'll be interested to see what you come up with.  I contribute to the open source farming community FarmHack.net on a number of projects, you might consider posting this project to their Tools Wiki if you want to get some people testing it in the field.  

-RJ

Andru Vallance

unread,
Jul 16, 2013, 4:54:35 PM7/16/13
to ka...@googlegroups.com
Thanks for the reply RJ.

Actually I've been fighting the instinct to normalize.  I guess I'm trying to de-normalize myself from the idea of normalizing everything into table based schemas, but perhaps you're right - maybe I'm getting carried away in my enthusiasm for document based storage, and certainly for form generators it's pretty fringe indeed.

As it happens today I've dropped CouchTypes/Duality through frustration with bugs and lack of documentation - so I'm back to Backbone/Marionette again, where I feel a lot more at home :)

Thanks for the link up to FarmHack.net - I've come across it before actually but haven't got involved yet.  I'll be sure to drop in when I've got a prototype up and running.  I'm also the main dev behind a collaborative plant use database: http://practicalplants.org.  In the long run I'm hoping to convert that from Semantic MediaWiki to a custom CouchApp so it's distributed and available offline but baby steps!

Andru Vallance


--
You received this message because you are subscribed to the Google Groups "kanso" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kanso+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages