Titanium JIRA Archive
Alloy (ALOY)

[ALOY-730] Fetching different models with a specific idAttribute inserts instead of replaces the "old" object in the fetch success response object.

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionNeeds more info
Resolution Date2013-07-09T17:01:51.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsandroid,, fetch, idAttribute, model, sqlrest
ReporterDaniel Sefton
AssigneeTony Lukasavage
Created2013-05-15T15:35:24.000+0000
Updated2014-06-22T13:23:20.000+0000

Description

*Problem* A model is created. The id of the model is set to a specific id. A fetch is made. When repeating this for another model with a different id results in a succes response object with 2 objects. There should be only one object because the fetch is for 1 specific object determined by the id. I've tried to create a collection and use the reset() function in all possible ways. Same situation/error. The created model doesn't have a reset method. We prefer lazyloading of the object. Therefore we pass the objectId in the args.objectId. When creating this controller the code is executed and extra data is received with a get from the server. *Source*
var args = arguments[0] || {};
Ti.API.info('args.objectId');
Ti.API.info(args.objectId);

$.plaatsing.open();

var plaatsing = Alloy.createModel('plaatsing');

plaatsing.id = args.objectId;

plaatsing.fetch({
	
	success : function(model) {
				
		alert('succes: ' + JSON.stringify(model));
			
			var plaatsing = model.toJSON();
			
			var p = plaatsing[0];						
	
			$.view1Block1Header.setText(p.plaatsing);
	},
	error : function(model) {
		alert(' error ' + model);
	}
});
function(model) here the model object is growinng in size by each new object instead of just containing the object where the id is set.

Comments

  1. Tony Lukasavage 2013-07-08

    I need more details on what is going on here. To be clear, the issue is that the fetch() on the model is retrieving the whole collection dataset, not just the model, right? What sync adapter are you using? Details on the model itself would be useful.
  2. Daniel Sefton 2013-07-09

    Hi Edwin, Please can you provide the extra info that Tony asked for? Thanks!

JSON Source