[dojo-contributors] dojo.data Schema API

Jon Sykes lists at jpsykes.com
Wed Aug 22 09:03:29 EDT 2007


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




More information about the dojo-contributors mailing list