Search code examples
javascriptangularjsbreeze

Specify a Breeze entity default resource name with a parameter


I have an AngularJS app using breeze for data. The back end is OData v4.

I have a Customer entity and an Address entity defined in my metadata store.

The API defines the default endpoint for Address to be path/api/Customers({id})/Addresses

I am able to query a particular customer and get his/her address okay by using $expand.

However, if I edit or add a new Address for that customer (say, customer #42) and then call entityManager.saveChanges(), I need the POST/PATCH request to go to path/api/Customers(42)/Addresses.

Is there any way to configure my Address entity to accept a parameter in its defaultResourceName property?


Solution

  • You have a few options here - one is to call saveChanges and pass in some custom saveOptions -

    http://www.getbreezenow.com/documentation/saving-changes

    With this you could use

    var so = new SaveOptions({ resourceName: entityId + "/Addresses" });
    // null = 'all-pending-changes'; saveOptions is the 2nd parameter
    myEntityManager.SaveChanges(addressEntities, so );
    

    You will probably need to configure this for your needs.

    The other possibility is to use breeze.ajaxPost to create a custom saveChanges method on your own on the client. This is more work intensive but allows you additional customization.