Skip to content

Commit

Permalink
chore(modelClass): works toward consistent use of kind/modelClass/int…
Browse files Browse the repository at this point in the history
…ernalModel/record
  • Loading branch information
runspired committed Oct 22, 2016
1 parent 44bdeef commit 196ca7a
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 240 deletions.
27 changes: 13 additions & 14 deletions addon/-private/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ export function debugSeal() {
return Ember.debugSeal(...arguments);
}

function checkPolymorphic(typeClass, addedRecord) {
if (typeClass.__isMixin) {
function checkPolymorphic(modelClass, addedModelClass) {
if (modelClass.__isMixin) {
//TODO Need to do this in order to support mixins, should convert to public api
//once it exists in Ember
return typeClass.__mixin.detect(addedRecord.type.PrototypeMixin);
return modelClass.__mixin.detect(addedModelClass.PrototypeMixin);
}
if (Ember.MODEL_FACTORY_INJECTIONS) {
typeClass = typeClass.superclass;
modelClass = modelClass.superclass;
}
return typeClass.detect(addedRecord.type);
return modelClass.detect(addedModelClass);
}

/*
Expand All @@ -57,19 +57,18 @@ function checkPolymorphic(typeClass, addedRecord) {
`record.relationshipFor(key)`.
@method assertPolymorphicType
@param {InternalModel} record
@param {InternalModel} internalModel
@param {RelationshipMeta} relationshipMeta retrieved via
`record.relationshipFor(key)`
@param {InternalModel} addedRecord record which
should be added/set for the relationship
*/
export function assertPolymorphicType(record, relationshipMeta, addedRecord) {
var addedType = addedRecord.type.modelName;
var recordType = record.type.modelName;
var key = relationshipMeta.key;
var typeClass = record.store.modelFor(relationshipMeta.type);
export function assertPolymorphicType(parentInternalModel, relationshipMeta, addedInternalModel) {
let addedModelName = addedInternalModel.modelName;
let parentModelName = parentInternalModel.modelName;
let key = relationshipMeta.key;
let relationshipClass = parentInternalModel.store.modelFor(relationshipMeta.type);
let assertionMessage = `You cannot add a record of modelClass '${addedModelName}' to the '${parentModelName}.${key}' relationship (only '${relationshipClass.modelName}' allowed)`;

var assertionMessage = `You cannot add a record of type '${addedType}' to the '${recordType}.${key}' relationship (only '${typeClass.modelName}' allowed)`;

assert(assertionMessage, checkPolymorphic(typeClass, addedRecord));
assert(assertionMessage, checkPolymorphic(relationshipClass, addedInternalModel.modelClass));
}
3 changes: 2 additions & 1 deletion addon/-private/system/many-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
if (!this.currentState[index]) {
return undefined;
}
return this.currentState[index].getRecord();

return this.currentState[index].record;
},

flushCanonical() {
Expand Down
Loading

0 comments on commit 196ca7a

Please sign in to comment.