@@ -177,10 +177,7 @@ export class Component {
177177 const element = new Element ( el ) ;
178178
179179 if ( element . isUnicorn ) {
180- if (
181- hasValue ( element . field ) &&
182- ( hasValue ( element . db ) || hasValue ( element . model ) )
183- ) {
180+ if ( hasValue ( element . field ) && hasValue ( element . db ) ) {
184181 if ( ! this . attachedDbEvents . some ( ( e ) => e . isSame ( element ) ) ) {
185182 this . attachedDbEvents . push ( element ) ;
186183 addDbEventListener ( this , element ) ;
@@ -227,6 +224,8 @@ export class Component {
227224 this . keyEls . push ( element ) ;
228225 }
229226
227+ console . log ( element . actions ) ;
228+
230229 element . actions . forEach ( ( action ) => {
231230 if ( this . actionEvents [ action . eventType ] ) {
232231 this . actionEvents [ action . eventType ] . push ( { action, element } ) ;
@@ -421,15 +420,19 @@ export class Component {
421420 */
422421 setDbModelValues ( ) {
423422 this . dbEls . forEach ( ( element ) => {
424- if ( element . db . pk === "" ) {
423+ if ( isEmpty ( element . db . pk ) ) {
425424 // Empty string for the PK implies that the model is not associated to an actual model instance
426425 element . setValue ( "" ) ;
427426 } else {
428- if ( isEmpty ( element . model . name ) ) {
429- throw Error ( "Setting a field value requires a model to be set" ) ;
427+ const dbName = element . db . name || element . model . name ;
428+
429+ if ( isEmpty ( dbName ) ) {
430+ throw Error (
431+ "Setting a field value requires a db or model name to be set"
432+ ) ;
430433 }
431434
432- let datas = this . data [ element . model . name ] ;
435+ let datas = this . data [ dbName ] ;
433436
434437 // Force the data to be an array if it isn't already for the next step
435438 if ( ! Array . isArray ( datas ) ) {
@@ -438,7 +441,7 @@ export class Component {
438441
439442 datas . forEach ( ( model ) => {
440443 // Convert the model's pk to a string because it will always be a string on the element
441- if ( hasValue ( model . pk ) ) {
444+ if ( hasValue ( model ) && hasValue ( model . pk ) ) {
442445 if ( model . pk . toString ( ) === element . db . pk ) {
443446 element . setValue ( model [ element . field . name ] ) ;
444447 }
0 commit comments