realmadrid2121 .
Posts: 0
Joined: Mon Sep 22, 2014 1:08 am

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

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

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

Hello,

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

realmadrid2121 .
Posts: 0
Joined: Mon Sep 22, 2014 1:08 am

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

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

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

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

realmadrid2121 .
Posts: 0
Joined: Mon Sep 22, 2014 1:08 am

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

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

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

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")

realmadrid2121 .
Posts: 0
Joined: Mon Sep 22, 2014 1:08 am

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

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

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

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.

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

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

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?

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

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

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

Return to “Issues”