Search code examples
ionic3baqend

Retrieve nested data using Baqend - undefined


I am building an app using ionic 3 and Baqend for BaaS.

If I have the following data:

product :{
   id: xxx,
   item: {
      name: "Name",
      description: "product details.."
   }  
}

How do I retrieve the value in 'item.name'?

I tried the following but gives me 'undefined'. It works if I do product.id but not the case for nested data.

import { baqend } from "baqend";

...

db: baqend;

...

this.db.Products.find().resultList(function(results) {
   results.forEach(function(product) {
      console.log(product.item.name);
   });
});

I am following the Baqend guide: https://www.baqend.com/guide/topics/queries/


Solution

  • In most cases this happens, if you didn't define the item and name property in the schema properly. To actually nest data in a baqend model you should define the property as an embedded property (shown in the screenshot below) or as an untyped JsonObject.

    Your defined schema of Products should look similar to the following:

    Products schema

    Hope that helps so far.