Open dalssoft opened 2 years ago
Given:
const User = entity('User', { id: id(Number), description: field(String), }) const Customer = entity('Customer', { id: id(Number), description: field(String), user: field(User) // <---- relationship 1:1 }) class CustomerRepository extends Repository { constructor(injection) { super({ entity: Customer, table: "customer", knex: connection, foreignKeys: [{ userId: String }], // <---- relationship 1:1 on DB }) } }
when:
const customer = Customer.fromJSON({ id: 1, description: "C1", user: { id: 2 } }) const repo = new CustomerRepository() const ret = await repo.insert(customer)
it should insert not only the fields for customer table (id and description) but also user_id
id
description
user_id
I will act on it.
Given:
when:
it should insert not only the fields for customer table (
id
anddescription
) but alsouser_id