Entity with reference to other entities
Is it always true that you don’t have to use add() when you set a property of an entity which is already added?
entity User {
username : String
}entity Article {
user : User
body : String
}var us = User()
var a = Article()add(us);
a.user = us;
Submitted by Terje Pedersen on 15 April 2011 at 09:08
Issue Log
I would guess, but maybe I’m wrong that when you execute the code you show, the
Article
would not be persisted. The other way around, would persist both objects (add(a)
instead ofadd(us)
). Otherwise you could end up with an inconsistent database (pointing to objects that don’t exist). The same holds for adding toCollection
s.
I haven’t tested the code above, but when I used like Article(user=us) it got persisted without using add() on the Article. But thats ok, I only had to add a.user afterwards instead of ending up with empty articles everytime you click on add new article.
Log in to post comments