[dojo-contributors] dojo.data Schema API

Brian Douglas Skinner skinner at dojotoolkit.org
Mon Aug 27 02:53:20 EDT 2007


Interesting idea.  Allowing for hierarchical schema structures like that 
might have the advantage of making the semantics more obvious for 
somebody who's reading the schema file.  Although, for newcomers 
approaching this from an RDBMS background, the hierarchical schema 
structure might make dojo.data seem even more weird and unintuitive.

Also, at a practical level, would the hierarchical format create the 
limitation that the nested definition is "anonymous"?  In the "flat" 
schema example from the original mail, we had named definitions for two 
kinds of items, "Country" and "State".  In this new hierarchical schema 
example, it looks as if "State" is just an attribute name, like "ABBR" 
and "NAME", and there's only a named definition for one kind of item, 
"Country".  Does that make it impossible for any other kind of item to 
have an attribute of type State -- for example, impossible to have a 
definition for "Person", with attributes for "NAME", "AGE", and "HOME 
STATE"?

:o) Brian


Jon Sykes wrote:
> Not sure if I'm jumping in halfway into this but is there a reason it  
> isn't something like:
> 
> schema == {
>      kinds: {
>          Country: {
>              attributes: {
>                  ABBR: {type: 'String'},
>                  NAME: {type: 'String'}
>                  State: [
>                      attributes: {
>                          NAME: {type: 'String'},
>                          CODE: {type: 'String'},
>                          POPULATION: {type: 'Number'}
>                      },
>                  ]
>              }
>          },
>      }
> }
> 
> Which seems to make more semantic sense in terms of relationships.
> 
> 
> 
> 
> On Aug 21, 2007, at 8:55 PM, Brian Douglas Skinner wrote:
>>>>     schema == {
>>>>          kinds: {
>>>>              Country: {
>>>>                  attributes: {
>>>>                      ABBR: {type: 'String'},
>>>>                      NAME: {type: 'String'}
>>>>                  }
>>>>              },
>>>>              State: {
>>>>                  attributes: {
>>>>                      NAME: {type: 'String'},
>>>>                      CODE: {type: 'String'},
>>>>                      COUNTRY: {kind: 'Country'},
>>>>                      POPULATION: {type: 'Number'}
>>>>                  }
>>>>              }
>>>>          }
>>>>      }
>>>
>>> What's the COUNTRY field of State?  Is that a reference to a Country
>>> item?   Or the id of a Country item?
>>>
>>> And if it's the former, how would you query for all states in the  
>>> USA?
>> In the example above, the COUNTRY field was intended to be a reference
>> to an item, rather than a foreign key.
>>
>> To query for all the states in the USA, you could do this:
>>
>>    store.fetch({query: {COUNTRY: usaItem}});
>>
>> Or, if the schema were a little different, and if Country also had an
>> attribute called STATES, then you could just do:
>>
>>    store.getValues(usaItem, 'STATES');
>>
>> Or if you wanted you could have a schema where COUNTRY really was a
>> foreign key with {type: 'String'}, rather than an item reference with
>> {kind: 'Country'}, and then you could do:
>>
>>    store.fetch({query: {COUNTRY: 'USA'}});
>>
>> :o) brian
>>
>>
>>
>>
>> _______________________________________________
>> dojo-contributors mailing list
>> dojo-contributors at dojotoolkit.org
>> http://dojotoolkit.org/mailman/listinfo/dojo-contributors
> 
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-contributors




More information about the dojo-contributors mailing list