Gail
Posts: 0
Joined: Tue Mar 06, 2012 12:34 am

Foreign Key Concept for UserId in the Database for User Photos

I'm following these tutorials to allow an app user to register, take a photo and upload the photo to the database so the photo is tied to their userId.

http://docs.appery.io/tutorials/build...
http://docs.appery.io/tutorials/using...

Later on I will create access to the db where a manager will log in and see the photo data for only the users who are associated with their ManagerCode.

I have one custom db collection called Photo and I will also use the pre-defined User collection.

How can I implement the concept of a foreign key in the database so that when a user takes a photo, it is saved to the db under their userId?

I see that the Users collection has a field called _id
I can put a field called UserId in my Photo collection, but how can I:

  1. Save a user's autogenerated _id to settings in their local storage during user registration so the UserId is always available when a photo is uploaded to the db?

  2. Retrieve the UserId from local storage to use in the DB REST API Add Service so it can be loaded into the Photo collection when the photo is uploaded to the db?

Oleg Danchenkov
Posts: 0
Joined: Tue Apr 30, 2013 5:51 pm

Foreign Key Concept for UserId in the Database for User Photos

Hi, Gail.
1) You can get user's _id from response of Sign in/Sign up services.
For more information see
http://docs.appery.io/documentation/b...
http://docs.appery.io/documentation/b...
2) You can use mapping.

Gail
Posts: 0
Joined: Tue Mar 06, 2012 12:34 am

Foreign Key Concept for UserId in the Database for User Photos

Thanks for the quick reply.

This will be a native app and the user won't have to sign in each time to use the app. That's why I would like their user _id stored in a "Settings" screen in the app. I can create a Settings screen with a UserId field, but I need the user data to be permanently stored in local storage in the app so the user won't have to login every time they take a photo and upload it (several times a day.)

What's the best way to do that? Maybe, at the end of the registration process, I could use an OnSuccess event which would then store the user's _id, email and password in local storage variables?

Will the local storage variables retain their data even after the app is closed?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Foreign Key Concept for UserId in the Database for User Photos

Hi --

Yes. You can store all you'll need in localStorage, it will be saved after rebooting app and after refreshing it.

Return to “Issues”