Permalink
Browse files

Makes model/record terminology consistent.

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...
1 parent 575251a commit 9745f0658db47c3ada73cf163c9bd5c2c40c33fb tomhuda committed Apr 17, 2012
Showing with 460 additions and 457 deletions.
  1. +29 −29 packages/ember-data/lib/adapters/rest_adapter.js
  2. +1 −1 packages/ember-data/lib/main.js
  3. +9 −9 packages/ember-data/lib/system/adapters.js
  4. +4 −4 packages/ember-data/lib/system/model/model.js
  5. +51 −51 packages/ember-data/lib/system/model/states.js
  6. +0 −4 packages/ember-data/lib/system/model_array.js
  7. +0 −66 packages/ember-data/lib/system/model_array/model_array.js
  8. +4 −0 packages/ember-data/lib/system/record_array.js
  9. +2 −2 ...m/{model_array/adapter_populated_model_array.js → record_array/adapter_populated_record_array.js}
  10. +3 −3 ...ber-data/lib/system/{model_array/filtered_model_array.js → record_array/filtered_record_array.js}
  11. +3 −3 packages/ember-data/lib/system/{model_array → record_array}/many_array.js
  12. 0 packages/ember-data/lib/system/{model_array → record_array}/many_array_states.js
  13. +66 −0 packages/ember-data/lib/system/record_array/record_array.js
  14. +106 −103 packages/ember-data/lib/system/store.js
  15. +10 −10 packages/ember-data/lib/system/transaction.js
  16. +1 −1 packages/ember-data/package.json
  17. +8 −8 packages/ember-data/tests/integration/associations_test.js
  18. +40 −40 packages/ember-data/tests/integration/store_adapter_test.js
  19. +3 −3 packages/ember-data/tests/unit/associations_test.js
  20. +3 −3 packages/ember-data/tests/unit/fixture_adapter_test.js
  21. +61 −61 packages/ember-data/tests/unit/model_array_test.js
  22. +10 −10 packages/ember-data/tests/unit/model_test.js
  23. +28 −28 packages/ember-data/tests/unit/store_test.js
  24. +18 −18 packages/ember-data/tests/unit/transaction_test.js
