File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -455,6 +455,10 @@ function fillup(Model, values={}) {
455455 const missing_keys = Object . keys ( schema ) . filter ( k => ! result_keys . includes ( k ) ) ;
456456
457457 for ( let k of missing_keys ) {
458+ if ( schema [ k ] instanceof PrimaryKey ) {
459+ continue ;
460+ }
461+
458462 if ( schema [ k ] . defaultValue !== undefined ) {
459463 values [ k ] = schema [ k ] . get_default ( ) ;
460464 }
Original file line number Diff line number Diff line change @@ -16,21 +16,23 @@ class Model {
1616 throw new Error ( 'Models can only be instanciated with an object as parameter' ) ;
1717 }
1818
19+ // Will fill up "from db" as well
20+ const values = Fields . fillup ( this . constructor , params ) ;
21+
1922 if ( validate ) {
2023 // Validate object
21- Fields . validate ( this , params ) ;
24+ Fields . validate ( this , values ) ;
2225 }
2326
2427 // Create PK if needed
25- let { pk, key } = Fields . get_pk ( this , params ) ;
28+ let { pk, key } = Fields . get_pk ( this , values ) ;
2629
2730 this [ key ] = pk ;
2831 this . __updated = __updated ;
2932 this . __created = __created ;
3033 this . __deleted = __deleted ;
3134
3235 // Populate with validation having been performed earlier
33- const values = Fields . fillup ( this . constructor , params ) ;
3436
3537 for ( let [ k , v ] of Object . entries ( values ) ) {
3638 this [ k ] = v ;
Original file line number Diff line number Diff line change @@ -418,7 +418,7 @@ describe('Models', () => {
418418 TestModel . VALIDATION_SCHEMA = {
419419 test_field : new Fields . String ( { defaultValue : ( ) => 'functional vlaue' } ) ,
420420 test_field_auto : new Fields . Number ( { defaultValue : 54 } ) ,
421- default_empty_string : new Fields . String ( { defaultValue : '' } ) ,
421+ default_empty_string : new Fields . String ( { defaultValue : '' , blank : true } ) ,
422422 default_zero : new Fields . Number ( { defaultValue : 0 } ) ,
423423 default_null : new Fields . Number ( { nullable : true , defaultValue : null } ) ,
424424 default_false : new Fields . Boolean ( { nullable : true , defaultValue : false } ) ,
You can’t perform that action at this time.
0 commit comments