Shalev Shalit
Shalev Shalit

Reputation: 1963

Extjs 4 - create new empty Record from Store without Model

I have tried to create a new empty record without creating a model.

Accidentally I tried to run this:

new new storeComp.model()

and it actually works!

anyone know any solution for this or an answer to how is it working ?

Thanks! Shalev

Upvotes: 2

Views: 7522

Answers (2)

rixo
rixo

Reputation: 25001

Stores that are not configured with a model will create an anonymous one implicitly. This is explained in the docs for the implicitModel private property (the store needs to know that because if it uses an implicit model, it must destroy it when it is itself destroyed).

In the end that means that you can safely expect any store to be backed with a model.

Upvotes: 8

Sivakumar
Sivakumar

Reputation: 1487

I faced the same problem for an associative store. For that i have used below JSON format to load project store. So automatically empty record is created in associative (project-resources) Store.

Store:

Ext.define('App.store.Projects', {
   extend : 'Ext.data.Store',
   model : 'App.model.Project'
});

Models:

Ext.define("App.model.Project", {
    extend: 'Ext.data.Model',
    idProperty : 'id',
    uses : ['App.model.ProjectResource'],
    fields: [
        { type: 'auto', name: 'id'},
        { type: 'number', name: 'customerid'},
        { type: 'string', name: 'projectcode'}
    ],
    associations: [
    {type: 'hasMany', model: 'App.model.ProjectResource', name: 'Resources', storeConfig: { remoteFilter: true }}
    ]
});

Ext.define("App.model.ProjectResource", {
    extend: 'Ext.data.Model',
    idProperty : 'id',
    fields: [
        { type: 'number', name: 'id'},
        { type: 'string', name: 'name'},
        { type: 'number', name: 'projectid'},
        { type: 'auto', name: 'resourceid'}
    ],

    associations : [
    {type : 'belongsTo', model: 'App.model.Project'}
    ]
});

JSON Format:

 [
        {
            "id": "105",
            "customerid": "105",
            "projectcode": "ALN01",
            "Resources": {}
        }
]

Loading store with empty object (like "Resources": {}) will create empty model.

Upvotes: 1

Related Questions