View Full Version : When create on proxy is called?

23 Mar 2012, 12:57 AM
I am very confused about proxy methods. I made a model like this:
Ext.define('My.ModelFile', {
extend: 'Ext.data.Model',
fields: [
name: 'id',
type: 'int',
useNull: false
{name: 'name', type: 'string'},
{name: 'location', type: 'string'}

and a store:
var store = Ext.create('Ext.data.Store', {
model: 'My.ModelFile',
autoLoad: true,
autoSync: true,
proxy: {
type: 'ajax',
extraParams: {component: component},
api: {
read: '/components/fill-files-component/',
destroy: '/components/destroy-file-component/',
create: '/components/add-file-component/',
update: '/components/update-file-component/'
reader: {
type: 'json',
successProperty: 'success',
root: 'data',
messageProperty: 'message',
writer: {
type: 'json',
writeAllFields: false,
root: 'data',

When I try to add record to the store:

store.insert(0, {'id' : 1, 'name': 'smth', 'location': 'smth'})

I can see a new record in a grid that I set my store to, but create method is not called, so i can not do proper actions on server side. I assume it has something to do with id... If I put emty string as id of the record, create is successfully called.
What i am doing wrong?
Thanks in advance...

23 Mar 2012, 4:30 AM
this is because Extjs works bit weird when you set an id, its kinda a bug.
when you set an id Extjs thinks that record its already saved (exists in the server side)
you can check this doing

store.getAt(0).phantom // will be false
// phatom=true is a record that doesnt exists in the server side

so you have 2 options, one is never assign ids to records if you want to create them which is weird ;D
another way is to set phantom to true manually, something like the next code

store.insert(0, {'id' : 1, 'name': 'smth', 'location': 'smth'})
store.getAt(0).phantom = true

i dont know all the consecuences of setting phantom to true manually but it should work, if you do
store.getAt(0).save() will trigger a create action, if u dont set phantom to true, will trigger an update action,
this only happens when you give ids to models, manually.
as i said its kinda a bug i didnt report because seems to come from Extjs designers that were on drugs or something (joke)