Problem in retrieving child records

Table Retailers has one to many relation with table Beacons and table Beacons has one to many relation with table BeaconLocalNotify. I am using following query to retrieve the records, but not able to get the desired result:

dataQuery = [BackendlessDataQuery new];

queryOptions = [QueryOptions new];

queryOptions.related = [NSMutableArray arrayWithArray:@[@"beacons",@"beacons.LocalNotify"]];

dataQuery.whereClause = [NSString stringWithFormat:@"beacons.majorVersion = \'%@\' AND beacons.minorVersion = \'%@\' AND beacons.LocalNotify.notifyStatus = 1 AND beacons.LocalNotify.StartDate <= \'%@\' AND beacons.LocalNotify.ExpirationDate >= \'%@\'",becMajor, becMinor, [NSDate date], [NSDate date]];

dataQuery.queryOptions = queryOptions;

use load method to load relations http://backendless.com/documentation/data/ios/data_relations_retrieve.htm#twostep

Thanks for your reply!

I am able to get the child records but the where clause condition doesn’t work for child table “beacons.LocalNotify.notifyStatus = 1 AND beacons.LocalNotify.StartDate <= ‘%@’ AND beacons.LocalNotify.ExpirationDate >= ‘%@’”

So, using two-step relations retrieval will solve the problem?

Have you tried testing your “where clause” using console?

Hi Mark,

Do you mean to say in REST Console? I tried in REST console, it didn’t work there.

Yes, I mean REST Console. If it didn’t work there, the problem must be in the query syntax. Can you show exactly what you’re trying there?

I appreciate your prompt reply!

Actually, I am trying to get the records from child tables based on where clause query. Table Retailers has one to many relation with table Beacons and table Beacons has one to many relation with table BeaconLocalNotify.

here is the query I am using:

dataQuery = [BackendlessDataQuery new];

queryOptions = [QueryOptions new];

queryOptions.related = [NSMutableArray arrayWithArray:@[@"beacons",@"beacons.LocalNotify"]];

dataQuery.whereClause = [NSString stringWithFormat:@"beacons.majorVersion = \'%@\' AND beacons.minorVersion = \'%@\' AND beacons.LocalNotify.notifyStatus = 1 AND beacons.LocalNotify.StartDate &lt;= \'%@\' AND beacons.LocalNotify.ExpirationDate &gt;= \'%@\'",becMajor, becMinor, [NSDate date], [NSDate date]];





BackendlessCollection *collection = [backendless.persistenceService find:[Retailer class] dataQuery:dataQuery error:&fault];

You should test your where clause in REST Console anyway. Try this:

    Open Backendless console and select your app Click Data and then click the Retailer table Enter your where clause in the search field and make sure the SQL Search toggle is set to ON
You need to make sure the search query is correct and you're getting expected data.

Thanks Mark! I will try to execute the query in REST Console. I will let you know If I find any difficulty.

Aman,

I told you REST Console first, but it it really is just a search bar on the Data Browser tab.

Regards,
Mark