From 9532a279ce6d8b82ac28b15500eea659e6639e4f Mon Sep 17 00:00:00 2001 From: Pawlo Date: Wed, 23 Sep 2020 20:06:28 +0200 Subject: [PATCH 1/2] update readme after eagerloading issues --- readme.md | 11 +++++++++++ src/Eloquent/Collection.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index e47c7aa..6f29674 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,9 @@ + +**DISCLAIMER : ELOQUENT FUNCTIONS OF THIS MACKAGE WILL BREAK EAGERLOADING OF BELONGSTOMANY RELATIONSHIPS** + +*This package is not compatible with belongsToMany relationships due to the indexation of entries. It is recommended not to use this package until I submit a solution to index collections properly* + + ## Utility classes for Laravel >= 5.8 ### Highest Laravel compatibily tested as of this readme : 7.9.2 @@ -37,6 +43,11 @@ Base Model class offers:
Collection as results of queries on a Model return an instance of `khwadj\Eloquent\Collection` that is indexed by primary key +**CAREFUL : THIS WILL BREAK EAGERLOADING OF BELONGSTOMANY RELATIONSHIPS** + +*This package is not compatible with belongsToMany relationships due to the indexation of entries. It is recommended not to use this package until I submit a solution to index collections properly* + + ``` $models = MyModel::all(); // get the model with primary key = 1 diff --git a/src/Eloquent/Collection.php b/src/Eloquent/Collection.php index 8c09e72..9e56eb3 100644 --- a/src/Eloquent/Collection.php +++ b/src/Eloquent/Collection.php @@ -29,7 +29,7 @@ public function add($item, $key = NULL) if ( $item instanceof Model ) $key = $item->getKey(); } - if ( $key ) $this->items[$key] = $item; + if ( $key !== NULL ) $this->items[$key] = $item; else $this->items[] = $item; return $this; From d34fb29381a29b28842bab5e5aa425d666c3b833 Mon Sep 17 00:00:00 2001 From: Pawlo Date: Wed, 23 Sep 2020 20:07:09 +0200 Subject: [PATCH 2/2] typo --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 6f29674..3c47244 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@ -**DISCLAIMER : ELOQUENT FUNCTIONS OF THIS MACKAGE WILL BREAK EAGERLOADING OF BELONGSTOMANY RELATIONSHIPS** +**DISCLAIMER : ELOQUENT FUNCTIONS OF THIS PACKAGE WILL BREAK EAGERLOADING OF BELONGSTOMANY RELATIONSHIPS** *This package is not compatible with belongsToMany relationships due to the indexation of entries. It is recommended not to use this package until I submit a solution to index collections properly*