Jordi Niubo
Posts: 0
Joined: Tue Nov 26, 2013 12:08 pm

Querys to 2 or more collections

Hi, i have 1 database with some collections. In one i have user information. In other one have the photo of this user.

I know how to get the user and then the photo. There are any form that with only the id of user, with only one Query, can get the information of the table user and the photo of the other table?

Thanks

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Querys to 2 or more collections

Hi Jordi,

If you have a collection with a field of pointer type that points at another collection, you can query both collections simultaneously. Add a request parameter 'include' where pass names of collections that you point at from the current collection. Find more here: http://docs.appery.io/documentation/b...

Jordi Niubo
Posts: 0
Joined: Tue Nov 26, 2013 12:08 pm

Querys to 2 or more collections

And for create this relation we need 2 querys?

One for create the first collection and get the id and other one for create the second collection with the pointer to the first?

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Querys to 2 or more collections

Hello,

Yes, you need 2 queries.

adam griffin
Posts: 0
Joined: Tue May 21, 2013 8:44 pm

Querys to 2 or more collections

If I have pointers from B - A and C - A. Can I query results from B and C? If so, how? Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Querys to 2 or more collections

Hello Adam,

Please clarify, do you want in to get one query info from B supplemented with data from A and similarly in another query get info from C supplemented with data from A? Or something different?

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Querys to 2 or more collections

Adam, it does not work like that. With that example, you would need to tier it like this: A - B - C and in the include, you would need to reference them like this:

"include" : b, b.c

With this, you are collecting A, including objects from B, and within the B object, you would have another object C.

adam griffin
Posts: 0
Joined: Tue May 21, 2013 8:44 pm

Querys to 2 or more collections

Collection A has all my users info -|id|Name|email|-, Collection B is all users messages-|user_id|message|date|-, Collection C has user networks kinda like this -|follow_id|follower_id|date|-. Im trying to query all 3 at once like this. I get Collection C: created date when someone join the another user network, i will also get the user id from Collection C. Then I will take that user id and compare it to collection A id to get the user info. I will then check all the users id from Collection B with its created date. I want to then display the results from when the user first join another user network and that user messages from collection B all on the same list component.

adam griffin
Posts: 0
Joined: Tue May 21, 2013 8:44 pm

Querys to 2 or more collections

I want the response to be like ulliJoe join your network 3days ago/lilitom sent a message hour ago/li/ul

Bad Addy
Posts: 0
Joined: Fri Dec 13, 2013 9:34 pm

Querys to 2 or more collections

I am not sure you can do that via the app, because Pointers only really work with static _id's. Because you have many _id's in both Collection B and C, you would need to do this in server Code and create a new object and then pass it to the app.

To save calls, you could add a pointer from Collection B that points to Collection A, and then make another call to collect all rows in Collection C with a 'WHERE' clause that equals the user_id. In this case, you would call all messages with a user_id, and within each result would hold another object, providing you include it, that has the users info.

Then with a simple FOR statement, push them together and send it to the app in one go.

You could also do all the sorting via server code, so the device has less to do, but print the result.

Return to “Issues”