Search code examples
angularjsone-to-manybackand

How to create objects that have relationships when using Backand BaaS?


I am using Backand BaaS for my ionic app. My model consists of two tables: 1. Users 2. Trips

A one-to-many relationship has been established between 'Users' and 'Trips'.

'Users' has a collection field that is a collection of 'Trips' and 'Trips' has a owner field that is an object of 'Users'.

What is the correct way to create an object so that upon creating I am assigning the correct owner ('Users' object) to 'Trips' collection field ?


Solution

  • When POSTing a new Trip use this for the Trip Object

    {
    tripName:"asdf"
    owner:1
    }
    

    In the users object it will look like this

    {
    id:1
    fName:"david"
    trips:[{__metadata: {id: 1}, tripName: "asdf"}]
    }