Skip to content

Commit

Permalink
Bugfix #72 for MSSQL.
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Nov 1, 2018
1 parent c078306 commit 4576e2a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Traits/CanBeFollowed.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function followers()
return $this->morphToMany(config('follow.user_model'), config('follow.morph_prefix'), config('follow.followable_table'))
->wherePivot('relation', '=', Follow::RELATION_FOLLOW)
->withPivot('followable_type', 'relation', 'created_at')
->addSelect("{$userTable}.*", DB::raw("{$tablePrefixedForeignKey} IS NOT NULL as {$eachOtherKey}"))
->addSelect("{$userTable}.*", DB::raw("(CASE WHEN {$tablePrefixedForeignKey} IS NOT NULL THEN 1 ELSE 0 END) as {$eachOtherKey}"))
->leftJoin("{$table} as pivot_followables", function ($join) use ($table, $class, $foreignKey) {
$join->on('pivot_followables.followable_type', '=', DB::raw(\addcslashes("'{$class}'", '\\')))
->on('pivot_followables.followable_id', '=', "{$table}.{$foreignKey}")
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/CanFollow.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function followings($class = __CLASS__)
return $this->morphedByMany($class, config('follow.morph_prefix'), $table)
->wherePivot('relation', '=', Follow::RELATION_FOLLOW)
->withPivot('followable_type', 'relation', 'created_at')
->addSelect("{$targetTable}.*", DB::raw("{$tablePrefixedForeignKey} IS NOT NULL as {$eachOtherKey}"))
->addSelect("{$targetTable}.*", DB::raw("(CASE WHEN {$tablePrefixedForeignKey} IS NOT NULL THEN 1 ELSE 0 END) as {$eachOtherKey}"))
->leftJoin("{$table} as pivot_followables", function ($join) use ($table, $class, $foreignKey) {
$join->on('pivot_followables.followable_type', '=', DB::raw(\addcslashes("'{$class}'", '\\')))
->on('pivot_followables.followable_id', '=', "{$table}.{$foreignKey}")
Expand Down

0 comments on commit 4576e2a

Please sign in to comment.