From 4576e2a5525fde6d4f3c9fc51c8f2862541777a7 Mon Sep 17 00:00:00 2001 From: overtrue Date: Thu, 1 Nov 2018 21:59:59 +0800 Subject: [PATCH] Bugfix #72 for MSSQL. --- src/Traits/CanBeFollowed.php | 2 +- src/Traits/CanFollow.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Traits/CanBeFollowed.php b/src/Traits/CanBeFollowed.php index a28f138..adef2f1 100644 --- a/src/Traits/CanBeFollowed.php +++ b/src/Traits/CanBeFollowed.php @@ -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}") diff --git a/src/Traits/CanFollow.php b/src/Traits/CanFollow.php index d3fc9d3..beb0758 100644 --- a/src/Traits/CanFollow.php +++ b/src/Traits/CanFollow.php @@ -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}")