[Dojo-interest] JsonRestStore updates and $ref lazy refrences

Peter Svensson psvensson at gmail.com
Tue Aug 12 14:29:11 UTC 2008


Maulin, Kris. Thanks a lot (again) for your answers. I'm building a small
backend for google app engine with a couple of friends, and we were
discussing back and forth on how to handle references between differnt
db.Model entities in json back and forth to the store.

It's excellent that the store will support the $ref attribute when updating,
since it simplifies the development very much.

The code is at http://code.google.com/p/gae-json-rest/  (just svn at the
moment), and is very much not done yet, but does support GET :)

Cheers,
PS

On Tue, Aug 12, 2008 at 3:47 PM, Kris Zyp <kris at sitepen.com> wrote:

>  Modifying two objects from two different tables like you describe will
> result in 2 PUT requests:
> PUT /foo/1
> {
>   id: "/foo/1",
>   abc: 667,
>   bar: {$ref: "/bar/2"}
> }
> PUT /bar/2
> {
>   id: "/bar/2",
>   quux: 42
> }
>
> On saves, the rule is that if the value is a identifiable object, than a
> $ref reference is used. Therefore even if /bar/2 was loaded as a compound
> object, JsonRestStore would still behave the same, making 2 PUT requests as
> result of the action you described. Here is how /foo/1 and /bar/2 could be
> loaded as a compound object:
> GET /foo/1
> {
>   id: "/foo/1",
>   bar: {id: "/bar/2",
>         quux: 4711
>     },...
>
> Now if the nested object was not identified, then modifications to that
> object would result in PUTs to the parent object. For example if we loaded:
>  GET /foo/1
> {
>   id: "/foo/1",
>   bar: {quux:4711}
> }
>
> and did:
> fooStore.setValue(fooObject.bar, "quux", 42);
>  fooStore.setValue(fooObject, "abc", 667);
> fooStore.save();
> This would result in:
>  PUT /foo/1
> {
>   id: "/foo/1",
>   abc:667,
>   bar: {quux:42}
> }
>
> Thanks,
> Kris
>
> ----- Original Message -----
> *From:* Peter Svensson <psvensson at gmail.com>
> *To:* dojo-interest at dojotoolkit.org
> *Sent:* Tuesday, August 12, 2008 1:41 AM
> *Subject:* [Dojo-interest] JsonRestStore updates and $ref lazy refrences
>
> Hi!
>
> I've been tinkering a bit (more) with JsonRestStore and really appreciate
> the lazy loading. But I wonder what happens if I have a hierarchical object,
> like this;
>
> {
>   id: "/foo/1",
>   abc: 17,
>   bar: {$ref: "/bar/2"}
> }
>
> And
>
> {
>   id: "/bar/2",
>   quux: 4711
> }
>
> Which are loaded in two steps by JsonRestStore (first /foo/1 and then later
> on /bar/2).
>
> Now we modify /bar/2 (set quux to 42, for instance) *and* we modify /foo/1
> (by setting abc to 667). Now we call store.save().  What will the store do
> with the bar reference in foo when updating???
> Will it create a compound object where bar is 'pulled in' inside foo, or
> will it use the $ref notation?
>
> Also, and related, will it update only foo or will it issue a separate PUT
> for both the foo and bar objects?
>
> Thansk for any clarification!
>
> Cheers,
> PS
>
> ------------------------------
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://dojotoolkit.org/docs/book
> Forums: http://dojotoolkit.org/forum
> Dojo-interest at dojotoolkit.org
> http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
> _______________________________________________
> FAQ: http://dojotoolkit.org/support/faq
> Book: http://dojotoolkit.org/docs/book
> Forums: http://dojotoolkit.org/forum
> Dojo-interest at dojotoolkit.org<http://dojotoolkit.org/forumDojo-interest@dojotoolkit.org>
> http://turtle.dojotoolkit.org/mailman/listinfo/dojo-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://turtle.dojotoolkit.org/pipermail/dojo-interest/attachments/20080812/d945db8f/attachment.html 


More information about the Dojo-interest mailing list