View
58 packages/ember-data/lib/adapters/rest_adapter.js
@@ -5,112 +5,112 @@ require('ember-data/system/adapters');
var get = Ember.get, set = Ember.set, getPath = Ember.getPath;
DS.RESTAdapter = DS.Adapter.extend({
- createRecord: function(store, type, model) {
+ createRecord: function(store, type, record) {
var root = this.rootForType(type);
var data = {};
- data[root] = model.toJSON();
+ data[root] = record.toJSON();
this.ajax(this.buildURL(root), "POST", {
data: data,
success: function(json) {
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) {
- return this._super(store, type, models);
+ return this._super(store, type, records);
}
var root = this.rootForType(type),
plural = this.pluralize(root);
var data = {};
- data[plural] = models.map(function(model) {
- return model.toJSON();
+ data[plural] = records.map(function(record) {
+ return record.toJSON();
});
this.ajax(this.buildURL(root), "POST", {
data: data,
success: function(json) {
this.sideload(store, type, json, plural);
- store.didCreateRecords(type, models, json[plural]);
+ store.didCreateRecords(type, records, json[plural]);
}
});
},
- updateRecord: function(store, type, model) {
- var id = get(model, 'id');
+ updateRecord: function(store, type, record) {
+ var id = get(record, 'id');
var root = this.rootForType(type);
var data = {};
- data[root] = model.toJSON();
+ data[root] = record.toJSON();
this.ajax(this.buildURL(root, id), "PUT", {
data: data,
success: function(json) {
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) {
- return this._super(store, type, models);
+ return this._super(store, type, records);
}
var root = this.rootForType(type),
plural = this.pluralize(root);
var data = {};
- data[plural] = models.map(function(model) {
- return model.toJSON();
+ data[plural] = records.map(function(record) {
+ return record.toJSON();
});
this.ajax(this.buildURL(root, "bulk"), "PUT", {
data: data,
success: function(json) {
this.sideload(store, type, json, plural);
- store.didUpdateRecords(models, json[plural]);
+ store.didUpdateRecords(records, json[plural]);
}
});
},
- deleteRecord: function(store, type, model) {
- var id = get(model, 'id');
+ deleteRecord: function(store, type, record) {
+ var id = get(record, 'id');
var root = this.rootForType(type);
this.ajax(this.buildURL(root, id), "DELETE", {
success: function(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) {
- return this._super(store, type, models);
+ return this._super(store, type, records);
}
var root = this.rootForType(type),
plural = this.pluralize(root);
var data = {};
- data[plural] = models.map(function(model) {
- return get(model, 'id');
+ data[plural] = records.map(function(record) {
+ return get(record, 'id');
});
this.ajax(this.buildURL(root, 'bulk'), "DELETE", {
data: data,
success: function(json) {
if (json) { this.sideload(store, type, json); }
- store.didDeleteRecords(models);
+ store.didDeleteRecords(records);
}
});
},
@@ -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);
this.ajax(this.buildURL(root), "GET", {
data: query,
success: function(json) {
- modelArray.load(json[plural]);
+ recordArray.load(json[plural]);
this.sideload(store, type, json, plural);
}
});
@@ -225,14 +225,14 @@ DS.RESTAdapter = DS.Adapter.extend({
}
},
- buildURL: function(model, suffix) {
+ buildURL: function(record, suffix) {
var url = [""];
if (this.namespace !== undefined) {
url.push(this.namespace);
}
- url.push(this.pluralize(model));
+ url.push(this.pluralize(record));
if (suffix !== undefined) {
url.push(suffix);
}
View
2 packages/ember-data/lib/main.js
@@ -20,7 +20,7 @@
require("ember-data/core");
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/associations");
require("ember-data/system/adapters");
View
18 packages/ember-data/lib/system/adapters.js
@@ -13,21 +13,21 @@ DS.Adapter = Ember.Object.extend({
}, this);
},
- createRecords: function(store, type, models) {
- models.forEach(function(model) {
- this.createRecord(store, type, model);
+ createRecords: function(store, type, records) {
+ records.forEach(function(record) {
+ this.createRecord(store, type, record);
}, this);
},
- updateRecords: function(store, type, models) {
- models.forEach(function(model) {
- this.updateRecord(store, type, model);
+ updateRecords: function(store, type, records) {
+ records.forEach(function(record) {
+ this.updateRecord(store, type, record);
}, this);
},
- deleteRecords: function(store, type, models) {
- models.forEach(function(model) {
- this.deleteRecord(store, type, model);
+ deleteRecords: function(store, type, records) {
+ records.forEach(function(record) {
+ this.deleteRecord(store, type, record);
}, this);
},
View
8 packages/ember-data/lib/system/model/model.js
@@ -198,7 +198,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
init: function() {
var stateManager = DS.StateManager.create({
- model: this
+ record: this
});
set(this, 'pendingQueue', {});
@@ -246,15 +246,15 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
var data = get(this, '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) {
var data = get(this, '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 {
return this._super(key, value);
}
@@ -273,7 +273,7 @@ DS.Model = Ember.Object.extend(Ember.Evented, {
/** @private */
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
// to determine membership.
Ember.run.once(this, this.notifyHashWasUpdated);
View
102 packages/ember-data/lib/system/model/states.js
@@ -43,27 +43,27 @@ DS.State = Ember.State.extend({
var setProperty = function(manager, context) {
var key = context.key, value = context.value;
- var model = get(manager, 'model'),
- data = get(model, 'data');
+ var record = get(manager, 'record'),
+ data = get(record, 'data');
set(data, key, value);
};
var setAssociation = function(manager, context) {
var key = context.key, value = context.value;
- var model = get(manager, 'model'),
- data = get(model, 'data');
+ var record = get(manager, 'record'),
+ data = get(record, 'data');
data.setAssociation(key, value);
};
var didChangeData = function(manager) {
- var model = get(manager, 'model'),
- data = get(model, 'data');
+ var record = get(manager, 'record'),
+ data = get(record, 'data');
data._savedData = null;
- model.notifyPropertyChange('data');
+ record.notifyPropertyChange('data');
};
// The waitingOn event shares common functionality
@@ -73,8 +73,8 @@ var didChangeData = function(manager) {
// behavior, and then implement the behavior specific
// to the state.
var waitingOn = function(manager, object) {
- var model = get(manager, 'model'),
- pendingQueue = get(model, 'pendingQueue'),
+ var record = get(manager, 'record'),
+ pendingQueue = get(record, 'pendingQueue'),
objectGuid = guidFor(object);
var observer = function() {
@@ -134,11 +134,11 @@ var Uncommitted = Ember.Mixin.create({
deleteRecord: function(manager) {
this._super(manager);
- var model = get(manager, 'model'),
+ var record = get(manager, 'record'),
dirtyType = get(this, 'dirtyType');
- model.withTransaction(function(t) {
- t.modelBecameClean(dirtyType, model);
+ record.withTransaction(function(t) {
+ t.recordBecameClean(dirtyType, record);
});
}
});
@@ -158,10 +158,10 @@ var UpdatedUncommitted = Ember.Mixin.create({
deleteRecord: function(manager) {
this._super(manager);
- var model = get(manager, 'model');
+ var record = get(manager, 'record');
- model.withTransaction(function(t) {
- t.modelBecameClean('created', model);
+ record.withTransaction(function(t) {
+ t.recordBecameClean('created', record);
});
manager.goToState('deleted');
@@ -189,16 +189,16 @@ var DirtyState = DS.State.extend({
// TRANSITIONS
enter: function(manager) {
var dirtyType = get(this, 'dirtyType'),
- model = get(manager, 'model');
+ record = get(manager, 'record');
- model.withTransaction(function (t) {
- t.modelBecameDirty(dirtyType, model);
+ record.withTransaction(function (t) {
+ t.recordBecameDirty(dirtyType, record);
});
},
exit: function(manager) {
- var model = get(manager, 'model');
- manager.send('invokeLifecycleCallbacks', model);
+ var record = get(manager, 'record');
+ manager.send('invokeLifecycleCallbacks', record);
},
// EVENTS
@@ -224,10 +224,10 @@ var DirtyState = DS.State.extend({
// TRANSITIONS
enter: function(manager) {
var dirtyType = get(this, 'dirtyType'),
- model = get(manager, 'model');
+ record = get(manager, 'record');
- model.withTransaction(function (t) {
- t.modelBecameClean(dirtyType, model);
+ record.withTransaction(function (t) {
+ t.recordBecameClean(dirtyType, record);
});
},
@@ -237,9 +237,9 @@ var DirtyState = DS.State.extend({
},
becameInvalid: function(manager, errors) {
- var model = get(manager, 'model');
+ var record = get(manager, 'record');
- set(model, 'errors', errors);
+ set(record, 'errors', errors);
manager.goToState('invalid');
},
@@ -269,8 +269,8 @@ var DirtyState = DS.State.extend({
uncommitted: DS.State.extend({
// EVENTS
deleteRecord: function(manager) {
- var model = get(manager, 'model'),
- pendingQueue = get(model, 'pendingQueue'),
+ var record = get(manager, 'record'),
+ pendingQueue = get(record, 'pendingQueue'),
tuple;
// since we are leaving the pending state, remove any
@@ -288,8 +288,8 @@ var DirtyState = DS.State.extend({
},
doneWaitingOn: function(manager, object) {
- var model = get(manager, 'model'),
- pendingQueue = get(model, 'pendingQueue'),
+ var record = get(manager, 'record'),
+ pendingQueue = get(record, 'pendingQueue'),
objectGuid = guidFor(object);
delete pendingQueue[objectGuid];
@@ -315,8 +315,8 @@ var DirtyState = DS.State.extend({
// EVENTS
doneWaitingOn: function(manager, object) {
- var model = get(manager, 'model'),
- pendingQueue = get(model, 'pendingQueue'),
+ var record = get(manager, 'record'),
+ pendingQueue = get(record, 'pendingQueue'),
objectGuid = guidFor(object);
delete pendingQueue[objectGuid];
@@ -327,10 +327,10 @@ var DirtyState = DS.State.extend({
},
doneWaiting: function(manager) {
- var model = get(manager, 'model'),
- transaction = get(model, 'transaction');
+ var record = get(manager, 'record'),
+ transaction = get(record, 'transaction');
- // Now that the model is no longer pending, schedule
+ // Now that the record is no longer pending, schedule
// the transaction to commit.
Ember.run.once(transaction, transaction.commit);
},
@@ -359,8 +359,8 @@ var DirtyState = DS.State.extend({
setProperty: function(manager, context) {
setProperty(manager, context);
- var model = get(manager, 'model'),
- errors = get(model, 'errors'),
+ var record = get(manager, 'record'),
+ errors = get(record, 'errors'),
key = context.key;
delete errors[key];
@@ -387,17 +387,17 @@ var createdState = DirtyState.create({
isNew: true,
// EVENTS
- invokeLifecycleCallbacks: function(manager, model) {
- model.fire('didCreate');
+ invokeLifecycleCallbacks: function(manager, record) {
+ record.fire('didCreate');
}
});
var updatedState = DirtyState.create({
dirtyType: 'updated',
// EVENTS
- invokeLifecycleCallbacks: function(manager, model) {
- model.fire('didUpdate');
+ invokeLifecycleCallbacks: function(manager, record) {
+ record.fire('didUpdate');
}
});
@@ -452,8 +452,8 @@ var states = {
loading: DS.State.create({
// TRANSITIONS
exit: function(manager) {
- var model = get(manager, 'model');
- model.fire('didLoad');
+ var record = get(manager, 'record');
+ record.fire('didLoad');
},
// EVENTS
@@ -530,15 +530,15 @@ var states = {
start: DS.State.create({
// TRANSITIONS
enter: function(manager) {
- var model = get(manager, 'model');
- var store = get(model, 'store');
+ var record = get(manager, 'record');
+ var store = get(record, 'store');
if (store) {
- store.removeFromModelArrays(model);
+ store.removeFromRecordArrays(record);
}
- model.withTransaction(function(t) {
- t.modelBecameDirty('deleted', model);
+ record.withTransaction(function(t) {
+ t.recordBecameDirty('deleted', record);
});
},
@@ -558,10 +558,10 @@ var states = {
// TRANSITIONS
exit: function(stateManager) {
- var model = get(stateManager, 'model');
+ var record = get(stateManager, 'record');
- model.withTransaction(function(t) {
- t.modelBecameClean('deleted', model);
+ record.withTransaction(function(t) {
+ t.recordBecameClean('deleted', record);
});
},
@@ -590,7 +590,7 @@ var states = {
};
DS.StateManager = Ember.StateManager.extend({
- model: null,
+ record: null,
initialState: 'rootState',
states: states
});
View
4 packages/ember-data/lib/system/model_array.js
@@ -1,4 +0,0 @@
-require('ember-data/system/model_array/model_array');
-require('ember-data/system/model_array/filtered_model_array');
-require('ember-data/system/model_array/adapter_populated_model_array');
-require('ember-data/system/model_array/many_array');
View
66 packages/ember-data/lib/system/model_array/model_array.js
@@ -1,66 +0,0 @@
-var get = Ember.get, set = Ember.set;
-
-/**
- A model array is an array that contains records of a certain type. The model
- array materializes records as needed when they are retrieved for the first
- time. You should not create model arrays yourself. Instead, an instance of
- DS.ModelArray or its subclasses will be returned by your application's store
- in response to queries.
-*/
-
-DS.ModelArray = Ember.ArrayProxy.extend({
-
- /**
- The model type contained by this model array.
-
- @type DS.Model
- */
- type: null,
-
- // The array of client ids backing the model array. When a
- // record is requested from the model array, the record
- // for the client id at the same index is materialized, if
- // necessary, by the store.
- content: null,
-
- // The store that created this model array.
- store: null,
-
- init: function() {
- set(this, 'modelCache', Ember.A([]));
- this._super();
- },
-
- arrayDidChange: function(array, index, removed, added) {
- var modelCache = get(this, 'modelCache');
- modelCache.replace(index, 0, new Array(added));
-
- this._super(array, index, removed, added);
- },
-
- arrayWillChange: function(array, index, removed, added) {
- this._super(array, index, removed, added);
-
- var modelCache = get(this, 'modelCache');
- modelCache.replace(index, removed);
- },
-
- objectAtContent: function(index) {
- var modelCache = get(this, 'modelCache');
- var model = modelCache.objectAt(index);
-
- if (!model) {
- var store = get(this, 'store');
- var content = get(this, 'content');
-
- var contentObject = content.objectAt(index);
-
- if (contentObject !== undefined) {
- model = store.findByClientId(get(this, 'type'), contentObject);
- modelCache.replace(index, 1, [model]);
- }
- }
-
- return model;
- }
-});
View
4 packages/ember-data/lib/system/record_array.js
@@ -0,0 +1,4 @@
+require('ember-data/system/record_array/record_array');
+require('ember-data/system/record_array/filtered_record_array');
+require('ember-data/system/record_array/adapter_populated_record_array');
+require('ember-data/system/record_array/many_array');
View
4 ...el_array/adapter_populated_model_array.js → ...d_array/adapter_populated_record_array.js
@@ -1,8 +1,8 @@
-require("ember-data/system/model_array");
+require("ember-data/system/record_array");
var get = Ember.get, set = Ember.set;
-DS.AdapterPopulatedModelArray = DS.ModelArray.extend({
+DS.AdapterPopulatedRecordArray = DS.RecordArray.extend({
query: null,
isLoaded: false,
View
6 ...ystem/model_array/filtered_model_array.js → ...tem/record_array/filtered_record_array.js
@@ -1,8 +1,8 @@
-require("ember-data/system/model_array");
+require("ember-data/system/record_array");
var get = Ember.get;
-DS.FilteredModelArray = DS.ModelArray.extend({
+DS.FilteredRecordArray = DS.RecordArray.extend({
filterFunction: null,
replace: function() {
@@ -12,6 +12,6 @@ DS.FilteredModelArray = DS.ModelArray.extend({
updateFilter: Ember.observer(function() {
var store = get(this, 'store');
- store.updateModelArrayFilter(this, get(this, 'type'), get(this, 'filterFunction'));
+ store.updateRecordArrayFilter(this, get(this, 'type'), get(this, 'filterFunction'));
}, 'filterFunction')
});
View
6 ...data/lib/system/model_array/many_array.js → ...ata/lib/system/record_array/many_array.js
@@ -1,9 +1,9 @@
-require("ember-data/system/model_array/model_array");
-require("ember-data/system/model_array/many_array_states");
+require("ember-data/system/record_array/record_array");
+require("ember-data/system/record_array/many_array_states");
var get = Ember.get, set = Ember.set, getPath = Ember.getPath;
-DS.ManyArray = DS.ModelArray.extend({
+DS.ManyArray = DS.RecordArray.extend({
init: function() {
set(this, 'stateManager', DS.ManyArrayStateManager.create({ manyArray: this }));
View
0 ...b/system/model_array/many_array_states.js → .../system/record_array/many_array_states.js
File renamed without changes.
View
66 packages/ember-data/lib/system/record_array/record_array.js
@@ -0,0 +1,66 @@
+var get = Ember.get, set = Ember.set;
+
+/**
+ A record array is an array that contains records of a certain type. The record
+ array materializes records as needed when they are retrieved for the first
+ time. You should not create record arrays yourself. Instead, an instance of
+ DS.RecordArray or its subclasses will be returned by your application's store
+ in response to queries.
+*/
+
+DS.RecordArray = Ember.ArrayProxy.extend({
+
+ /**
+ The model type contained by this record array.
+
+ @type DS.Model
+ */
+ type: null,
+
+ // The array of client ids backing the record array. When a
+ // record is requested from the record array, the record
+ // for the client id at the same index is materialized, if
+ // necessary, by the store.
+ content: null,
+
+ // The store that created this record array.
+ store: null,
+
+ init: function() {
+ set(this, 'recordCache', Ember.A([]));
+ this._super();
+ },
+
+ arrayDidChange: function(array, index, removed, added) {
+ var recordCache = get(this, 'recordCache');
+ recordCache.replace(index, 0, new Array(added));
+
+ this._super(array, index, removed, added);
+ },
+
+ arrayWillChange: function(array, index, removed, added) {
+ this._super(array, index, removed, added);
+
+ var recordCache = get(this, 'recordCache');
+ recordCache.replace(index, removed);
+ },
+
+ objectAtContent: function(index) {
+ var recordCache = get(this, 'recordCache');
+ var record = recordCache.objectAt(index);
+
+ if (!record) {
+ var store = get(this, 'store');
+ var content = get(this, 'content');
+
+ var contentObject = content.objectAt(index);
+
+ if (contentObject !== undefined) {
+ record = store.findByClientId(get(this, 'type'), contentObject);
+ recordCache.replace(index, 1, [record]);
+ }
+ }
+
+ return record;
+ }
+});
View
209 packages/ember-data/lib/system/store.js
@@ -1,4 +1,6 @@
-require("ember-data/system/model_array");
+/*globals Ember*/
+
+require("ember-data/system/record_array");
require("ember-data/system/transaction");
var get = Ember.get, set = Ember.set, getPath = Ember.getPath, fmt = Ember.String.fmt;
@@ -28,7 +30,7 @@ var LOADING = 'loading';
// * +type+ means a subclass of DS.Model.
/**
- The store contains all of the hashes for data models loaded from the server.
+ The store contains all of the hashes for records loaded from the server.
It is also responsible for creating instances of DS.Model when you request one
of these data hashes, so that they can be bound to in your Handlebars templates.
@@ -37,9 +39,9 @@ var LOADING = 'loading';
MyApp.store = DS.Store.create();
You can retrieve DS.Model instances from the store in several ways. To retrieve
- a model for a specific id, use the `find()` method:
+ a record for a specific id, use the `find()` method:
- var model = MyApp.store.find(MyApp.Contact, 123);
+ var record = MyApp.store.find(MyApp.Contact, 123);
By default, the store will talk to your backend using a standard REST mechanism.
You can customize how the store talks to your backend by specifying a custom adapter:
@@ -77,7 +79,7 @@ DS.Store = Ember.Object.extend({
this.typeMaps = {};
this.recordCache = [];
this.clientIdToId = {};
- this.modelArraysByClientId = {};
+ this.recordArraysByClientId = {};
set(this, 'defaultTransaction', this.transaction());
@@ -97,7 +99,7 @@ DS.Store = Ember.Object.extend({
/**
@private
- This is used only by the model's DataProxy. Do not use this directly.
+ This is used only by the record's DataProxy. Do not use this directly.
*/
dataForRecord: function(record) {
var type = record.constructor,
@@ -136,9 +138,9 @@ DS.Store = Ember.Object.extend({
// data hashes and records.
clientIdCounter: 1,
- // ....................
- // . CREATE NEW MODEL .
- // ....................
+ // .....................
+ // . CREATE NEW RECORD .
+ // .....................
/**
Create a new record in the current store. The properties passed
@@ -190,14 +192,14 @@ DS.Store = Ember.Object.extend({
// Set the properties specified on the record.
record.setProperties(properties);
- this.updateModelArrays(type, clientId, get(record, 'data'));
+ this.updateRecordArrays(type, clientId, get(record, 'data'));
return record;
},
- // ................
- // . DELETE MODEL .
- // ................
+ // .................
+ // . DELETE RECORD .
+ // .................
/**
For symmetry, a record can be deleted via the store.
@@ -208,9 +210,9 @@ DS.Store = Ember.Object.extend({
record.send('deleteRecord');
},
- // ...............
- // . FIND MODELS .
- // ...............
+ // ................
+ // . FIND RECORDS .
+ // ................
/**
This is the main entry point into finding records. The first
@@ -230,7 +232,8 @@ DS.Store = Ember.Object.extend({
If the record with that `id` had not previously been loaded,
the store will return an empty record immediately and ask
- the adapter to find the data by calling its `find` method.
+ the adapter to find the data by calling the adapter's `find`
+ method.
The `find` method will always return the same object for a
given type and `id`. To check whether the adapter has populated
@@ -244,11 +247,11 @@ DS.Store = Ember.Object.extend({
store.find(App.Person);
App.Person.find();
- This will return a `ModelArray` representing all known records
+ This will return a `RecordArray` representing all known records
for the given type and kick off a request to the adapter's
`findAll` method to load any additional records for the type.
- The `ModelArray` returned by `find()` is live. If any more
+ The `RecordArray` returned by `find()` is live. If any more
records for the type are added at a later time through any
mechanism, it will automatically update to reflect the change.
@@ -260,12 +263,12 @@ DS.Store = Ember.Object.extend({
store.find(App.Person, { page: 1 });
App.Person.find({ page: 1 });
- This will return a `ModelArray` immediately, but it will always
- be an empty `ModelArray` at first. It will call the adapter's
- `findQuery` method, which will populate the `ModelArray` once
+ This will return a `RecordArray` immediately, but it will always
+ be an empty `RecordArray` at first. It will call the adapter's
+ `findQuery` method, which will populate the `RecordArray` once
the server has returned results.
- You can check whether a query results `ModelArray` has loaded
+ You can check whether a query results `RecordArray` has loaded
by checking its `isLoaded` property.
*/
find: function(type, id, query) {
@@ -291,39 +294,39 @@ DS.Store = Ember.Object.extend({
findByClientId: function(type, clientId, id) {
var recordCache = get(this, 'recordCache'),
dataCache = this.typeMapFor(type).cidToHash,
- model;
+ record;
// If there is already a clientId assigned for this
// type/id combination, try to find an existing
- // model for that id and return. Otherwise,
- // materialize a new model and set its data to the
+ // record for that id and return. Otherwise,
+ // materialize a new record and set its data to the
// value we already have.
if (clientId !== undefined) {
- model = recordCache[clientId];
+ record = recordCache[clientId];
- if (!model) {
- // create a new instance of the model in the
+ if (!record) {
+ // create a new instance of the model type in the
// 'isLoading' state
- model = this.materializeRecord(type, clientId);
+ record = this.materializeRecord(type, clientId);
if (typeof dataCache[clientId] === 'object') {
- model.send('didChangeData');
+ record.send('didChangeData');
}
}
} else {
clientId = this.pushHash(LOADING, id, type);
- // create a new instance of the model in the
+ // create a new instance of the model type in the
// 'isLoading' state
- model = this.materializeRecord(type, clientId);
+ record = this.materializeRecord(type, clientId);
// let the adapter set the data, possibly async
var adapter = get(this, '_adapter');
if (adapter && adapter.find) { adapter.find(this, type, id); }
else { throw fmt("Adapter is either null or does not implement `find` method", this); }
}
- return model;
+ return record;
},
/**
@@ -404,7 +407,7 @@ DS.Store = Ember.Object.extend({
},
findQuery: function(type, query) {
- var array = DS.AdapterPopulatedModelArray.create({ type: type, content: Ember.A([]), store: this });
+ var array = DS.AdapterPopulatedRecordArray.create({ type: type, content: Ember.A([]), store: this });
var adapter = get(this, '_adapter');
if (adapter && adapter.findQuery) { adapter.findQuery(this, type, query, array); }
else { throw fmt("Adapter is either null or does not implement `findQuery` method", this); }
@@ -418,8 +421,8 @@ DS.Store = Ember.Object.extend({
if (findAllCache) { return findAllCache; }
- var array = DS.ModelArray.create({ type: type, content: Ember.A([]), store: this });
- this.registerModelArray(array, type);
+ var array = DS.RecordArray.create({ type: type, content: Ember.A([]), store: this });
+ this.registerRecordArray(array, type);
var adapter = get(this, '_adapter');
if (adapter && adapter.findAll) { adapter.findAll(this, type); }
@@ -436,9 +439,9 @@ DS.Store = Ember.Object.extend({
filter = query;
}
- var array = DS.FilteredModelArray.create({ type: type, content: Ember.A([]), store: this, filterFunction: filter });
+ var array = DS.FilteredRecordArray.create({ type: type, content: Ember.A([]), store: this, filterFunction: filter });
- this.registerModelArray(array, type, filter);
+ this.registerRecordArray(array, type, filter);
return array;
},
@@ -448,7 +451,7 @@ DS.Store = Ember.Object.extend({
// ............
hashWasUpdated: function(type, clientId, record) {
- this.updateModelArrays(type, clientId, get(record, 'data'));
+ this.updateRecordArrays(type, clientId, get(record, 'data'));
},
// ..............
@@ -464,37 +467,37 @@ DS.Store = Ember.Object.extend({
didUpdateRecords: function(array, hashes) {
if (hashes) {
- array.forEach(function(model, idx) {
- this.didUpdateRecord(model, hashes[idx]);
+ array.forEach(function(record, idx) {
+ this.didUpdateRecord(record, hashes[idx]);
}, this);
} else {
- array.forEach(function(model) {
- this.didUpdateRecord(model);
+ array.forEach(function(record) {
+ this.didUpdateRecord(record);
}, this);
}
},
- didUpdateRecord: function(model, hash) {
+ didUpdateRecord: function(record, hash) {
if (hash) {
- var clientId = get(model, 'clientId'),
- dataCache = this.typeMapFor(model.constructor).cidToHash;
+ var clientId = get(record, 'clientId'),
+ dataCache = this.typeMapFor(record.constructor).cidToHash;
dataCache[clientId] = hash;
- model.send('didChangeData');
- model.hashWasUpdated();
+ record.send('didChangeData');
+ record.hashWasUpdated();
}
- model.send('didCommit');
+ record.send('didCommit');
},
didDeleteRecords: function(array) {
- array.forEach(function(model) {
- model.send('didCommit');
+ array.forEach(function(record) {
+ record.send('didCommit');
});
},
- didDeleteRecord: function(model) {
- model.send('didCommit');
+ didDeleteRecord: function(record) {
+ record.send('didCommit');
},
_didCreateRecord: function(record, hash, typeMap, clientId, primaryKey) {
@@ -529,15 +532,15 @@ DS.Store = Ember.Object.extend({
clientId;
for (var i=0, l=get(array, 'length'); i<l; i++) {
- var model = array[i], hash = hashes[i];
- clientId = get(model, 'clientId');
+ var record = array[i], hash = hashes[i];
+ clientId = get(record, 'clientId');
- this._didCreateRecord(model, hash, typeMap, clientId, primaryKey);
+ this._didCreateRecord(record, hash, typeMap, clientId, primaryKey);
}
},
- didCreateRecord: function(model, hash) {
- var type = model.constructor,
+ didCreateRecord: function(record, hash) {
+ var type = record.constructor,
typeMap = this.typeMapFor(type),
clientId, primaryKey;
@@ -550,42 +553,42 @@ DS.Store = Ember.Object.extend({
if (hash) {
ember_assert("The server must provide a primary key: " + primaryKey, get(hash, primaryKey));
} else {
- ember_assert("The server did not return data, and you did not create a primary key (" + primaryKey + ") on the client", get(get(model, 'data'), primaryKey));
+ ember_assert("The server did not return data, and you did not create a primary key (" + primaryKey + ") on the client", get(get(record, 'data'), primaryKey));
}
- clientId = get(model, 'clientId');
+ clientId = get(record, 'clientId');
- this._didCreateRecord(model, hash, typeMap, clientId, primaryKey);
+ this._didCreateRecord(record, hash, typeMap, clientId, primaryKey);
},
recordWasInvalid: function(record, errors) {
record.send('becameInvalid', errors);
},
- // ................
- // . MODEL ARRAYS .
- // ................
+ // .................
+ // . RECORD ARRAYS .
+ // .................
- registerModelArray: function(array, type, filter) {
- var modelArrays = this.typeMapFor(type).modelArrays;
+ registerRecordArray: function(array, type, filter) {
+ var recordArrays = this.typeMapFor(type).recordArrays;
- modelArrays.push(array);
+ recordArrays.push(array);
- this.updateModelArrayFilter(array, type, filter);
+ this.updateRecordArrayFilter(array, type, filter);
},
createManyArray: function(type, clientIds) {
var array = DS.ManyArray.create({ type: type, content: clientIds, store: this });
clientIds.forEach(function(clientId) {
- var modelArrays = this.modelArraysForClientId(clientId);
- modelArrays.add(array);
+ var recordArrays = this.recordArraysForClientId(clientId);
+ recordArrays.add(array);
}, this);
return array;
},
- updateModelArrayFilter: function(array, type, filter) {
+ updateRecordArrayFilter: function(array, type, filter) {
var typeMap = this.typeMapFor(type),
dataCache = typeMap.cidToHash,
clientIds = typeMap.clientIds,
@@ -605,22 +608,22 @@ DS.Store = Ember.Object.extend({
proxy = DATA_PROXY;
}
- this.updateModelArray(array, filter, type, clientId, proxy);
+ this.updateRecordArray(array, filter, type, clientId, proxy);
}
}
},
- updateModelArrays: function(type, clientId, dataProxy) {
- var modelArrays = this.typeMapFor(type).modelArrays,
- modelArrayType, filter;
+ updateRecordArrays: function(type, clientId, dataProxy) {
+ var recordArrays = this.typeMapFor(type).recordArrays,
+ filter;
- modelArrays.forEach(function(array) {
+ recordArrays.forEach(function(array) {
filter = get(array, 'filterFunction');
- this.updateModelArray(array, filter, type, clientId, dataProxy);
+ this.updateRecordArray(array, filter, type, clientId, dataProxy);
}, this);
},
- updateModelArray: function(array, filter, type, clientId, dataProxy) {
+ updateRecordArray: function(array, filter, type, clientId, dataProxy) {
var shouldBeInArray;
if (!filter) {
@@ -632,22 +635,22 @@ DS.Store = Ember.Object.extend({
var content = get(array, 'content');
var alreadyInArray = content.indexOf(clientId) !== -1;
- var modelArrays = this.modelArraysForClientId(clientId);
+ var recordArrays = this.recordArraysForClientId(clientId);
if (shouldBeInArray && !alreadyInArray) {
- modelArrays.add(array);
+ recordArrays.add(array);
content.pushObject(clientId);
} else if (!shouldBeInArray && alreadyInArray) {
- modelArrays.remove(array);
+ recordArrays.remove(array);
content.removeObject(clientId);
}
},
- removeFromModelArrays: function(model) {
- var clientId = get(model, 'clientId');
- var modelArrays = this.modelArraysForClientId(clientId);
+ removeFromRecordArrays: function(record) {
+ var clientId = get(record, 'clientId');
+ var recordArrays = this.recordArraysForClientId(clientId);
- modelArrays.forEach(function(array) {
+ recordArrays.forEach(function(array) {
var content = get(array, 'content');
content.removeObject(clientId);
});
@@ -657,12 +660,12 @@ DS.Store = Ember.Object.extend({
// . INDEXING .
// ............
- modelArraysForClientId: function(clientId) {
- var modelArrays = get(this, 'modelArraysByClientId');
- var ret = modelArrays[clientId];
+ recordArraysForClientId: function(clientId) {
+ var recordArrays = get(this, 'recordArraysByClientId');
+ var ret = recordArrays[clientId];
if (!ret) {
- ret = modelArrays[clientId] = Ember.OrderedSet.create();
+ ret = recordArrays[clientId] = Ember.OrderedSet.create();
}
return ret;
@@ -682,7 +685,7 @@ DS.Store = Ember.Object.extend({
idToCid: {},
clientIds: [],
cidToHash: {},
- modelArrays: []
+ recordArrays: []
});
}
},
@@ -709,10 +712,10 @@ DS.Store = Ember.Object.extend({
/**
Load a new data hash into the store for a given id and type combination.
- If data for that model had been loaded previously, the new information
+ If data for that record had been loaded previously, the new information
overwrites the old.
- If the model you are loading data for has outstanding changes that have not
+ If the record you are loading data for has outstanding changes that have not
yet been saved, an exception will be thrown.
@param {DS.Model} type
@@ -723,7 +726,7 @@ DS.Store = Ember.Object.extend({
if (hash === undefined) {
hash = id;
var primaryKey = type.proto().primaryKey;
- ember_assert("A data hash was loaded for a model of type " + type.toString() + " but no primary key '" + primaryKey + "' was provided.", primaryKey in hash);
+ ember_assert("A data hash was loaded for a record of type " + type.toString() + " but no primary key '" + primaryKey + "' was provided.", primaryKey in hash);
id = hash[primaryKey];
}
@@ -744,7 +747,7 @@ DS.Store = Ember.Object.extend({
}
DATA_PROXY.savedData = hash;
- this.updateModelArrays(type, clientId, DATA_PROXY);
+ this.updateRecordArrays(type, clientId, DATA_PROXY);
return { id: id, clientId: clientId };
},
@@ -804,22 +807,22 @@ DS.Store = Ember.Object.extend({
return clientId;
},
- // .........................
- // . MODEL MATERIALIZATION .
- // .........................
+ // ..........................
+ // . RECORD MATERIALIZATION .
+ // ..........................
materializeRecord: function(type, clientId) {
- var model;
+ var record;
- get(this, 'recordCache')[clientId] = model = type._create({
+ get(this, 'recordCache')[clientId] = record = type._create({
store: this,
clientId: clientId
});
- get(this, 'defaultTransaction').adoptRecord(model);
+ get(this, 'defaultTransaction').adoptRecord(record);
- model.send('loadingData');
- return model;
+ record.send('loadingData');
+ return record;
},
destroy: function() {
View
20 packages/ember-data/lib/system/transaction.js
@@ -20,10 +20,10 @@ DS.Transaction = Ember.Object.extend({
// we could probably make this work if someone has a valid use case. Do you?
ember_assert("Once a record has changed, you cannot move it into a different transaction", !get(record, 'isDirty'));
- var modelTransaction = get(record, 'transaction'),
+ var recordTransaction = get(record, 'transaction'),
defaultTransaction = getPath(this, 'store.defaultTransaction');
- ember_assert("Models cannot belong to more than one transaction at a time.", modelTransaction === defaultTransaction);
+ ember_assert("Models cannot belong to more than one transaction at a time.", recordTransaction === defaultTransaction);
this.adoptRecord(record);
},
@@ -57,7 +57,7 @@ DS.Transaction = Ember.Object.extend({
set(record, 'transaction', this);
},
- modelBecameDirty: function(kind, record) {
+ recordBecameDirty: function(kind, record) {
this.removeFromBucket('clean', record);
this.addToBucket(kind, record);
},
@@ -86,7 +86,7 @@ DS.Transaction = Ember.Object.extend({
records.remove(record);
},
- modelBecameClean: function(kind, record) {
+ recordBecameClean: function(kind, record) {
this.removeFromBucket(kind, record);
var defaultTransaction = getPath(this, 'store.defaultTransaction');
@@ -99,16 +99,16 @@ DS.Transaction = Ember.Object.extend({
var iterate = function(kind, fn, binding) {
var dirty = get(buckets, kind);
- dirty.forEach(function(type, models) {
- if (models.isEmpty()) { return; }
+ dirty.forEach(function(type, records) {
+ if (records.isEmpty()) { return; }
var array = [];
- models.forEach(function(model) {
- model.send('willCommit');
+ records.forEach(function(record) {
+ record.send('willCommit');
- if (get(model, 'isPending') === false) {
- array.push(model);
+ if (get(record, 'isPending') === false) {
+ array.push(record);
}
});
View
2 packages/ember-data/package.json
@@ -1,7 +1,7 @@
{
"name": "ember-data",
"summary": "Short package description",
- "description": "Ember Data is a library for loading models from a persistence layer (such as a JSON API), updating those models, then saving the changes. It provides many of the facilities you'd find in server-side ORMs like ActiveRecord, but is designed specifically for the unique environment of JavaScript in the browser.",
+ "description": "Ember Data is a library for loading records from a persistence layer (such as a JSON API), updating those records, then saving the changes. It provides many of the facilities you'd find in server-side ORMs like ActiveRecord, but is designed specifically for the unique environment of JavaScript in the browser.",
"homepage": "https://github.com/emberjs/data",
"author": "Tom Dale, Yehuda Katz, and contributors",
"version": "0.5.0.pre",
View
16 packages/ember-data/tests/integration/associations_test.js
@@ -35,13 +35,13 @@ test("when adding a record to an association that belongs to another record that
parentRecord.get('comments').pushObject(childRecord);
var createCalled = 0;
- adapter.createRecord = function(store, type, model) {
+ adapter.createRecord = function(store, type, record) {
createCalled++;
if (createCalled === 1) {
- equal(model, parentRecord, "parent record is committed first");
- store.didCreateRecord(model, { id: 1 });
+ equal(record, parentRecord, "parent record is committed first");
+ store.didCreateRecord(record, { id: 1 });
} else if (createCalled === 2) {
- equal(model, childRecord, "child record is committed after its parent is committed");
+ equal(record, childRecord, "child record is committed after its parent is committed");
}
};
@@ -59,16 +59,16 @@ test("if a record is added to the store while a child is pending, auto-committin
parentRecord.get('comments').pushObject(childRecord);
var createCalled = 0;
- adapter.createRecord = function(store, type, model) {
+ adapter.createRecord = function(store, type, record) {
createCalled++;
if (createCalled === 1) {
- equal(model, parentRecord, "parent record is committed first");
+ equal(record, parentRecord, "parent record is committed first");
Comment.createRecord();
- store.didCreateRecord(model, { id: 1 });
+ store.didCreateRecord(record, { id: 1 });
} else if (createCalled === 2) {
- equal(model, childRecord, "child record is committed after its parent is committed");
+ equal(record, childRecord, "child record is committed after its parent is committed");
} else {
ok(false, "Third comment should not be saved");
}
View
80 packages/ember-data/tests/integration/store_adapter_test.js
@@ -8,7 +8,7 @@
by calling a method on the store.
These tests ensure that the proper methods get called, and, if applicable,
- the given model or model array changes state appropriately.
+ the given record orrecord arrayay changes state appropriately.
*/
var get = Ember.get, set = Ember.set, getPath = Ember.getPath;
@@ -44,7 +44,7 @@ test("when a single record is requested, the adapter's find method is called unl
store.find(Person, 1);
});
-test("when multiple models are requested, the adapter's findMany method is called", function() {
+test("when multiple records are requested, the adapter's findMany method is called", function() {
expect(1);
adapter.findMany = function(store, type, ids) {
@@ -55,7 +55,7 @@ test("when multiple models are requested, the adapter's findMany method is calle
store.findMany(Person, [1,2,3]);
});
-test("when multiple models are requested, the adapter's find method is called multiple times if findMany is not implemented", function() {
+test("when multiple records are requested, the adapter's find method is called multiple times if findMany is not implemented", function() {
expect(3);
var count = 0;
@@ -71,13 +71,13 @@ test("when multiple models are requested, the adapter's find method is called mu
test("when many records are requested with query parameters, the adapter's findQuery method is called", function() {
expect(6);
- adapter.findQuery = function(store, type, query, modelArray) {
+ adapter.findQuery = function(store, type, query, recordArray) {
equal(type, Person, "the find method is called with the correct type");
stop();
setTimeout(function() {
- modelArray.load([{ id: 1, name: "Peter Wagenet" }, { id: 2, name: "Brohuda Katz" }]);
+ recordArray.load([{ id: 1, name: "Peter Wagenet" }, { id: 2, name: "Brohuda Katz" }]);
start();
}, 100);
};
@@ -198,7 +198,7 @@ test("when a store is committed, the adapter's commit method is called with dele
tom.deleteRecord();
store.commit();
- equal(get(tom, 'isDeleted'), true, "model is marked as deleted");
+ equal(get(tom, 'isDeleted'), true, "record is marked as deleted");
});
test("by default, commit calls createRecords once per type", function() {
@@ -221,7 +221,7 @@ test("by default, commit calls createRecords once per type", function() {
});
store.commit();
- equal(callCount, 1, "calls observer on the model when it has been changed");
+ equal(callCount, 1, "calls observer on the record when it has been changed");
equal(tom, store.find(Person, 1), "Once an ID is in, find returns the same object");
equal(yehuda, store.find(Person, 2), "Once an ID is in, find returns the same object");
@@ -258,7 +258,7 @@ test("by default, commit calls updateRecords once per type", function() {
store.commit();
- equal(get(store.find(Person, 2), "name"), "Yehuda Katz", "model was updated");
+ equal(get(store.find(Person, 2), "name"), "Yehuda Katz", "record was updated");
// there is nothing to commit, so eachType won't do anything
store.commit();
@@ -290,8 +290,8 @@ test("updateRecords can return an array of Hashes to update the store with", fun
store.commit();
- equal(get(store.find(Person, 1), "name"), "Tom Dale", "model was updated");
- equal(get(store.find(Person, 2), "name"), "Yehuda Katz", "model was updated");
+ equal(get(store.find(Person, 1), "name"), "Tom Dale", "record was updated");
+ equal(get(store.find(Person, 2), "name"), "Yehuda Katz", "record was updated");
// there is nothing to commit, so eachType won't do anything
store.commit();
@@ -316,8 +316,8 @@ test("by default, commit calls deleteRecords once per type", function() {
yehuda.deleteRecord();
store.commit();
- ok(get(tom, 'isDeleted'), "model is marked as deleted");
- ok(!get(tom, 'isDirty'), "model is marked as not being dirty");
+ ok(get(tom, 'isDeleted'), "record is marked as deleted");
+ ok(!get(tom, 'isDirty'), "record is marked as not being dirty");
// there is nothing to commit, so eachType won't do anything
store.commit();
@@ -327,23 +327,23 @@ test("by default, createRecords calls createRecord once per record", function()
expect(8);
var count = 1;
- adapter.createRecord = function(store, type, model) {
+ adapter.createRecord = function(store, type, record) {
equal(type, Person, "the type is correct");
if (count === 1) {
- equal(get(model, 'name'), "Tom Dale");
+ equal(get(record, 'name'), "Tom Dale");
} else if (count === 2) {
- equal(get(model, 'name'), "Yehuda Katz");
+ equal(get(record, 'name'), "Yehuda Katz");
} else {
ok(false, "should not have invoked more than 2 times");
}
- var hash = get(model, 'data');
+ var hash = get(record, 'data');
hash.id = count;
hash.updated_at = "now";
- store.didCreateRecord(model, hash);
- equal(get(model, 'updatedAt'), "now", "the model should receive the new information");
+ store.didCreateRecord(record, hash);
+ equal(get(record, 'updatedAt'), "now", "the record should receive the new information");
count++;
};
@@ -362,25 +362,25 @@ test("by default, updateRecords calls updateRecord once per record", function()
var count = 0;
- adapter.updateRecord = function(store, type, model) {
+ adapter.updateRecord = function(store, type, record) {
equal(type, Person, "the type is correct");
if (count === 0) {
- equal(get(model, 'name'), "Tom Dale");
+ equal(get(record, 'name'), "Tom Dale");
} else if (count === 1) {
- equal(get(model, 'name'), "Yehuda Katz");
+ equal(get(record, 'name'), "Yehuda Katz");
} else {
ok(false, "should not get here");
}
count++;
- equal(model.get('isSaving'), true, "model is saving");
+ equal(record.get('isSaving'), true, "record is saving");
- store.didUpdateRecord(model);
+ store.didUpdateRecord(record);
- equal(model.get('isSaving'), false, "model is no longer saving");
- equal(model.get('isLoaded'), true, "model is saving");
+ equal(record.get('isSaving'), false, "record is no longer saving");
+ equal(record.get('isLoaded'), true, "record is saving");
};
store.load(Person, { id: 1, name: "Braaaahm Dale" });
@@ -403,19 +403,19 @@ test("calling store.didUpdateRecord can provide an optional hash", function() {
var count = 0;
- adapter.updateRecord = function(store, type, model) {
+ adapter.updateRecord = function(store, type, record) {
equal(type, Person, "the type is correct");
if (count === 0) {
- equal(get(model, 'name'), "Tom Dale");
- store.didUpdateRecord(model, { id: 1, name: "Tom Dale", updated_at: "now" });
- equal(get(model, 'isDirty'), false, "the model should not be dirty");
- equal(get(model, 'updatedAt'), "now", "the hash was updated");
+ equal(get(record, 'name'), "Tom Dale");
+ store.didUpdateRecord(record, { id: 1, name: "Tom Dale", updated_at: "now" });
+ equal(get(record, 'isDirty'), false, "the record should not be dirty");
+ equal(get(record, 'updatedAt'), "now", "the hash was updated");
} else if (count === 1) {
- equal(get(model, 'name'), "Yehuda Katz");
- store.didUpdateRecord(model, { id: 2, name: "Yehuda Katz", updated_at: "now!" });
- equal(model.get('isDirty'), false, "the model should not be dirty");
- equal(get(model, 'updatedAt'), "now!", "the hash was updated");
+ equal(get(record, 'name'), "Yehuda Katz");
+ store.didUpdateRecord(record, { id: 2, name: "Yehuda Katz", updated_at: "now!" });
+ equal(record.get('isDirty'), false, "the record should not be dirty");
+ equal(get(record, 'updatedAt'), "now!", "the hash was updated");
} else {
ok(false, "should not get here");
}
@@ -443,20 +443,20 @@ test("by default, deleteRecords calls deleteRecord once per record", function()
var count = 0;
- adapter.deleteRecord = function(store, type, model) {
+ adapter.deleteRecord = function(store, type, record) {
equal(type, Person, "the type is correct");
if (count === 0) {
- equal(get(model, 'name'), "Tom Dale");
+ equal(get(record, 'name'), "Tom Dale");
} else if (count === 1) {
- equal(get(model, 'name'), "Yehuda Katz");
+ equal(get(record, 'name'), "Yehuda Katz");
} else {
ok(false, "should not get here");
}
count++;
- store.didDeleteRecord(model);
+ store.didDeleteRecord(record);
};
store.load(Person, { id: 1, name: "Tom Dale" });
@@ -473,7 +473,7 @@ test("by default, deleteRecords calls deleteRecord once per record", function()
store.commit();
});
-test("if a created model is marked as invalid by the server, it enters an error state", function() {
+test("if a created record is marked as invalid by the server, it enters an error state", function() {
adapter.createRecord = function(store, type, record) {
equal(type, Person, "the type is correct");
@@ -509,7 +509,7 @@ test("if a created model is marked as invalid by the server, it enters an error
// Test key mapping
});
-test("if an updated model is marked as invalid by the server, it enters an error state", function() {
+test("if an updated record is marked as invalid by the server, it enters an error state", function() {
adapter.updateRecord = function(store, type, record) {
equal(type, Person, "the type is correct");
View
6 packages/ember-data/tests/unit/associations_test.js
@@ -312,9 +312,9 @@ test("it is possible to remove an item from an association", function() {
equal(getPath(person, 'tags.length'), 0, "object is removed from the association");
});
-module("ModelArray");
+module("RecordArray");
-test("updating the content of a ModelArray updates its content", function() {
+test("updating the content of a RecordArray updates its content", function() {
var Tag = DS.Model.extend({
name: DS.attr('string')
});
@@ -324,7 +324,7 @@ test("updating the content of a ModelArray updates its content", function() {
var clientIds = loaded.clientIds;
- var tags = DS.ModelArray.create({ content: Ember.A([clientIds[0], clientIds[1]]), store: store, type: Tag });
+ var tags = DS.RecordArray.create({ content: Ember.A([clientIds[0], clientIds[1]]), store: store, type: Tag });
var tag = tags.objectAt(0);
equal(get(tag, 'name'), "friendly", "precond - we're working with the right tags");
View
6 packages/ember-data/tests/unit/fixture_adapter_test.js
@@ -32,7 +32,7 @@ test("should load all data for a type asynchronously the first time it is reques
var ebryn = store.find(Person, 'ebryn');
- equal(get(ebryn, 'isLoaded'), false, "model from fixtures is returned in the loading state");
+ equal(get(ebryn, 'isLoaded'), false, "record from fixtures is returned in the loading state");
ebryn.addObserver('isLoaded', function() {
clearTimeout(timer);
@@ -42,8 +42,8 @@ test("should load all data for a type asynchronously the first time it is reques
equal(get(ebryn, 'height'), 70, "data from fixtures is loaded correctly");
var wycats = store.find(Person, 'wycats');
- equal(get(wycats, 'isLoaded'), true, "subsequent requests for models are returned immediately");
- equal(get(wycats, 'height'), 65, "subsequent requested models contain correct information");
+ equal(get(wycats, 'isLoaded'), true, "subsequent requests for records are returned immediately");
+ equal(get(wycats, 'height'), 65, "subsequent requested records contain correct information");
});
stop();
View
122 packages/ember-data/tests/unit/model_array_test.js
@@ -1,7 +1,7 @@
var get = Ember.get, set = Ember.set, getPath = Ember.getPath;
var Person;
-module("DS.ModelArray");
+module("DS.RecordArray");
var array = [{ id: 1, name: "Scumbag Dale" }, { id: 2, name: "Scumbag Katz" }, { id: 3, name: "Scumbag Bryn" }];
@@ -18,107 +18,107 @@ module("DS.Store", {
}
});
-test("a model array is backed by models", function() {
+test("a record array is backed by records", function() {
var store = DS.Store.create({ adapter: null });
store.loadMany(Person, [1,2,3], array);
- var modelArray = store.find(Person, [1,2,3]);
+ var recordArray = store.find(Person, [1,2,3]);
for (var i=0, l=get(array, 'length'); i<l; i++) {
- deepEqual(modelArray.objectAt(i).toJSON(), array[i], "a model array materializes objects on demand");
+ deepEqual(recordArray.objectAt(i).toJSON(), array[i], "a record array materializes objects on demand");
}
});
-test("a model is moved from a model array when it is deleted", function() {
+test("a record is removed from a record array when it is deleted", function() {
var store = DS.Store.create({ adapter: null });
store.loadMany(Person, [1,2,3], array);
var scumbag = store.find(Person, 1);
- var modelArray = store.find(Person, [1, 2, 3]);
- equal(get(modelArray, 'length'), 3, "precond - model array has three items");
- equal(get(modelArray.objectAt(0), 'name'), "Scumbag Dale", "item at index 0 is model with id 1");
+ var recordArray = store.find(Person, [1, 2, 3]);
+ equal(get(recordArray, 'length'), 3, "precond - record array has three items");
+ equal(get(recordArray.objectAt(0), 'name'), "Scumbag Dale", "item at index 0 is record with id 1");
scumbag.deleteRecord();
- equal(get(modelArray, 'length'), 2, "model is removed from the model array");
- ok(get(modelArray.objectAt(0), 'name') !== "Scumbag Dale", "item was removed");
+ equal(get(recordArray, 'length'), 2, "record is removed from the record array");
+ ok(get(recordArray.objectAt(0), 'name') !== "Scumbag Dale", "item was removed");
});
-test("a model array can have a filter on it", function() {
+test("a record array can have a filter on it", function() {
var store = DS.Store.create();
store.loadMany(Person, array);
- var modelArray = store.filter(Person, function(hash) {
+ var recordArray = store.filter(Person, function(hash) {
if (hash.get('name').match(/Scumbag [KD]/)) { return true; }
});
- equal(get(modelArray, 'length'), 2, "The model Array should have the filtered objects on it");
+ equal(get(recordArray, 'length'), 2, "The Record Array should have the filtered objects on it");
store.load(Person, { id: 4, name: "Scumbag Koz" });
- equal(get(modelArray, 'length'), 3, "The model Array should be updated as new items are added to the store");
+ equal(get(recordArray, 'length'), 3, "The Record Array should be updated as new items are added to the store");
store.load(Person, { id: 1, name: "Scumbag Tom" });
- equal(get(modelArray, 'length'), 2, "The model Array should be updated as existing members are updated");
+ equal(get(recordArray, 'length'), 2, "The Record Array should be updated as existing members are updated");
});
-test("a filtered model array includes created elements", function() {
+test("a filtered record array includes created elements", function() {
var store = DS.Store.create();
store.loadMany(Person, array);
- var modelArray = store.filter(Person, function(hash) {
+ var recordArray = store.filter(Person, function(hash) {
if (hash.get('name').match(/Scumbag [KD]/)) { return true; }
});
- equal(get(modelArray, 'length'), 2, "precond - The model Array should have the filtered objects on it");
+ equal(get(recordArray, 'length'), 2, "precond - The Record Array should have the filtered objects on it");
store.createRecord(Person, { name: "Scumbag Koz" });
- equal(get(modelArray, 'length'), 3, "The model array has the new object on it");
+ equal(get(recordArray, 'length'), 3, "The record array has the new object on it");
});
-test("a model array returns undefined when asking for a member outside of its content Array's range", function() {
+test("a record array returns undefined when asking for a member outside of its content Array's range", function() {
var store = DS.Store.create();
store.loadMany(Person, array);
- var modelArray = store.find(Person);
+ var recordArray = store.find(Person);
- strictEqual(modelArray.objectAt(20), undefined, "objects outside of the range just return undefined");
+ strictEqual(recordArray.objectAt(20), undefined, "objects outside of the range just return undefined");
});
-test("a model Array can update its filter", function() {
+test("a Record Array can update its filter", function() {
var store = DS.Store.create();
store.loadMany(Person, array);
- var modelArray = store.filter(Person, function(hash) {
+ var recordArray = store.filter(Person, function(hash) {
if (hash.get('name').match(/Scumbag [KD]/)) { return true; }
});
- equal(get(modelArray, 'length'), 2, "The model Array should have the filtered objects on it");
+ equal(get(recordArray, 'length'), 2, "The Record Array should have the filtered objects on it");
- modelArray.set('filterFunction', function(hash) {
+ recordArray.set('filterFunction', function(hash) {
if (hash.get('name').match(/Katz/)) { return true; }
});
- equal(get(modelArray, 'length'), 1, "The model Array should have one object on it");
+ equal(get(recordArray, 'length'), 1, "The Record Array should have one object on it");
store.load(Person, 5, { name: "Other Katz" });
- equal(get(modelArray, 'length'), 2, "The model Array now has the new object matching the filter");
+ equal(get(recordArray, 'length'), 2, "The Record Array now has the new object matching the filter");
store.load(Person, 6, { name: "Scumbag Demon" });
- equal(get(modelArray, 'length'), 2, "The model Array doesn't have objects matching the old filter");
+ equal(get(recordArray, 'length'), 2, "The Record Array doesn't have objects matching the old filter");
});
(function(){
- var store, modelArray;
+ var store, recordArray;
var clientEdits = function(ids) {
Ember.run( function() {
@@ -148,86 +148,86 @@ test("a model Array can update its filter", function() {
store.loadMany(Person, array);
- modelArray = store.filter(Person, function(hash) {
+ recordArray = store.filter(Person, function(hash) {
if (hash.get('name').match(/Scumbag/)) { return true; }
});
- equal(get(modelArray, 'length'), 3, "The filter function should work");
+ equal(get(recordArray, 'length'), 3, "The filter function should work");
};
- test("a model Array can update its filter after server-side updates one record", function() {
+ test("a Record Array can update its filter after server-side updates one record", function() {
setup({
- updateRecord: function(store, type, model) {
- store.didUpdateRecord(model, {id: 1, name: "Scumbag Server-side Dale"});
+ updateRecord: function(store, type, record) {
+ store.didUpdateRecord(record, {id: 1, name: "Scumbag Server-side Dale"});
}
});
clientEdits([1]);
- equal(get(modelArray, 'length'), 2, "The model array updates when the client changes records");
+ equal(get(recordArray, 'length'), 2, "The record array updates when the client changes records");
serverResponds();
- equal(get(modelArray, 'length'), 3, "The model array updates when the server changes one record");
+ equal(get(recordArray, 'length'), 3, "The record array updates when the server changes one record");
});
- test("a model Array can update its filter after server-side updates multiple records", function() {
+ test("a Record Array can update its filter after server-side updates multiple records", function() {
setup({
- updateRecords: function(store, type, models) {
- store.didUpdateRecords(models, [
+ updateRecords: function(store, type, records) {
+ store.didUpdateRecords(records, [
{id: 1, name: "Scumbag Server-side Dale"},
{id: 2, name: "Scumbag Server-side Katz"}
]);
}
});
clientEdits([1,2]);
- equal(get(modelArray, 'length'), 1, "The model array updates when the client changes records");
+ equal(get(recordArray, 'length'), 1, "The record array updates when the client changes records");
serverResponds();
- equal(get(modelArray, 'length'), 3, "The model array updates when the server changes multiple records");
+ equal(get(recordArray, 'length'), 3, "The record array updates when the server changes multiple records");
});
- test("a model Array can update its filter after server-side creates one record", function() {
+ test("a Record Array can update its filter after server-side creates one record", function() {
setup({
- createRecord: function(store, type, model) {
- store.didCreateRecord(model, {id: 4, name: "Scumbag Server-side Tim"});
+ createRecord: function(store, type, record) {
+ store.didCreateRecord(record, {id: 4, name: "Scumbag Server-side Tim"});
}
});
clientCreates(["Tim"]);
- equal(get(modelArray, 'length'), 3, "The model array does not include non-matching records");
+ equal(get(recordArray, 'length'), 3, "The record array does not include non-matching records");
serverResponds();
- equal(get(modelArray, 'length'), 4, "The model array updates when the server creates a record");
+ equal(get(recordArray, 'length'), 4, "The record array updates when the server creates a record");
});
- test("a model Array can update its filter after server-side creates multiple records", function() {
+ test("a Record Array can update its filter after server-side creates multiple records", function() {
setup({
- createRecords: function(store, type, models) {