Skip to content

Commit

Permalink
latest version of ember-data
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed May 3, 2012
1 parent 449093c commit da21e79
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 22 deletions.
41 changes: 29 additions & 12 deletions vendor/ember/development/ember-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,21 @@ DS.ManyArray = DS.RecordArray.extend({
if (actual) {
set(record, actual.name, remove ? null : parentRecord);
}
},

// Create a child record within the parentRecord
createRecord: function(hash, transaction) {
var parentRecord = get(this, 'parentRecord'),
store = get(parentRecord, 'store'),
type = get(this, 'type'),
record;

transaction = transaction || get(parentRecord, 'transaction');

record = store.createRecord.call(store, type, hash, transaction);
this.pushObject(record);

return record;
}
});

Expand Down Expand Up @@ -518,7 +533,7 @@ DS.Transaction = Ember.Object.extend({
this.removeCleanRecords();

if (adapter && adapter.commit) { adapter.commit(store, commitDetails); }
else { throw fmt("Adapter is either null or do not implement `commit` method", this); }
else { throw fmt("Adapter is either null or does not implement `commit` method", this); }
},

/**
Expand Down Expand Up @@ -1591,7 +1606,7 @@ var get = Ember.get, set = Ember.set, getPath = Ember.getPath, guidFor = Ember.g
string. You can determine a record's current state by getting its manager's
current state path:
record.getPath('manager.currentState.path');
record.getPath('stateManager.currentState.path');
//=> "created.uncommitted"
The `DS.Model` states are themselves stateless. What we mean is that,
Expand Down Expand Up @@ -2547,7 +2562,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
addHasManyToJSON: function(json, data, meta, options) {
var key = meta.key,
manyArray = get(this, key),
records = [],
records = [], i, l,
clientId, id;

if (meta.options.embedded) {
Expand All @@ -2558,7 +2573,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
} else {
var clientIds = get(manyArray, 'content');

for (var i=0, l=clientIds.length; i<l; i++) {
for (i=0, l=clientIds.length; i<l; i++) {
clientId = clientIds[i];
id = get(this, 'store').clientIdToId[clientId];

Expand All @@ -2568,7 +2583,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
}
}

key = options.key || get(this, 'namingConvention').keyToJSONKey(key);
key = meta.options.key || get(this, 'namingConvention').keyToJSONKey(key);
json[key] = records;
},

Expand All @@ -2585,12 +2600,12 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
addBelongsToToJSON: function(json, data, meta, options) {
var key = meta.key, value, id;

if (options.embedded) {
key = options.key || get(this, 'namingConvention').keyToJSONKey(key);
if (meta.options.embedded) {
key = meta.options.key || get(this, 'namingConvention').keyToJSONKey(key);
value = get(data.record, key);
json[key] = value ? value.toJSON(options) : null;
} else {
key = options.key || get(this, 'namingConvention').foreignKey(key);
key = meta.options.key || get(this, 'namingConvention').foreignKey(key);
id = data.get(key);
json[key] = none(id) ? null : id;
}
Expand Down Expand Up @@ -3475,7 +3490,7 @@ DS.RESTAdapter = DS.Adapter.extend({
hash.url = url;
hash.type = type;
hash.dataType = 'json';
hash.contentType = 'application/json';
hash.contentType = 'application/json; charset=utf-8';
hash.context = this;

if (hash.data && type !== 'GET') {
Expand All @@ -3496,11 +3511,9 @@ DS.RESTAdapter = DS.Adapter.extend({

if (!sideloadedType) {
mappings = get(this, 'mappings');

ember_assert("Your server returned a hash with the key " + prop + " but you have no mappings", !!mappings);

sideloadedType = get(get(this, 'mappings'), prop);

sideloadedType = get(mappings, prop);
ember_assert("Your server returned a hash with the key " + prop + " but you have no mapping for it", !!sideloadedType);
}

Expand All @@ -3519,6 +3532,10 @@ DS.RESTAdapter = DS.Adapter.extend({
buildURL: function(record, suffix) {
var url = [""];

ember_assert("Namespace URL (" + this.namespace + ") must not start with slash", !this.namespace || this.namespace.toString().charAt(0) !== "/");
ember_assert("Record URL (" + record + ") must not start with slash", !record || record.toString().charAt(0) !== "/");
ember_assert("URL suffix (" + suffix + ") must not start with slash", !suffix || suffix.toString().charAt(0) !== "/");

if (this.namespace !== undefined) {
url.push(this.namespace);
}
Expand Down
38 changes: 28 additions & 10 deletions vendor/ember/production/ember-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,21 @@ DS.ManyArray = DS.RecordArray.extend({
if (actual) {
set(record, actual.name, remove ? null : parentRecord);
}
},

// Create a child record within the parentRecord
createRecord: function(hash, transaction) {
var parentRecord = get(this, 'parentRecord'),
store = get(parentRecord, 'store'),
type = get(this, 'type'),
record;

transaction = transaction || get(parentRecord, 'transaction');

record = store.createRecord.call(store, type, hash, transaction);
this.pushObject(record);

return record;
}
});

Expand Down Expand Up @@ -517,7 +532,7 @@ DS.Transaction = Ember.Object.extend({
this.removeCleanRecords();

if (adapter && adapter.commit) { adapter.commit(store, commitDetails); }
else { throw fmt("Adapter is either null or do not implement `commit` method", this); }
else { throw fmt("Adapter is either null or does not implement `commit` method", this); }
},

/**
Expand Down Expand Up @@ -1590,7 +1605,7 @@ var get = Ember.get, set = Ember.set, getPath = Ember.getPath, guidFor = Ember.g
string. You can determine a record's current state by getting its manager's
current state path:
record.getPath('manager.currentState.path');
record.getPath('stateManager.currentState.path');
//=> "created.uncommitted"
The `DS.Model` states are themselves stateless. What we mean is that,
Expand Down Expand Up @@ -2546,7 +2561,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
addHasManyToJSON: function(json, data, meta, options) {
var key = meta.key,
manyArray = get(this, key),
records = [],
records = [], i, l,
clientId, id;

if (meta.options.embedded) {
Expand All @@ -2557,7 +2572,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
} else {
var clientIds = get(manyArray, 'content');

for (var i=0, l=clientIds.length; i<l; i++) {
for (i=0, l=clientIds.length; i<l; i++) {
clientId = clientIds[i];
id = get(this, 'store').clientIdToId[clientId];

Expand All @@ -2567,7 +2582,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
}
}

key = options.key || get(this, 'namingConvention').keyToJSONKey(key);
key = meta.options.key || get(this, 'namingConvention').keyToJSONKey(key);
json[key] = records;
},

Expand All @@ -2584,12 +2599,12 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
addBelongsToToJSON: function(json, data, meta, options) {
var key = meta.key, value, id;

if (options.embedded) {
key = options.key || get(this, 'namingConvention').keyToJSONKey(key);
if (meta.options.embedded) {
key = meta.options.key || get(this, 'namingConvention').keyToJSONKey(key);
value = get(data.record, key);
json[key] = value ? value.toJSON(options) : null;
} else {
key = options.key || get(this, 'namingConvention').foreignKey(key);
key = meta.options.key || get(this, 'namingConvention').foreignKey(key);
id = data.get(key);
json[key] = none(id) ? null : id;
}
Expand Down Expand Up @@ -3472,7 +3487,7 @@ DS.RESTAdapter = DS.Adapter.extend({
hash.url = url;
hash.type = type;
hash.dataType = 'json';
hash.contentType = 'application/json';
hash.contentType = 'application/json; charset=utf-8';
hash.context = this;

if (hash.data && type !== 'GET') {
Expand All @@ -3495,7 +3510,7 @@ DS.RESTAdapter = DS.Adapter.extend({
mappings = get(this, 'mappings');


sideloadedType = get(get(this, 'mappings'), prop);
sideloadedType = get(mappings, prop);

}

Expand All @@ -3514,6 +3529,9 @@ DS.RESTAdapter = DS.Adapter.extend({
buildURL: function(record, suffix) {
var url = [""];




if (this.namespace !== undefined) {
url.push(this.namespace);
}
Expand Down

0 comments on commit da21e79

Please sign in to comment.