Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
openhoat committed Jul 30, 2015
1 parent ce14e9f commit 8022969
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Entity.findIdsByIndex = function (name, value) {
index = clazz.indexes && clazz.indexes[name];
if (!index) {
logger.enabledLevels.debug && log.debug('no index "%s" for entity "%s"', name, type);
return [];
return;
}
k = util.format.apply(null, Array.isArray(value) ? [index.key].concat(value) : [index.key, value]);
return ohm.exec(index.unique ? 'get' : 'smembers', k)
Expand All @@ -63,14 +63,14 @@ Entity.findIdsByIndex = function (name, value) {
},
function (result) {
var link, k;
if (result.length) {
if (result) {
return result;
}
logger.enabledLevels.info && log.info('searching %s entity ID with link "%s" matching "%s"', type, name, value);
link = clazz.links && clazz.links[name];
if (!link) {
logger.enabledLevels.debug && log.debug('no link "%s" for entity "%s"', name, type);
return result;
return [];
}
k = util.format.apply(null, Array.isArray(value) ? [link.key].concat(value) : [link.key, value]);
return ohm.exec(link.reverseUnique ? 'get' : 'smembers', k)
Expand Down
2 changes: 1 addition & 1 deletion lib/ohm.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ ohm = {
entityClassName = _.camelCase(name);
entityClassName = entityClassName.substring(0, 1).toUpperCase() + entityClassName.substring(1);
if (typeof ohm[entityClassName] === 'undefined') {
logger.enabledLevels.debug && log.debug('entityClassName :', entityClassName);
logger.enabledLevels.debug && log.debug('registering entity class "%s"', entityClassName);
ohm[entityClassName] = entityClass;
} else {
logger.enabledLevels.debug && log.debug('ohm already has a property named "%s" : cannot define entity class', entityClassName);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hw-redis-ohm",
"version": "0.0.2",
"version": "0.0.3",
"description": "Redis Object Hash Mapping",
"main": "lib/ohm.js",
"author": "Olivier Penhoat <openhoat@gmail.com> (http://headwood.net/)",
Expand Down
7 changes: 4 additions & 3 deletions test/ohmSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('hw-redis-ohm', function () {
type: 'hasOne',
target: 'contact',
as: 'masterId',
foreignKey: 'dogIds',
foreignKey: 'dogId',
unique: true
}],
operations: {
Expand Down Expand Up @@ -260,6 +260,7 @@ describe('hw-redis-ohm', function () {
entity.value.masterId = contactEntities[index].getId();
dogEntities.push(entity);
return entity.save().then(function (result) {
contactEntities[index].value.dogId = result.getId();
expect(result).to.eql(entity);
expect(entity.getId()).to.match(new RegExp(ohm.patterns.id));
});
Expand Down Expand Up @@ -302,8 +303,8 @@ describe('hw-redis-ohm', function () {
});
},
function findContactOfDog() {
return ohm.Contact.findByIndex('dogIds', dogEntities[0].getId()).then(function (result) {
expect(result).to.be.an('array').of.length(0);
return ohm.Contact.findByIndex('dogId', dogEntities[0].getId()).then(function (result) {
expect(result).to.be.an('array').of.length(1);
});
},
function findByContactUnknown() {
Expand Down

0 comments on commit 8022969

Please sign in to comment.