Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Defining a Relation Expanding Expression

Defining a Relation Expanding Expression

The Backend Services JavaScript SDK provides an easy way to modify read requests to expand data relations.

After initializing the Everlive instance, you need to define your expand expression in a variable. For example:

var everliveApp = new Everlive('your-app-id');

var expandExp = {
  "Likes" : {
    "TargetTypeName" : "Users"
    }
};

Having defined your expand expression, you have two options to make the request:

  • Using a Query object:

    var query = new Everlive.Query();
    query.expand(expandExp);
    
    var data = everliveApp.data('Activities');
    data.get(query)
        .then(function(data){
            console.log(JSON.stringify(data));
        },
        function(error){
            console.log(JSON.stringify(error));
        });
    
  • Using an expand data modifier:

    var data = everliveApp.data('Activities');
    data.expand(expandExp).get()
        .then(function(data){
            console.log(JSON.stringify(data));
        },
        function(error){
            console.log(JSON.stringify(error));
        });
    

Both options return the same result, but the former cannot be used in a GetById scenario, because the getById method accepts Id as a parameter and not a query object. You can use the latter in both GetByFilter (get) and GetById (getById) cases.

The Everlive.Query() option has the benefit of being able to take a query object, which is required when you need to sort or page your data before expanding it.

See Also

To learn how to build the actual expand expressions, explore the following articles:

Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.