Search and Pagination on 2 Step Relations Query

Hi there,

I have a 2 Tables, User and Prescriptions where User has one to many relationship with Prescriptions.
Currently im getting attached prescriptions of a user using following query

https://api.backendless.com/v1/data/Users/{userid}?loadRelations=prescription

which works.

Prescription table has “medication” column.

But i now want two things
1- retrieve those prescriptions whose medication column has “care” or some keyword given in it.
2- How to paginate this data?

Thanks

Hello,

Use the route documented at:
https://backendless.com/documentation/data/rest/data_search_and_query.htm

with the following whereClause:Users[“prescriptions”].objectId = ‘objectId of user’ and medication = ‘care’

Regards,
Mark

I’m using Rest API, so url will be like?

https://api.backendless.com/v1/data/Users/{userid}?loadRelations=prescription&where=users["prescriptions"].objectId=user_object_id and medication Like 'care%'

No, use the URL documented in the page I referenced in my previous reply.

Documentation Page has following url

https://api.backendless.com/<version>/data/<table-name>?props=prop1,prop2&loadRelations=relprop1,relprop2&where=whereClause&pageSize=XX&sortBy=prop1,prop2&offset=ZZ

which if i change becomes as following

https://api.backendless.com/&lt;version&gt;/data/Users?loadRelations=prescription&where=medications Like 'care%'

You need to send the request with the where clause I showed to the Prescriptions table. Do not use loadRelations, simply load objects with that where clause from Prescriptions.

Sorry for misunderstanding, here is another attempt,

https://api.backendless.com/&lt;version&gt;/data/Prescription?where=whereClause:Users["prescriptions"].objectId = &lt;user object id&gt; AND medications Like 'care%'

if i fail can you make a sample url, otherwise ill throwing arrows in dark?

It should look like this:

ttps://api.backendless.com/<version>/data/Prescription?where=Users%5Bprescriptions%5D.objectId%20%3D%20%27%3Cuser%20object%20id%3E%27%20AND%20medications%20Like%20%27care%25%27

Solved, it Thanks
You guys are amazing :slight_smile:

Can i do something like that?


https://api.backendless.com/&lt;version&gt;/data/Prescription?where=Users[prescriptions].objectId = '&lt;user object id&gt;' AND (medication_a Like 'care%' OR medication_b Like 'care%' )

You should give it a try and see it for yourself. Keep in mind that with REST requests, the URL must be URL-encoded.

Worked, Awesome :slight_smile: