couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Troy Kruthoff <>
Subject Re: How to organize/differentiate Documents?
Date Wed, 16 Jul 2008 18:24:16 GMT
If you are using a type attribute, you can also combine then in a  
vehicles view such as

views =>

:all =>
function(doc) {
if (doc.type=='Car' || doc.type=='Truck') {
  //I'm a vehicle

:trucks =>
function(doc) {
if (doc.type=='Truck') {
  //I'm a vehicle

etc...  You can also use an array as the type attribute, such as  
['Vehicle','Truck'].  The big take away is you can do whatever makes  
the most sense for your situation which IMHO is determined by what  
your doing with the data at the app level and which language.  For  
example, I've been toying with the idea of the array concept in Ruby  
and using modules to mixin the type when I build the object, for  
example everything starts as a Document class and when fetching the  
data from couch I would mixin the Vehicle and Truck modules.  However,  
if my app was written in Java I would take an entire different  
approach.  Even in Ruby this would be silly overkill if I didn't have  
the design requirement to demote a Truck to a Vehicle on a obj by obj  
basis, as like you said, its just the attributes and not the methods.

-- troy

On Jul 16, 2008, at 8:50 AM, Dean Landolt wrote:

>> Duck typing will go a long way here.
>> function(doc) {
>> if (doc.wheels && doc.engine) {
>> //I'm a vehicle
>> } else if (doc.wheels && doc.pedals) {
>> // I'm a bike
>> }
>> }
> That seemed to be what Troy was hinting at with his example as well.  
> I guess
> explicit inheritance doesn't matter much when you're just storing the
> attributes and not the methods. Thanks for the insight.

View raw message