This is a migrated thread and some comments may be shown as answers.

Changing Model id field's defaultValue?

1 Answer 660 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Troy
Top achievements
Rank 1
Troy asked on 15 Nov 2016, 07:01 PM

My back-end prefers a null value in the primary key for adding new records, but kendo uses 0 for numeric fields. If I change the "defaultValue" for a numeric model field that is defined as the 'id' field for the model, will this cause any problems with create operations or anything else that deals with new instances of the model?  Model has a "isNew" function, so it looks like things should work even if the defaultValue is changed from the normal zero value, I just wanted to be sure in the real world there won't be any nasty side-effects or anything that explicitly compares to zero instead of relying on isNew().  So:

var dataSource = new kendo.data.DataSource({
  schema: {
    model: {
      id: "dbID"
      fields:{
         dbID: {type:"number", defaultValue:null},
      }
    }
  }
});

 

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 17 Nov 2016, 07:14 AM

Hello Troy,

Indeed, it should be OK to change the defaultValue to null. However, for your scenario it might be sufficient to just set the nullable option to true. This will bypass defaultValue assignment  altogether and leave the field value undefined. 

Regards,
Rosen
Telerik by Progress
Kendo UI is ready for Visual Studio 2017 RC! Learn more.
Tags
Data Source
Asked by
Troy
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or