Hi TQ,
>
> Can we have this?
>
> @MOdel
> class Parent {
> List<Child> childs = new ArrayList<Child>();
> }
>
> @Model Child {
>
> }
>
>
We can have bidirectional one to many relationships as follows:
@Model
public class Parent {
@Attribute(primaryKey = true);
private Key key;
@Attribute(persistent = false)
private InverseModelListRef<Child, Parent> childListRef =
new InverseModelListRef<Child, Parent>(Child.class, "parentRef", this);
...
}
@Model
public class Child {
@Attribute(primaryKey = true);
private Key key;
private ModelRef<Parent> parentRef =
new ModelRef<Parent>(Parent.class);
...
}
> If so, how to get parents based on child's property in Slim3?
Query for children:
ChildMeta cm = ChildMeta.get();
List<Child> children = Datastore.query(cm).filter(...).asList();
Gathering parent keys:
Set<Key> keys = new HashSet<Key>();
for (Child child : children) {
keys.add(child.getParentRef().getKey());
}
Batch get for parents:
List<Parent> parents = Datastore.get(Parent.class, keys);
The document of relationships is here:
http://sites.google.com/site/slim3appengine/slim3-datastore/relationships
Hope this helps,
Yasuo Higa
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.