From e35919c5304d21e543672ab4f1e8aac169f1cf98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 15 Nov 2011 16:19:16 +0400 Subject: [PATCH] Determining type for additional association attributes from associated class --- src/sproutcore-resource.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sproutcore-resource.js b/src/sproutcore-resource.js index c9c4ec2..a62be83 100644 --- a/src/sproutcore-resource.js +++ b/src/sproutcore-resource.js @@ -299,11 +299,12 @@ create: function(name, schema) { var definition = schema[name]; var instance = this._super.apply(this, arguments); + var theType = definition.type.schema.hasOwnProperty('id') ? definition.type.schema['id'].get('theType') : Number; instance.set('path', definition.path || name); var id_name = name + '_id'; if (!schema[id_name]) { - schema[id_name] = {type: Number, association: instance }; + schema[id_name] = {type: theType, association: instance }; schema[id_name] = SC.Resource.HasOneNestedIdSchemaItem.create(id_name, schema); } @@ -312,7 +313,6 @@ }); SC.Resource.HasOneNestedIdSchemaItem = SC.Resource.AbstractSchemaItem.extend({ fetchable: true, - theType: Number, getValue: function(instance) { return instance.getPath(this.get('path')); }, @@ -324,6 +324,7 @@ create: function(name, schema) { var definition = schema[name]; var instance = this._super.apply(this, arguments); + instance.set('theType', definition.type); instance.set('association', definition.association); instance.set('path', definition.association.get('path') + '.id'); return instance; @@ -353,10 +354,11 @@ var definition = schema[name]; var instance = this._super.apply(this, arguments); var path = definition.path || name + '_id'; + var theType = definition.type.schema.hasOwnProperty('id') ? definition.type.schema['id'].get('theType') : Number; instance.set('path', path); if (!schema[path]) { - schema[path] = Number; + schema[path] = theType; schema[path] = SC.Resource.SchemaItem.create(path, schema); }