Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:47:36+00:00 2026-06-15T01:47:36+00:00

Suppose I have the following data structure: a Customer entity that has a collection

  • 0

Suppose I have the following data structure: a Customer entity that has a collection of Orders (1 to n relationship). So, Customer.Orders() returns an array of zero or more Orders.

Now, I create a new Customer newCustomer, and a new Orders entity array. This Orders entity array is assigned to the Customer. All entities have the “Added” entity state.

Then, I call saveChanges() as follows:

manager.saveChanges([newCustomer])

I used the saveChanges()‘s [entities] parameter according to this documentation: http://www.breezejs.com/sites/all/apidocs/classes/EntityManager.html#method_saveChanges

I would expect that both the newCustomer and its Orders array would be saved in the server, but only the newCustomer was saved.

Is there any way to save the newCustomer and its Orders array? Maybe I could pass all entities in the [entities] parameter, but this would be verbose and a point of bugs. I know I could call only saveChanges() method to save all entities, but I want to save only a specific entity completely.

Thanks in advance,

Bernardo Pacheco

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:47:39+00:00Added an answer on June 15, 2026 at 1:47 am

    Update 8 Oct 2014

    I’m sticking with my original advice to avoid cherry-picking changes.

    But if you must, I am reminded by @utopik’s comment that breeze labs has the getEntityGraph plugin which may make such scenarios considerably easier.

    Install the getEntityGraph.js plugin script after breeze itself. Then you should be able to say:

    // get flat array of cust and its orders
    var graph = manager.getEntityGraph(newCustomer,'Orders'); 
    manager.saveChanges(graph);   
    

    You do have to state explicitly which navigation paths should be included using the breeze "expand" clause syntax.

    This approach will send both changed and unmodified graph entities to the server. You could filter out the unchanged ones:

    var changes = manager
        .getEntityGraph(newCustomer,'Orders')
        .filter(function(entity){
            return !entity.entityAspect.entityState.isUnchanged();
        }); 
    
    manager.saveChanges(changes)
    

    getEntityGraph may make it into the core product someday. Until then, there is breeze labs.

    Original Answer

    Excellent question, BP. Your concern about omitting entities that should be saved is why we discourage calling saveChanges(array-of-entities). The routine, safe thing to do is simply call saveChanges(). This will save every entity with pending changes in a single transaction.

    We offer the selective save overload (the one you tried) for the special case in which you need to cherry pick the entities that should be saved. You must be careful when you do this; you don’t want to orphan related entities … such as the new orders that you added to your new customer. It’s really easy to make a mistake … as you rightly point out.

    I can see that you want Breeze to infer that it should include the child orders with the parent customer. But you’re asking Breeze to guess what you really want to do. If Breeze followed the cookie trail from newCustomer down every branch of every navigation path, who knows what it would save … or not save? We give you the option to cherry pick; now it’s your responsibility to say precisely what you mean.

    If you really needed to save the newCustomer and its orders, you could write:

    var entitiesToSave = newCustomer.Orders().slice(); // Make sure it's a copy!
    entitiesToSave.push(newCustomer); // add the newCustomer too.
    manager.saveChanges(entitiesToSave); // save newCustomer and its orders.
    

    But I beg you to avoid this approach. If you find yourself often in this position of needing to save subsets of entities-with-changes, I urge you to re-examine your workflow. Perhaps you need multiple managers … as described here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following types of data: class Customer { String id; //
I have a table in database which has following structure(data) : +--------------------------+ Organization +--------------------------+
Suppose you have a data frame with the following structure: df <- data.frame(a=c(1,2,3,4), b=c(job1;job2,
Suppose I have a DataFrame which has a subindex structure like the following, with
I have the following json and suppose that I can't modify it: { structure:
Suppose I have a function that will return a large data structure, with the
Suppose the following scenario: I have a master database that contains lots of data,
Suppose I have the following data frame: Data1 X1 X2 1 15 1 2
Suppose we have the following table data: ID parent stage submitted 1 1 1
Suppose a Ruby project with the following structure... project/ |-- data | `-- data.yaml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.