Skip to content

Commit

Permalink
Merge pull request #2072 from yajra/reverts
Browse files Browse the repository at this point in the history
Revert #2051, fix #2058.
  • Loading branch information
yajra authored Apr 26, 2019
2 parents 4114813 + 9bcb828 commit d725ca0
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/EloquentDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected function joinEagerLoadedColumn($relation, $relationColumn)
$table = '';
$deletedAt = false;
$lastQuery = $this->query;
foreach (explode('.', $relation) as $index => $eachRelation) {
foreach (explode('.', $relation) as $eachRelation) {
$model = $lastQuery->getRelation($eachRelation);
switch (true) {
case $model instanceof BelongsToMany:
Expand Down Expand Up @@ -169,24 +169,19 @@ protected function joinEagerLoadedColumn($relation, $relationColumn)

case $model instanceof BelongsTo:
$table = $model->getRelated()->getTable();
$alias = "{$table}_{$index}";
$tableAs = "{$table} AS {$alias}";
$foreign = $model->getQualifiedForeignKeyName();
$other = "{$alias}.{$model->getOwnerKeyName()}";
$other = $model->getQualifiedOwnerKeyName();
$deletedAt = $this->checkSoftDeletesOnModel($model->getRelated());

break;

default:
throw new Exception('Relation ' . get_class($model) . ' is not yet supported.');
}
$this->performJoin($tableAs ?? $table, $foreign, $other, $deletedAt);
$this->performJoin($table, $foreign, $other, $deletedAt);
$lastQuery = $model->getQuery();
}

$table = $alias ?? $table;

return "{$table}.{$relationColumn}";
return $table . '.' . $relationColumn;
}

protected function checkSoftDeletesOnModel($model)
Expand Down

0 comments on commit d725ca0

Please sign in to comment.