Page 1 of 1

Mapping from Array column in DB to Appery model storage Array fails when there is nothing in the DB array

Posted: Mon Nov 30, 2015 12:56 am
by realmadrid2121 .

Hello, I have a collection with an Array column containing favorite user id's. Upon user login ... I have a getUser service that maps all the users information to storage including array of favorite user id's . Everything works well. However when I have a new user login , the Rest service mapping does not work because the user doesnt have favorite s yet in the user Array column . So the mapping fails . I get a uncaught error "undefined expected to be an array" error. I am mapping to an array i created in local storage using the new Appery Storage model . It works fine unless a new user has nothing in the array column in the db then it fails. I tried adding JS in the mapping something like if (!value) { return "";} However this did not work. Please help


Mapping from Array column in DB to Appery model storage Array fails when there is nothing in the DB array

Posted: Mon Nov 30, 2015 4:47 pm
by Serhii Kulibaba

Hello,

Unfortunately it is not clear enough. Could you please provide more details, screen shots would help a lot.


Mapping from Array column in DB to Appery model storage Array fails when there is nothing in the DB array

Posted: Mon Nov 30, 2015 5:53 pm
by realmadrid2121 .

Sergiy,
Image

Above is my mapping from Get- Rest Service to storage

Image

Above is what my storage variables look like

Image

My Rest service above fails when the array in the fav_user and watchlist columns are empty . When there is info in these array columns the Rest service works and returns all the info from the collection. I would like the Rest service to return all the information from the other DB columns even if the fav_user and watchlist columns are empty since a user might not have a watchlist or fav_users .

As mentioned above this Rest service is designed to retreive all the user information and put it into storage upon login .
Thanks


Mapping from Array column in DB to Appery model storage Array fails when there is nothing in the DB array

Posted: Tue Dec 01, 2015 9:13 pm
by Serhii Kulibaba

Could you show us service's response from the browser's network tab?
Also, you can set storage values with JS on the success event of the service, e.g.:
preApperyio.storage.fav_users.set(data.fav_users);/pre


Mapping from Array column in DB to Appery model storage Array fails when there is nothing in the DB array

Posted: Wed Dec 09, 2015 6:54 pm
by realmadrid2121 .

Sergiy,
what I have is a rest service that Invoke on user login that retrieves all user information from DB user collection and MAPS them into local storage for use throughout the app. It works fine . In the mapping I map favorite users and a user watchlist from two columns in the User collection . both columns are array type. It works fine. However if a user has no favorites or no watchlist (ie. the columns in the DB are empty... the mapping to local storage fails for the entire rest service
Image Image Image Image

IS there a way to bypass this and have the REST service work even if the columns are empty ?
Thanks


Mapping from Array column in DB to Appery model storage Array fails when there is nothing in the DB array

Posted: Thu Dec 10, 2015 1:03 pm
by Serhii Kulibaba

There are no errors if service doesn't return any parameter.
Please check JS on your mapping, it can use undefined variables. Please add checking of income variable ("value")


Mapping from Array column in DB to Appery model storage Array fails when there is nothing in the DB array

Posted: Sun Dec 20, 2015 4:32 pm
by realmadrid2121 .

The fact that Im mapping to an array in storage creates an error because the appery model storage array in storage expects an array value to get mapped to it. ie. the error (undefined expected to be an array) . If its undefined the entire service fails. Is there a way via JS in the mapping I can check for undefined and STOP or ARREST the mapping ? I tried many different JS. none worked
Thnaks


Mapping from Array column in DB to Appery model storage Array fails when there is nothing in the DB array

Posted: Tue Dec 22, 2015 12:23 pm
by Serhii Kulibaba

It's hard to say blindly, but the solution might be to check if favourites[] is empty - if that, just initialize empty array and save it in localStorage, if not - leave the same behaviour that was used for non-empty data.


Mapping from Array column in DB to Appery model storage Array fails when there is nothing in the DB array

Posted: Tue Oct 18, 2016 4:55 pm
by Joe Sharples

Did you manage to find a solution for this? i'm having the exact same problem.

I have a favourites column that can only be populated once the user has signed up and started to manually favourite items, but initially this column is empty, yet u still want to save user information in local storage.

did you manage to find a way to ignore empty array columns?


Mapping from Array column in DB to Appery model storage Array fails when there is nothing in the DB array

Posted: Tue Oct 18, 2016 4:55 pm
by Joe Sharples

An alternate solution would be set the empty array column to contain "[]", this avoids the error message. But i've not been able to set the column value to "[]"

Any help would be greatly appreciated