Question

I'm working in Windows Azure mobile services. I got 2 tables Plans 1:N Subscription (one plan have many subscription related, a subscription have one plan related). I'm not very acquainted with the JS server scripts. When I Insert a new Subscripton I need to query the Plan that this new subcription has (the planId is coming from the client in the subscription object). So I've this:

function insert(item, user, request) 
{
    var planTable = tables.getTable("Plan");
    //Here I want to select the plan from planTable using item.PlanId

    request.execute();
}
Was it helpful?

Solution

You can do it like this (official documentation is available here):

 planTable.where({
        id: item.PlanId
    }).read({
        success: function(results) {
            // Do something here!
            request.execute();
        }
    });

OTHER TIPS

You can find exactly this scenario explained in the blog post at http://blogs.msdn.com/b/carlosfigueira/archive/2012/09/11/supporting-complex-types-in-azure-mobile-services-clients-implementing-1-n-table-relationships.aspx. It contains examples which expands on Sandrino Di Mattia's answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top