Hi all!

I’m trying to update an entity and I don’t know if I using the correct approach.

I’m using the mysql backend and I’ve receiving this error every time I call Entity’s constructor:

Error: immutable field: id
at Object.set (/Users/leandro/w/persistencejs/lib/persistence.js:67:51)
at Observable.Entity (/Users/leandro/w/persistencejs/lib/persistence.js:493:25)
at /Users/leandro/w/proj/entity.js:60:16

Am I doing something wrong?

Best regards.
Leandro.

================================

this.Entity = persistence.define(‘Entity’, tableInfo);

update: function(id, entity) {
var that = this;
var session = persistenceStore.getSession();

	session.transaction(function(tx) 
	{
		session.add(new that.Entity(session, entity));	
		
		session.flush(tx, function()
		{
			session.close();
		});
	});
}
Submitted by leandro batista on 31 December 2010 at 04:48

On 31 December 2010 at 13:29 Zef Hemel commented:

Hi Leandro, what’s in the entity variable there? If it’s something that has an id property, that may be causing the problem.


On 4 January 2011 at 18:09 leandro batista commented:

Hi Zef,

The entity variable holds a value that was generated by bodyDecoder, a middleware connect’s function. (http://senchalabs.github.com/connect/bodyDecoder.html)

Here the snippet:

exports.update = function(req, res, next) {
var id = req.params.id;
// req.body contais a json and what generated by bodyDecoder()
// it looks like a simple json object.

var new_entity = req.body;

Entity.Collection.update(id, new_entity);

};

Thank you.
[ ]s
leandro.


On 4 January 2011 at 20:01 Zef Hemel commented:

The problems seems to be that it tries to set the .id field from the req.body, which is immutable. If you make sure that req.body no longer contains the id field it should work. For instance using:

delete req.body.id;

Log in to post comments