Page 1 of 1

How can I use a pointer to assign an id to a collection

Posted: Fri Jun 13, 2014 3:50 pm
by Deki

I have read the documentation on pointers ( http://devcenter.appery.io/documentat... ) but it is still unclear to me how to use them specifically in my app. I have two collections, one is Users and the other is Cars. I want to assign an id (from the Users collection) to a user_id in the Cars collection. Can anyone tell me how to specifically do this? Also, when I do assign the id, will I be able to use this as a foreign key? For example, can I do a query on cars collection that says, give me a list of all cars with specific user id 123456?

Thanks Image

If possible, can you please explain to me the steps in this format

1) first do this
2) then do this
3) finally do this
etc...


How can I use a pointer to assign an id to a collection

Posted: Fri Jun 13, 2014 5:04 pm
by Evgene Karachevtsev

User_id column must contain the corresponding id records from the collection Users.
So you can get all machine specific user:
http://devcenter.appery.io/documentat...


How can I use a pointer to assign an id to a collection

Posted: Fri Jun 13, 2014 9:30 pm
by Deki

Evgene, your reply does not answer my question. I know that the value of _id column in Users must correspond to the user_id in Cars....that is what I am asking how to do. I have created a "Create User" service. So when I test it, it does not create any record in the Car collection (just a user record). How can I link the two collections so that I can create a car record based on the user id I choose. Also, what is special about the Pointer type? Can't I just create a "user_id" of String type and somehow connect it to the users collection? What is the difference between those two approaches? Thanks


How can I use a pointer to assign an id to a collection

Posted: Sun Jun 15, 2014 6:07 pm
by Alena Prykhodko

Deki,

The doc advised by Evgene will help you to get list of all cars with specific user id.
To correspond between collections you can use only Pointers, as they are used as references to another object.
Do you use Service based on POST method to set pointer value to collection?

Please show us what you have tried and what exactly doesn't work.


How can I use a pointer to assign an id to a collection

Posted: Mon Jun 16, 2014 2:06 am
by Deki

I get an 400 error when I try and assign a value to the user_id. Please refer to pictures

Image Image


How can I use a pointer to assign an id to a collection

Posted: Mon Jun 16, 2014 2:42 pm
by Deki

Any thoughts on this?


How can I use a pointer to assign an id to a collection

Posted: Mon Jun 16, 2014 4:42 pm
by Kateryna Grynko

Hi Deki,

Add the following code for mapping of request parameter 'user_id':prereturn '{"collName":"users", "id":"' + value + '"}';/preThis is because all queries to a field of pointer type should be like this:
http://devcenter.appery.io/documentat...