Stillat / relationships

Provides automated bi-directional @statamic entry relationships
MIT License
16 stars 1 forks source link

Users In Database Break Relationship Save #27

Closed danielml01 closed 8 months ago

danielml01 commented 8 months ago

Error: in_array(): Argument #2 ($haystack) must be of type array, string given at vendor/stillat/relationships/src/Processors/RelationshipProcessor.php:409

This is because if users are in a database (as opposed to flat files), the relationship field is stored as a string that looks like ["slug", "slug2", "slug3"]

Can be resolved before line 409 with something like:

if (is_string($rightReference)) {
    $rightReference = str_ireplace(['[', ']', '\\', '"'], '', $rightReference);
    $rightReference = explode(',', $rightReference);
}
JohnathonKoster commented 8 months ago

Thanks for the info!

Feel free to open a PR with the proposed change and I can take a look later today - if not, I will likely have time to reproduce/address in the later half of next week.

JohnathonKoster commented 8 months ago

Carved out some time for this today and released as part of 2.1.2

GioChocolateBro commented 8 months ago

@JohnathonKoster I was using a patch file to make things work with the eloquent driver

--- /dev/null
+++ ../src/Processors/RelationshipProcessor.php
@@ -183,7 +183,8 @@
         $updated = [];

         if ($this->pristineEntry != null && $this->isNewEntry == false) {
-            $pristine = $this->getFieldValue($fieldName, $this->pristineEntry, []);
+            //$pristine = $this->getFieldValue($fieldName, $this->pristineEntry, []);
+            $pristine = $this->pristineEntry->model()[$fieldName];
         }

         if ($this->isDelete) {

I don't think I need this anymore right?