Skip to content

Commit 36968a0

Browse files
author
Chris Carpenter
committed
Fix not unique table/alias
1 parent 082ef53 commit 36968a0

File tree

1 file changed

+2
-37
lines changed

1 file changed

+2
-37
lines changed

src/VersioningScope.php

+2-37
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,6 @@ public function apply(Builder $builder, Model $model)
3333
$this->extend($builder);
3434
}
3535

36-
/**
37-
* Remove the scope from the given Eloquent query builder.
38-
*
39-
* @param \Illuminate\Database\Eloquent\Builder $builder
40-
* @param \Illuminate\Database\Eloquent\Model $model
41-
* @return void
42-
*/
43-
public function remove(Builder $builder, Model $model)
44-
{
45-
$table = $model->getVersionTable();
46-
47-
$query = $builder->getQuery();
48-
49-
$query->joins = collect($query->joins)->reject(function($join) use ($table)
50-
{
51-
return $this->isVersionJoinConstraint($join, $table);
52-
})->values()->all();
53-
}
54-
5536
/**
5637
* Extend the query builder with the needed functions.
5738
*
@@ -77,9 +58,7 @@ protected function addVersion(Builder $builder)
7758
$builder->macro('version', function(Builder $builder, $version) {
7859
$model = $builder->getModel();
7960

80-
$this->remove($builder, $builder->getModel());
81-
82-
$builder->join($model->getVersionTable(), function($join) use ($model, $version) {
61+
$builder->withoutGlobalScope($this)->join($model->getVersionTable(), function($join) use ($model, $version) {
8362
$join->on($model->getQualifiedKeyName(), '=', $model->getQualifiedVersionKeyName());
8463
$join->where($model->getQualifiedVersionColumn(), '=', $version);
8564
});
@@ -99,26 +78,12 @@ protected function addAllVersions(Builder $builder)
9978
$builder->macro('allVersions', function(Builder $builder) {
10079
$model = $builder->getModel();
10180

102-
$this->remove($builder, $builder->getModel());
103-
104-
$builder->join($model->getVersionTable(), function($join) use ($model) {
81+
$builder->withoutGlobalScope($this)->join($model->getVersionTable(), function($join) use ($model) {
10582
$join->on($model->getQualifiedKeyName(), '=', $model->getQualifiedVersionKeyName());
10683
});
10784

10885
return $builder;
10986
});
11087
}
11188

112-
/**
113-
* Determine if the given join clause is a version constraint.
114-
*
115-
* @param \Illuminate\Database\Query\JoinClause $join
116-
* @param string $column
117-
* @return bool
118-
*/
119-
protected function isVersionJoinConstraint(JoinClause $join, $table)
120-
{
121-
return $join->type == 'inner' && $join->table == $table;
122-
}
123-
12489
}

0 commit comments

Comments
 (0)