diff --git a/lib/persistence.store.sql.js b/lib/persistence.store.sql.js index 07b681f..bdb7a2e 100644 --- a/lib/persistence.store.sql.js +++ b/lib/persistence.store.sql.js @@ -648,8 +648,10 @@ function config(persistence, dialect) { joinSql += this._additionalJoinSqls.join(' '); - for ( var i = 0; i < this._prefetchFields.length; i++) { - var prefetchField = this._prefetchFields[i]; + this._prefetchFields.forEach(function(prefetchField) { + if(!(prefetchField in meta.hasOne)) { + throw(new ReferenceError( "'" + meta.name + "' does not 'hasOne' field called '" + prefetchField + "'.")); + } var thisMeta = meta.hasOne[prefetchField].type.meta; if (thisMeta.isMixin) throw new Error("cannot prefetch a mixin"); @@ -659,7 +661,7 @@ function config(persistence, dialect) { joinSql += "LEFT JOIN `" + thisMeta.name + "` AS `" + tableAlias + "` ON `" + tableAlias + "`.`id` = `" + mainAlias + '`.`' + prefetchField + "` "; - } + }); var whereSql = "WHERE " + [ this._filter.sql(meta, mainAlias, args) ].concat(additionalWhereSqls).join(' AND ');