Search code examples
odatajaydata

Using JayData mapping with inverseproperty for one-to-many relationships


Trying to use the JayData mapping option (per their tutorial):

<script>
    northwind.Products
        .map(function (product) {
            return {
                ProductID: product.ProductID,
                ProductName: product.ProductName,
                CategoryName: product.Category.CategoryName,
                CompanyName: product.Supplier.CompanyName,
                ContactName: product.Supplier.ContactName,

            }
        })
        .toArray(function (products) {
            console.dir(products[0]);
        });
</script>

The question is how do I do this in the cases where for example there is more than one ContactName per company, and I want to choose one based on particular criteria (e.g. last updated date). I have already defined the necessary inverseProperties in my model definition (in the js and ts files)

Thanks!


Solution

  • You have to filter your query like

    northwind.Products.filter("it.Category.CategoryName.contains('abc')").map(...)