Skip to content

Commit

Permalink
Makes model/record terminology consistent.
Browse files Browse the repository at this point in the history
Previously, there was some confusion internally
about what was a record and what was a model. This
commit makes the terminology consistent. A model
is a schema definition that creates a subclass of
DS.Model. Instances of those subclasses are called
records. A record corresponds to a single entry
in the persistence layer, as loaded by the
adapter.

To support this change, DS.ModelArray and its
subclasses are now named DS.RecordArray. Since
you should not be using these class names directly
(but rather have them returned by store methods
such as find() and filter()), this should not be
a breaking API change and thus we have not updated
the API revision number.
  • Loading branch information
tomhuda committed Apr 17, 2012
1 parent 575251a commit 9745f06
Show file tree
Hide file tree
Showing 24 changed files with 460 additions and 457 deletions.
58 changes: 29 additions & 29 deletions packages/ember-data/lib/adapters/rest_adapter.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,112 +5,112 @@ require('ember-data/system/adapters');
var get = Ember.get, set = Ember.set, getPath = Ember.getPath; var get = Ember.get, set = Ember.set, getPath = Ember.getPath;


DS.RESTAdapter = DS.Adapter.extend({ DS.RESTAdapter = DS.Adapter.extend({
createRecord: function(store, type, model) { createRecord: function(store, type, record) {
var root = this.rootForType(type); var root = this.rootForType(type);


var data = {}; var data = {};
data[root] = model.toJSON(); data[root] = record.toJSON();


this.ajax(this.buildURL(root), "POST", { this.ajax(this.buildURL(root), "POST", {
data: data, data: data,
success: function(json) { success: function(json) {
this.sideload(store, type, json, root); this.sideload(store, type, json, root);
store.didCreateRecord(model, json[root]); store.didCreateRecord(record, json[root]);
} }
}); });
}, },


createRecords: function(store, type, models) { createRecords: function(store, type, records) {
if (get(this, 'bulkCommit') === false) { if (get(this, 'bulkCommit') === false) {
return this._super(store, type, models); return this._super(store, type, records);
} }


var root = this.rootForType(type), var root = this.rootForType(type),
plural = this.pluralize(root); plural = this.pluralize(root);


var data = {}; var data = {};
data[plural] = models.map(function(model) { data[plural] = records.map(function(record) {
return model.toJSON(); return record.toJSON();
}); });


this.ajax(this.buildURL(root), "POST", { this.ajax(this.buildURL(root), "POST", {
data: data, data: data,


success: function(json) { success: function(json) {
this.sideload(store, type, json, plural); this.sideload(store, type, json, plural);
store.didCreateRecords(type, models, json[plural]); store.didCreateRecords(type, records, json[plural]);
} }
}); });
}, },


updateRecord: function(store, type, model) { updateRecord: function(store, type, record) {
var id = get(model, 'id'); var id = get(record, 'id');
var root = this.rootForType(type); var root = this.rootForType(type);


var data = {}; var data = {};
data[root] = model.toJSON(); data[root] = record.toJSON();


this.ajax(this.buildURL(root, id), "PUT", { this.ajax(this.buildURL(root, id), "PUT", {
data: data, data: data,
success: function(json) { success: function(json) {
this.sideload(store, type, json, root); this.sideload(store, type, json, root);
store.didUpdateRecord(model, json && json[root]); store.didUpdateRecord(record, json && json[root]);
} }
}); });
}, },


updateRecords: function(store, type, models) { updateRecords: function(store, type, records) {
if (get(this, 'bulkCommit') === false) { if (get(this, 'bulkCommit') === false) {
return this._super(store, type, models); return this._super(store, type, records);
} }


var root = this.rootForType(type), var root = this.rootForType(type),
plural = this.pluralize(root); plural = this.pluralize(root);


var data = {}; var data = {};
data[plural] = models.map(function(model) { data[plural] = records.map(function(record) {
return model.toJSON(); return record.toJSON();
}); });


this.ajax(this.buildURL(root, "bulk"), "PUT", { this.ajax(this.buildURL(root, "bulk"), "PUT", {
data: data, data: data,
success: function(json) { success: function(json) {
this.sideload(store, type, json, plural); this.sideload(store, type, json, plural);
store.didUpdateRecords(models, json[plural]); store.didUpdateRecords(records, json[plural]);
} }
}); });
}, },


deleteRecord: function(store, type, model) { deleteRecord: function(store, type, record) {
var id = get(model, 'id'); var id = get(record, 'id');
var root = this.rootForType(type); var root = this.rootForType(type);


this.ajax(this.buildURL(root, id), "DELETE", { this.ajax(this.buildURL(root, id), "DELETE", {
success: function(json) { success: function(json) {
if (json) { this.sideload(store, type, json); } if (json) { this.sideload(store, type, json); }
store.didDeleteRecord(model); store.didDeleteRecord(record);
} }
}); });
}, },


deleteRecords: function(store, type, models) { deleteRecords: function(store, type, records) {
if (get(this, 'bulkCommit') === false) { if (get(this, 'bulkCommit') === false) {
return this._super(store, type, models); return this._super(store, type, records);
} }


var root = this.rootForType(type), var root = this.rootForType(type),
plural = this.pluralize(root); plural = this.pluralize(root);


var data = {}; var data = {};
data[plural] = models.map(function(model) { data[plural] = records.map(function(record) {
return get(model, 'id'); return get(record, 'id');
}); });


this.ajax(this.buildURL(root, 'bulk'), "DELETE", { this.ajax(this.buildURL(root, 'bulk'), "DELETE", {
data: data, data: data,
success: function(json) { success: function(json) {
if (json) { this.sideload(store, type, json); } if (json) { this.sideload(store, type, json); }
store.didDeleteRecords(models); store.didDeleteRecords(records);
} }
}); });
}, },
Expand Down Expand Up @@ -149,13 +149,13 @@ DS.RESTAdapter = DS.Adapter.extend({
}); });
}, },


