[dojo-contributors] dojo.data Schema API

Brian Douglas Skinner skinner at dojotoolkit.org
Tue Aug 21 20:59:05 EDT 2007

>>     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

More information about the dojo-contributors mailing list