Mike W
Mike W

Reputation: 1403

Filter by the id of an embedded entity in Objectify

Let's say I have

@Entity
public class Car implements Serializable{

    @Id private Long id = null;
    @Index private Driver driver = null;
    ...
}

and

@Entity
public class Driver implements Serializable{

    @Id private Long id = null;
    ...
}

How can I filter a Car entity by the id of his driver entity in Objectify? Something like ofy().load().type(Car.class).filter("driver.id", someId).first().now();

Thanks in advance.

Upvotes: 1

Views: 857

Answers (1)

stickfigure
stickfigure

Reputation: 13556

At present, you can't. And even if you could, it would almost certainly be something awkward like filter("driver.__key__", Key.create(Driver.class, someId)). This is getting pretty far into unexplored territory. Unless you're super familiar with GAE and Objectify, you're best off dropping the @Id annotation and treating embedded entities just like regular embedded objects. There's no reason why id can't just be a regular (indexed) property.

Upvotes: 1

Related Questions