Skip to content

Commit

Permalink
fix: deprecated relatedTableAlias from objection.js, upgrade objectio…
Browse files Browse the repository at this point in the history
…njs (#44)
  • Loading branch information
vigzmv authored and kibertoad committed Feb 26, 2019
1 parent 275bc04 commit 5116082
Show file tree
Hide file tree
Showing 4 changed files with 741 additions and 705 deletions.
7 changes: 5 additions & 2 deletions lib/FindQueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,11 @@ class FindQueryBuilder {
});
});

_.each(_.uniq(relationsToJoin, 'name'), function(relation) {
relation.join(builder, { joinOperation: 'leftJoin' });
_.each(_.uniq(relationsToJoin, 'name'), relation => {
relation.join(builder, {
joinOperation: 'leftJoin',
relatedTableAlias: this._modelClass.tableName + '_rel_' + relation.name
});
});

if (!_.isEmpty(relationsToJoin)) {
Expand Down
9 changes: 8 additions & 1 deletion lib/PropertyRef.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ class PropertyRef {
const builder = this.modelClass.query();
// one-to-one relations are joined and the joined table is given an alias.
// We must refer to the column through that alias.
return this.relation.relatedTableAlias(builder) + '.' + this.columnName;

return (
this.relation.relatedModelClass.getTableName() +
'_rel_' +
this.relation.name +
'.' +
this.columnName
);
} else {
return this.modelClass.tableName + '.' + this.columnName;
}
Expand Down
Loading

0 comments on commit 5116082

Please sign in to comment.