Load Entity using Ref in Objectify

153 views
Skip to first unread message

Azeem Haider

unread,
Nov 22, 2017, 12:16:02 AM11/22/17
to Google App Engine

I'm and new in objectify and datastore. I have three kinds 1-user, 2-post, 3-feed user is parent of post and feed and feed contain Ref of post.


Feed


public class Feed {

@Id Long id;
@Parent Key<User> userKey;
Ref<Post> post;


Post


public class Post {

@Id Long id;

@Parent Key<User> userKey;

String content;


Get Entity


Key key = Key.create(User.class, 124);
    Query query = ofy().load().type(Feed.class).ancestor(key);

    Feed feed = (Feed) query.list().get(0);

    out.print(feed.getPost()); // return LiveRef(Key<?>(Post(4644337115725824)))
    out.print(feed.getPost().get()); // return null


I want to get the content of Post. How can I do that ? Post is exist with this id in datastore.

Yannick (Cloud Platform Support)

unread,
Nov 22, 2017, 3:40:01 PM11/22/17
to Google App Engine
Hello, to get started with using Objectify you should read through this walk-through on Storing Data with Objectify and Datastore as well as the Objectify Wiki.

If you want to figure out what you're doing wrong with your classes, you should post their full code. This is best done by creating a question on Stack Overflow using one of the tags monitored by our community technical support team.
Reply all
Reply to author
Forward
0 new messages