kripod / knex-orm

Knex-based object-relational mapping for JavaScript.
MIT License
61 stars 6 forks source link

Saving related properties of Models #3

Open kripod opened 8 years ago

kripod commented 8 years ago

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

const company = new Company({
  email: 'famous@company.com',
  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.