From f28c0a3e1fddbfab32986a8d71cd6250e0ec3c25 Mon Sep 17 00:00:00 2001 From: Khalil Laleh Date: Fri, 27 Nov 2020 23:47:14 +0330 Subject: [PATCH 1/2] Move the getRelationCountHash method to parent class (relation) --- .../Database/Eloquent/Relations/BelongsTo.php | 18 ------------------ .../Eloquent/Relations/BelongsToMany.php | 18 ------------------ .../Eloquent/Relations/HasManyThrough.php | 18 ------------------ .../Eloquent/Relations/HasOneOrMany.php | 18 ------------------ .../Database/Eloquent/Relations/Relation.php | 18 ++++++++++++++++++ 5 files changed, 18 insertions(+), 72 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php b/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php index e438d8854490..ce7ba4421973 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php @@ -40,13 +40,6 @@ class BelongsTo extends Relation */ protected $relationName; - /** - * The count of self joins. - * - * @var int - */ - protected static $selfJoinCount = 0; - /** * Create a new belongs to relationship instance. * @@ -279,17 +272,6 @@ public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder ); } - /** - * Get a relationship join table hash. - * - * @param bool $lockCount - * @return string - */ - public function getRelationCountHash($lockCount = false) - { - return 'laravel_reserved_'.($lockCount ? static::$selfJoinCount : static::$selfJoinCount++); - } - /** * Determine if the related model has an auto-incrementing ID. * diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php index ae82ac02ddce..f2904972cc3f 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php @@ -127,13 +127,6 @@ class BelongsToMany extends Relation */ protected $accessor = 'pivot'; - /** - * The count of self joins. - * - * @var int - */ - protected static $selfJoinCount = 0; - /** * Create a new belongs to many relationship instance. * @@ -1167,17 +1160,6 @@ public function getExistenceCompareKey() return $this->getQualifiedForeignPivotKeyName(); } - /** - * Get a relationship join table hash. - * - * @param bool $lockCount - * @return string - */ - public function getRelationCountHash($lockCount = false) - { - return 'laravel_reserved_'.($lockCount ? static::$selfJoinCount : static::$selfJoinCount++); - } - /** * Specify that the pivot table has creation and update timestamps. * diff --git a/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php b/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php index 7d5008d782c2..6285cf230b7f 100644 --- a/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php +++ b/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php @@ -53,13 +53,6 @@ class HasManyThrough extends Relation */ protected $secondLocalKey; - /** - * The count of self joins. - * - * @var int - */ - protected static $selfJoinCount = 0; - /** * Create a new has many through relationship instance. * @@ -596,17 +589,6 @@ public function getRelationExistenceQueryForThroughSelfRelation(Builder $query, ); } - /** - * Get a relationship join table hash. - * - * @param bool $lockCount - * @return string - */ - public function getRelationCountHash($lockCount = false) - { - return 'laravel_reserved_'.($lockCount ? static::$selfJoinCount : static::$selfJoinCount++); - } - /** * Get the qualified foreign key on the related model. * diff --git a/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php b/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php index 18dc09094886..ede942018f6f 100755 --- a/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php @@ -22,13 +22,6 @@ abstract class HasOneOrMany extends Relation */ protected $localKey; - /** - * The count of self joins. - * - * @var int - */ - protected static $selfJoinCount = 0; - /** * Create a new has one or many relationship instance. * @@ -363,17 +356,6 @@ public function getRelationExistenceQueryForSelfRelation(Builder $query, Builder ); } - /** - * Get a relationship join table hash. - * - * @param bool $lockCount - * @return string - */ - public function getRelationCountHash($lockCount = false) - { - return 'laravel_reserved_'.($lockCount ? static::$selfJoinCount : static::$selfJoinCount++); - } - /** * Get the key for comparing against the parent key in "has" query. * diff --git a/src/Illuminate/Database/Eloquent/Relations/Relation.php b/src/Illuminate/Database/Eloquent/Relations/Relation.php index 97ee55de772b..a24ea7e22c3e 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Relation.php +++ b/src/Illuminate/Database/Eloquent/Relations/Relation.php @@ -62,6 +62,13 @@ abstract class Relation */ public static $tableNameAsMorphType = false; + /** + * The count of self joins. + * + * @var int + */ + protected static $selfJoinCount = 0; + /** * Create a new relation instance. * @@ -220,6 +227,17 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, ); } + /** + * Get a relationship join table hash. + * + * @param bool $lockCount + * @return string + */ + public function getRelationCountHash($lockCount = false) + { + return 'laravel_reserved_'.($lockCount ? static::$selfJoinCount : static::$selfJoinCount++); + } + /** * Get all of the primary keys for an array of models. * From e42111d3429466555e0516f8b2730769d8ce5bbc Mon Sep 17 00:00:00 2001 From: Khalil Laleh Date: Fri, 27 Nov 2020 23:59:53 +0330 Subject: [PATCH 2/2] Rename the getRelationCountHash parameter to incrementJoinCount --- src/Illuminate/Database/Eloquent/Relations/Relation.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/Relation.php b/src/Illuminate/Database/Eloquent/Relations/Relation.php index a24ea7e22c3e..c698217abf9a 100755 --- a/src/Illuminate/Database/Eloquent/Relations/Relation.php +++ b/src/Illuminate/Database/Eloquent/Relations/Relation.php @@ -230,12 +230,12 @@ public function getRelationExistenceQuery(Builder $query, Builder $parentQuery, /** * Get a relationship join table hash. * - * @param bool $lockCount + * @param bool $incrementJoinCount * @return string */ - public function getRelationCountHash($lockCount = false) + public function getRelationCountHash($incrementJoinCount = true) { - return 'laravel_reserved_'.($lockCount ? static::$selfJoinCount : static::$selfJoinCount++); + return 'laravel_reserved_'.($incrementJoinCount ? static::$selfJoinCount++ : static::$selfJoinCount); } /**