-
Notifications
You must be signed in to change notification settings - Fork 643
Closed
Description
I have the following code:
return PurchaseTransaction.query()
.insertGraph({
site_id: siteId,
customer_id: customerId,
total: amount,
credit: amount,
purchases: purchases
})
.debug()
.then(function (result) {
// [...]
});My Model has the following definition:
class PurchaseTransaction extends Model {
static get tableName() {
return 'purchase_transactions';
}
static get jsonSchema() {
return {
type: 'object',
required: [
'site_id',
'customer_id',
'success',
'biller_id',
'biller_transaction_id',
'total',
'billed',
'credit'
],
properties: {
id: { type: 'integer' },
site_id: { type: 'integer' },
customer_id: { type: 'integer' },
success: { type: 'integer', default: 1 },
timestamp: { type: 'string' },
updated: { type: 'string' },
biller_id: { type: 'integer', default: 0 },
biller_transaction_id: { type: 'string', maxLength: 255, default: '' },
total: { type: 'number' },
billed: { type: 'number', default: 0 },
credit: { type: 'number', default: 0 }
}
};
}
static get modelPaths() {
return [__dirname];
}
static get relationMappings() {
return {
purchases: {
relation: Model.HasManyRelation,
modelClass: 'Purchase',
join: {
from: 'purchase_transactions.id',
to: 'purchases.transaction_id'
}
}
};
}
}In 0.6.2, the .debug() method produces the following:
{ method: 'insert',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ 0, 0, '', 27, 529, 1, 1, 27 ],
__knexQueryUid: '621ed504-2e0e-48a0-8907-692189e90631',
sql: 'insert into `purchase_transactions` (`billed`, `biller_id`, `biller_transaction_id`, `credit`, `customer_id`, `site_id`, `success`, `total`) values (?, ?, ?, ?, ?, ?, ?, ?)' }
In 0.7.2, it produces this:
{ method: 'insert',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ 27, 529, 1, 27 ],
__knexQueryUid: 'f0cdd177-b8cd-4f1b-bae0-c892a00043e6',
sql: 'insert into `purchase_transactions` (`credit`, `customer_id`, `site_id`, `total`) values (?, ?, ?, ?)' }
And I get the following error:
insert into `purchase_transactions` (`credit`, `customer_id`, `site_id`, `total`) values (27, 529, 1, 27) - ER_NO_DEFAULT_FOR_FIELD: Field 'biller_id' doesn't have a default value
In 0.7.2, none of the default values declared in my jsonSchema properties are included in the insert statement: billed, biller_id, biller_transaction_id, success.
Metadata
Metadata
Assignees
Labels
No labels