I think this actually deserves a slightly more detailed explanation. I've made a note to make a blog post about this later.
Given something like this:
private function doSomeStuff():void {
var bob:Person = new Person;
bob.create();
var ugly:Zombi = new Zombie();
ugly.person = bob;
ugly.create();
}
What's wrong with this?
Well, in a synchronous universe nothing. Your bob reference can be meaningfully updated with a new ID you get from the database or elsewhere behind the scenes, when all is done with bob this method will move on to creating the ugly zombie, ugly.person = bob will resolve to a fully functional bob object which has an id, etc. Everybody is happy.
In an asynchronous universe, this won't work. You did bob.create(), bob will not be created and it will not have an ID until some unspecified time t. This has no effect on the execution of the rest of this method, which will proceed immediately. The ugly will get created immediately after you did bob.create with no regard for asynchronous nature of that call. As you'd expect, bob database instance was not yet created, it doesn't have an ID, etc. Fail.
While it's possible to deal with AIR SQLite in both synchronous and asynchronous mode, in RestfulX all CRUD operations are asynchronous independently of what service provider you use. This is done so that if you switch to some other service provider which is explicitly asynchronous (anything other than SQLite), you don't have to run around rewriting your code.
How you can you write the above to make sure that these operations perform as expected. Do the following:
private function doSomeStuff():void {
var bob:Person = new Person;
bob.create({onSuccess: onPersonCreate});
ugly.person = result;
this.bob = result; // or whatever
ugly.create();
}
In this case, you explicitly wait for the successful creation of bob, then you proceed to create an object which directly references bob ([BelongsTo]). Everybody is happy.
As far as you are concerned, until onSuccess fired or CacheUpdateEvent fired, there's no bob.
Hope this helps,
Dima