Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #136 from shustariov-andrey/master

Multilevel prefetch
  • Loading branch information...
commit 4ecb3aebcf8f83372980acdc11fa323aabf32aec 2 parents ddce1cc + 446f979
@zefhemel zefhemel authored
Showing with 26 additions and 7 deletions.
  1. +0 −1  lib/persistence.js
  2. +26 −6 lib/persistence.store.sql.js
View
1  lib/persistence.js 100644 → 100755
@@ -468,7 +468,6 @@ persistence.get = function(arg1, arg2) {
}
}
if(oldValueObj) {
- console.log("OldValue", oldValueObj);
var inverse = oldValueObj[meta.hasOne[ref].inverseProperty];
if(inverse.list && inverse._filter) {
inverse.triggerEvent('change', that, ref, val);
View
32 lib/persistence.store.sql.js 100644 → 100755
@@ -652,15 +652,26 @@ function config(persistence, dialect) {
joinSql += this._additionalJoinSqls.join(' ');
for ( var i = 0; i < this._prefetchFields.length; i++) {
- var prefetchField = this._prefetchFields[i];
- var thisMeta = meta.hasOne[prefetchField].type.meta;
+ var prefetchFieldParts = this._prefetchFields[i].split('.');
+ var prefetchField = prefetchFieldParts[0];
+ var eName = entityName;
+ if(prefetchFieldParts.length > 1){
+ prefetchField = prefetchFieldParts[1];
+ eName = prefetchFieldParts[0];
+ }
+ var theMeta = persistence.getMeta(eName);
+ var thisMeta = theMeta.hasOne[prefetchField].type.meta;
if (thisMeta.isMixin)
throw new Error("cannot prefetch a mixin");
var tableAlias = thisMeta.name + '_' + prefetchField + "_tbl";
+ var PrefetchFrom = mainAlias;
+ if(prefetchFieldParts.length > 1){
+ PrefetchFrom = eName + '_' + eName + "_tbl";;
+ }
selectFields = selectFields.concat(selectAll(thisMeta, tableAlias,
prefetchField + "_"));
joinSql += "LEFT JOIN `" + thisMeta.name + "` AS `" + tableAlias
- + "` ON `" + tableAlias + "`.`id` = `" + mainAlias + '`.`' + prefetchField + "` ";
+ + "` ON `" + tableAlias + "`.`id` = `" + PrefetchFrom + '`.`' + prefetchField + "` ";
}
@@ -698,8 +709,17 @@ function config(persistence, dialect) {
var r = rows[i];
var e = rowToEntity(session, entityName, r, mainPrefix);
for ( var j = 0; j < that._prefetchFields.length; j++) {
- var prefetchField = that._prefetchFields[j];
- var thisMeta = meta.hasOne[prefetchField].type.meta;
+
+ var prefetchFieldParts = that._prefetchFields[j].split('.');
+ var prefetchField = prefetchFieldParts[0];
+ var eName = entityName;
+ if(prefetchFieldParts.length > 1){
+ prefetchField = prefetchFieldParts[1];
+ eName = prefetchFieldParts[0];
+ }
+ var theMeta = persistence.getMeta(eName);
+ var thisMeta = theMeta.hasOne[prefetchField].type.meta;
+
e._data_obj[prefetchField] = rowToEntity(session, thisMeta.name, r, prefetchField + '_');
session.add(e._data_obj[prefetchField]);
}
@@ -892,7 +912,7 @@ if (typeof exports !== 'undefined') {
}
else {
window = window || {};
- window.persistence = window.persistence || {};
+ window.persistence = window.persistence || persistence || {};
window.persistence.store = window.persistence.store || {};
window.persistence.store.sql = {
defaultTypeMapper: defaultTypeMapper,
Please sign in to comment.
Something went wrong with that request. Please try again.