Page 1 of 2

Combine queries from multiple Collections in list

Posted: Wed Mar 02, 2016 6:14 am
by Michael Droll

I am trying to do something similar to this thread. https://getsatisfaction.com/apperyio/...
The differences are that I'm doing a count of all records that match the "id" from the "Properties" collection to the "PropID" column of the "Comments" collection and that match "pro" in the "ProCon" column of the "Comments" collection. and mapping the "count" to a label in the list that matches the "id". And then repeat the process again to count "con" in the "ProCon" column.

Here is the design:
Image

here is the flow:

on page load: Invoke service "GetProperties" a list service
On service success: Mapping
Image topic m

in the mapping I have the _id mapped to a invisible label in the listitem and added JS to the mapping

I used the JS from the thread mentioned above but I dont understand it enough to make it work. but here is what I got so far.
codefunction successFunction (data){
console.log(data);
if (data.length >0) {
$(element).closest("li").find("[dsid=PropIDLabel]").text(data[0].Body);

Code: Select all

             } 

}
ProsCount.execute({
data: {
"where": '{"PropID":"'+ value +'","ProCon": "pro"}'
},
success: function(data) {
successFunction(data);
}
});
return value;/code

Here is the mapping for the "CountPros" service.
Image
I'm not sure if I need to map the count service or not. It does not change the results of my test.

When I test the app and the page loads here is what the console log shows
Image
Here is the network, it is executing the service with the id of each property in the list.
Image
but the response is missing.
Image
Image

I'm not sure but I think my query syntax is wrong in the JS. (note: I use the exact same query in another part of my app without a problem, it is only when I try this list combination that it gets not response.)

Thank you for the help.


Combine queries from multiple Collections in list

Posted: Wed Mar 02, 2016 9:11 am
by Serhii Kulibaba

Hello,

Please use $and parameter for multiple where clauses: https://devcenter.appery.io/documenta...


Combine queries from multiple Collections in list

Posted: Wed Mar 02, 2016 1:40 pm
by Michael Droll

This still does not work, returns empty response.
Image
Image

And if I test the query in the builder it returns a count of "0"
Image

but if I use the old syntax it works (without the $and)
Image


Combine queries from multiple Collections in list

Posted: Fri Mar 04, 2016 3:18 pm
by Michael Droll

Any help?


Combine queries from multiple Collections in list

Posted: Fri Mar 04, 2016 9:14 pm
by Serhii Kulibaba

Could you check the DB, how many these items there?


Combine queries from multiple Collections in list

Posted: Sat Mar 05, 2016 5:24 am
by Michael Droll

For this particular query code{"PropID":"56ba3cdce4b0c4161647839d","ProCon":"pro"} /code there are 6 records. here is a picture of the app running while testing. the "Pros:" should have the response next to it, not the "...." that is just there for the loading. but the service is responding empty.
Image
each list item will be different. altogether there are 21 records in the database for now. but that increase quickly when the app is updated with this new feature.

here is another page in the app using the above query without any problems.
Image


Combine queries from multiple Collections in list

Posted: Sat Mar 05, 2016 6:05 am
by Michael Droll

Ok so after playing with this some more I think I have managed to get the service to respond correctly for each list item.

I used the following JS code.
code
function successFunction (data){
console.log(data);

Code: Select all

 if (data.length >0) { 
     $(element).closest("li").find("[dsid=PropIDLabel]").text(data[0].Body); 

 } 

}
ProsCount.execute({
data: {
"where": '{"PropID":"'+value+'","ProCon":"pro"}',
"count": "1"
},
success: function(data) {
successFunction(data);
}
});
return value;

/code

But now the responses are not getting into the list items. is there something different with this type of mapping, should I not have any mapping for the second list service called by JS?

here is the mapping for the secondary list service.
Image

I'm pretty sure it has something to do with this part of the JS
code $(element).closest("li").find("[dsid=PropIDLabel]").text(data[0].Body);/code I really have no clue what this does. I think it is supposed to find the matching label??? I don't even know if this is correct since I took it from the other thread and swapped out the label name for mine.


Combine queries from multiple Collections in list

Posted: Sat Mar 05, 2016 3:46 pm
by Serhii Kulibaba

Please clarify, where do you run function "successFunction"? Is it from the success event? I can't see response parameter "Body" in your service. Also, there object "element" is not available


Combine queries from multiple Collections in list

Posted: Sun Mar 06, 2016 3:54 am
by Michael Droll

I'm not sure what the "Body" you are referring to, where would I find this?

The "successFunction is being ran in the success mapping on my "GetProperties" list service. here is a pic of the mapping.
Image
in this mapping is the JS that calls the "successFunction".

What should I have instead of "element"???
I'm still new to JS.


Combine queries from multiple Collections in list

Posted: Sun Mar 06, 2016 4:08 am
by Michael Droll

is this the "Body" you are asking about?
Image