jeudi 5 février 2015

Model Association id is not sent to the server

Hello,

I have a strange problem an I don't figure out a solution.


My Extjs application is linked with json to a backend I do develop.

So when a new model is creation on the client side and I save it, the following POST reuquest is sent to the server:


http://localhost/roadmapprojet/api/f...=1423154456259



Code:



{"typeEnumId":2,"voteDate":"2015-01-27T00:00:00+01:00","amountToVote":"10000.00","amountVoted":"7500.00","comments":"dfghdgh","projectId":1,"id":"FundingSource-1","active":false,"createdById":null,"creationDate":null,"historicalValue":false}

and the backend answer with the following

Code:



{"success":true,"message":"ok","fundingSource":[{"id":18}]}

As you can see, the backend return the id of the newly created item.

Ok, now my problem:


I have the two following models:



Code:



Ext.define('RoadMapProject.model.FundingSource', {
extend: 'RoadMapProject.model.Base',

fields: [
{ name: 'typeEnumId', reference: 'FundingSourceTypeEnum', type: 'int'},
{ name: 'voteDate', type: 'date', dateFormat: 'c'},
{ name: 'amountToVote', type: 'string' },
{ name: 'amountVoted', type: 'string' },
{ name: 'comments', type: 'string' },
{ name: 'createdById', reference: 'User', type: 'int'},
{ name: 'creationDate', type: 'date', dateFormat: 'c'},
{ name: 'historicalValue', type: 'boolean' },
{ name: 'projectId', type: 'int' }
],

proxy: {
reader: {
type: 'json',
rootProperty: 'fundingSource'
}
}


});

and


Code:



Ext.define('RoadMapProject.model.FundingPlanification', {
extend: 'RoadMapProject.model.Base',
fields: [
{ name: 'amountToVote', type: 'string' },
{ name: 'amountVoted', type: 'string' },
{ name: 'year', type: 'int' },
{ name: 'fundingSourceId', reference: 'FundingSource', type: 'int'}
],
proxy: {
reader: {
type: 'json',
rootProperty: 'fundingPlanification'
}
}
});

In one of my controller, I do create a fundingSource and a fundingPlanification. This last fundingPlanification is associated to the fundingSource with the association described in the model.

Code:



var FundingSourceData = {
typeEnumId: viewModel.get('typeEnumId'),
voteDate: viewModel.get('voteDate'),
amountToVote: viewModel.get('amountToVote'),
amountVoted: viewModel.get('amountVoted'),
comments: viewModel.get('comments'),
projectId: project.id
};
var fundingSource = viewModel.getSession().createRecord("FundingSource", FundingSourceData);

var fundingPlanifications = fundingSource.fundingPlanifications();

var FundingPlanificationData = {
amountToVote: 2234,
amountVoted: 555,
year: "2015"
};
var fundingPlanification = viewModel.getSession().createRecord("FundingPlanification", FundingPlanificationData);

fundingPlanifications.add(fundingPlanification);

var batch = viewModel.getSession().getSaveBatch();

batch.start();
batch.on("operationcomplete", function (batch, operation, eOpts)
{
console.log('return clicked');
});



When this code is executed, first the fundingSource is send to the backend (see the 2 json at the begining of this post then the fundingPlanification is also sent to the backend.


Code:



{"amountToVote":"2234","amountVoted":"555","year":2015,"id":"FundingPlanification-1","active":false,"fundingSourceId":null}

As you can see, the id (fundingSourceId)that realize the association between the fundingSource and the fundingPlanification is null. What I don’t understand is why? The backend gives back to the client the id of the newly creation fundingSource. fundingPlanification relation's id should have been updated before it has been post to the backend. I am surely missing something but I don’t not what.

Thank you very much for any help you could give me.



Model Association id is not sent to the server

Aucun commentaire:

Enregistrer un commentaire