findQuery: function(store, type, query, modelArray) { findQuery: function(store, type, query, recordArray) {
var root = this.rootForType(type), plural = this.pluralize(root); var root = this.rootForType(type), plural = this.pluralize(root);


this.ajax(this.buildURL(root), "GET", { this.ajax(this.buildURL(root), "GET", {
data: query, data: query,
success: function(json) { success: function(json) {
modelArray.load(json[plural]); recordArray.load(json[plural]);
this.sideload(store, type, json, plural); this.sideload(store, type, json, plural);
} }
}); });
Expand Down Expand Up @@ -225,14 +225,14 @@ DS.RESTAdapter = DS.Adapter.extend({
} }
}, },


buildURL: function(model, suffix) { buildURL: function(record, suffix) {
var url = [""]; var url = [""];


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


url.push(this.pluralize(model)); url.push(this.pluralize(record));
if (suffix !== undefined) { if (suffix !== undefined) {
url.push(suffix); url.push(suffix);
} }
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-data/lib/main.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


require("ember-data/core"); require("ember-data/core");
require("ember-data/system/store"); require("ember-data/system/store");
require("ember-data/system/model_array"); require("ember-data/system/record_array");
require("ember-data/system/model"); require("ember-data/system/model");
require("ember-data/system/associations"); require("ember-data/system/associations");
require("ember-data/system/adapters"); require("ember-data/system/adapters");
Expand Down
18 changes: 9 additions & 9 deletions packages/ember-data/lib/system/adapters.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ DS.Adapter = Ember.Object.extend({
}, this); }, this);
}, },


createRecords: function(store, type, models) { createRecords: function(store, type, records) {
models.forEach(function(model) { records.forEach(function(record) {
this.createRecord(store, type, model); this.createRecord(store, type, record);
}, this); }, this);
}, },


updateRecords: function(store, type, models) { updateRecords: function(store, type, records) {
models.forEach(function(model) { records.forEach(function(record) {
this.updateRecord(store, type, model); this.updateRecord(store, type, record);
}, this); }, this);
}, },


deleteRecords: function(store, type, models) { deleteRecords: function(store, type, records) {
models.forEach(function(model) { records.forEach(function(record) {
this.deleteRecord(store, type, model); this.deleteRecord(store, type, record);
}, this); }, this);
}, },


Expand Down
8 changes: 4 additions & 4 deletions packages/ember-data/lib/system/model/model.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {


init: function() { init: function() {
var stateManager = DS.StateManager.create({ var stateManager = DS.StateManager.create({
model: this record: this
}); });


set(this, 'pendingQueue', {}); set(this, 'pendingQueue', {});
Expand Down Expand Up @@ -246,15 +246,15 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
var data = get(this, 'data'); var data = get(this, 'data');


if (data && key in data) { if (data && key in data) {
ember_assert("You attempted to access the " + key + " property on a model without defining an attribute.", false); ember_assert("You attempted to access the " + key + " property on a record without defining an attribute.", false);
} }
}, },


setUnknownProperty: function(key, value) { setUnknownProperty: function(key, value) {
var data = get(this, 'data'); var data = get(this, 'data');


if (data && key in data) { if (data && key in data) {
ember_assert("You attempted to set the " + key + " property on a model without defining an attribute.", false); ember_assert("You attempted to set the " + key + " property on a record without defining an attribute.", false);
} else { } else {
return this._super(key, value); return this._super(key, value);
} }
Expand All @@ -273,7 +273,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {


/** @private */ /** @private */
hashWasUpdated: function() { hashWasUpdated: function() {
// At the end of the run loop, notify model arrays that // At the end of the run loop, notify record arrays that
// this record has changed so they can re-evaluate its contents // this record has changed so they can re-evaluate its contents
// to determine membership. // to determine membership.
Ember.run.once(this, this.notifyHashWasUpdated); Ember.run.once(this, this.notifyHashWasUpdated);
Expand Down
Loading

0 comments on commit 9745f06

Please sign in to comment.