Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/sproutcore-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -312,7 +313,6 @@
});
SC.Resource.HasOneNestedIdSchemaItem = SC.Resource.AbstractSchemaItem.extend({
fetchable: true,
theType: Number,
getValue: function(instance) {
return instance.getPath(this.get('path'));
},
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down