Skip to content

Commit

Permalink
simplified mixin implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Jouhier authored and Bruno Jouhier committed Oct 18, 2010
1 parent 71f97d7 commit 2e211cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
17 changes: 7 additions & 10 deletions lib/persistence.js
Expand Up @@ -387,16 +387,6 @@ persistence.get = function(arg1, arg2) {
throw "Property '" + ref + "' with id: " + that._data[ref] + " not fetched, either prefetch it or fetch it manually.";
}
});
if (mixinClass) {
meta.fields[mixinClass] = persistence.typeMapper ? persistence.typeMapper.classNameType : "TEXT";
persistence.defineProp(that, mixinClass, function(val) {
var oldValue = that._data[mixinClass];
that._data[mixinClass] = val;
that._dirtyProperties[mixinClass] = oldValue;
}, function() {
return that._data[mixinClass];
})
}
}());
}
}
Expand Down Expand Up @@ -844,6 +834,7 @@ persistence.get = function(arg1, arg2) {
tableName: tableName
};
delete meta.hasOne[collName];
delete meta.fields[collName + "_class"]; // in case it existed
} else {
meta.hasMany[collName] = {
type: otherEntity,
Expand All @@ -853,17 +844,23 @@ persistence.get = function(arg1, arg2) {
type: Entity,
inverseProperty: collName
};
if (meta.isMixin)
otherMeta.fields[invRel + "_class"] = persistence.typeMapper ? persistence.typeMapper.classNameType : "TEXT";
}
}

Entity.hasOne = function (refName, otherEntity) {
meta.hasOne[refName] = {
type: otherEntity
};
if (otherEntity.meta.isMixin)
meta.fields[refName + "_class"] = persistence.typeMapper ? persistence.typeMapper.classNameType : "TEXT";
};

Entity.is = function(mixin){
var mixinMeta = mixin.meta;
if (!mixinMeta.isMixin)
throw new Error("not a mixin: " + mixin);
for (var field in mixinMeta.fields) {
console.log("mixin field: " + field);
if (mixinMeta.fields.hasOwnProperty(field))
Expand Down
2 changes: 0 additions & 2 deletions lib/persistence.store.sql.js
Expand Up @@ -181,8 +181,6 @@ persistence.store.sql.config = function(persistence, dialect) {
if (meta.hasOne.hasOwnProperty(rel)) {
otherMeta = meta.hasOne[rel].type.meta;
colDefs.push([rel, tm.idType]);
if (otherMeta.isMixin)
colDefs.push([rel + "_class", tm.classNameType]);
queries.push([dialect.createIndex(meta.name, [rel]), null]);
}
}
Expand Down

0 comments on commit 2e211cd

Please sign in to comment.