Gilson
Gilson

Reputation: 498

Make "Or" clause using objectify

I am trying to create a query in Objectify with "OR" clause, but i dont found in any place how to do it. Even reading the user's guide of Objectify v5, i don't found anything. I found only this here, but it not apply to me.

In sql the clause would be like this:

SELECT * FROM bulletin WHERE visibility = 'public' OR ownerId = :userId

Upvotes: 0

Views: 651

Answers (2)

stickfigure
stickfigure

Reputation: 13556

You can use the low-level API Query.CompositeFilter object directly, which supports some level of AND and OR composition:

com.google.appengine.api.datastore.Query.Filter filter = // see docs
ofy().load().type(Thing.class).filter(filter);

Here are some examples of how to make a composite filter:

https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Query.CompositeFilter

Upvotes: 3

Igor Artamonov
Igor Artamonov

Reputation: 35961

The problem that Google Datastore doesn't support OR filters at all (only multiply values of same field, IN).

But you can make two separate queries and join results into one.

Upvotes: 2

Related Questions