knex-orm icon indicating copy to clipboard operation
knex-orm copied to clipboard

Saving related properties of Models

Open kripod opened this issue 8 years ago • 0 comments

The easiest way to describe this feature is by providing a syntactical example:

const company = new Company({
  email: '[email protected]',
  employees: [
    new Employee({ name: 'John Doe' }), // New Employee
    new Employee({ id: 6 }, false), // Existing Employee
  ],
});

await company.save();

The code above should insert a new Company to the database, but before that, the new Employee (first in the array) shall be stored. Related object trees should be stored recursively, in an order defined by the relations of the referenced objects.

kripod avatar Apr 13 '16 18:04 kripod