Start a new topic

Upgrading from 1.22 queries with relations don't return any entities

This is a piece of code that, when linked with K.1.23-26 stop to work as expected and returns an empty array. No error.

KCSQuery *query = [KCSQuery query];

[query addQuery:[KCSQuery queryOnField:@"status" withExactMatchForValue:@0]];

[query addQuery:[KCSQuery queryOnField:@"organization" withExactMatchForValue:self.model.organization]];

[_store queryWithQuery:query

withCompletionBlock:^(NSArray *objectsOrNil, NSError *errorOrNil)


addendum: removing the relation from the query, results are correctly fetched.
Can you explain a little more? Can you send me a complete example?
This is another example, just after app startup:

[self.user refreshFromServer:^(NSArray *objectsOrNil, NSError *errorOrNil)


if (!errorOrNil)


self.user = objectsOrNil.firstObject;

KCSQuery *query = [KCSQuery queryOnField:@"user" withExactMatchForValue:self.user];

NSNumber *type = @(ORGANIZATION_TYPE);

[query addQuery:[KCSQuery queryOnField:@"type" withExactMatchForValue:type]];

[self loadEntitiesWithQuery:query completionHandler:^(NSArray *entities)


// 0 entities in K 1.26 - 1 entity in K 1.22

Kinvey id: 6CA96184-A7EB-4A57-8963-99E7C00A67D2
The request id for the last example was: b570ad4896bc4586bdce806099f0b211
[query JSONStringRepresentation]


using this query on API console gives no result

using {"type":100} gives result
I found this:

the query works only this way:

[query addQueryOnField:@"user._id" withExactMatchForValue:self.user.userId];

it doesn't work anymore with this syntax:

[query addQueryOnField:@"user" withExactMatchForValue:self.user];

(working until version 1.22 and much more better)

The user field is a KinveyRef object, in this case?
Yes it is.

In the case of the first example "organization" it's also a KinveyRef object.

Using "organization._id" and self.model.organization.entityId the query is working.
Thanks. Using the _id piece is the correct behavior. We had a convenience part before that put it in the "_id" automatically when using a target object, but that must have fallen out since then. We will fix that in a future release.
Login or Signup to post a comment