Stillat / relationships

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

php please relate:fill resulting in errors #10

Closed philliphartin closed 1 year ago

philliphartin commented 2 years ago

Firstly, thank you for this fantastic package.

I'm having an issue running the relate:fill command. I am receiving the following error:

❯ php please relate:fill --dry
Updating relationships. This may take a while if you have a lot of entries.

   TypeError

  Stillat\Relationships\Processors\FillRelationshipsProcessor::fillRelationship(): Argument #1 ($relationship) must be of type Stillat\Relationships\EntryRelationship, string given, called in /Users/myuser/Development/myproject/vendor/stillat/relationships/src/Processors/FillRelationshipsProcessor.php on line 56

  at vendor/stillat/relationships/src/Processors/FillRelationshipsProcessor.php:60
     56▕             $this->fillRelationship($relationship);
     57▕         }
     58▕     }
     59▕
  ➜  60▕     protected function fillRelationship(EntryRelationship $relationship)
     61▕     {
     62▕         $collectionEntries = $this->entries->query()
     63▕             ->whereIn('collection', [$relationship->leftCollection])
     64▕             ->where($relationship->leftField, '!=', null)

      +16 vendor frames
  17  please:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

The relationship is configured as follows in AppServiceProvider:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Stillat\Relationships\Support\Facades\Relate;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Relate::oneToMany(
            'books.author',
            'authors.books'
        );
    }
}

I'm not sure what's causing the issue. I've played around with manual relationships as well but always get the error. In addition when I run relate:list my console output has [entry] prefixed to each collection

formable on  develop [$!] via  v16.16.0 via 🐘 v8.1.10
❯ php please relate:list
+---+--------------------+--------------------+-----------------+---------------+-------------------+--------------+----------------+-----------------------+
|   | Primary Collection | Related Collection | Primary Field   | Related Field | Relationship      | With Events? | Allow Deletes? | Is Automatic Inverse? |
+---+--------------------+--------------------+-----------------+---------------+-------------------+--------------+----------------+-----------------------+
| 1 | [entry].books      | [entry].author     | [entry].authors | books         | Many to One (*-1) | No           | Yes            | No                    |
| 2 | [entry].authors    | [entry].books      | [entry].books   | author        | One to Many (1-*) | No           | Yes            | Yes (1)               |
+---+--------------------+--------------------+-----------------+---------------+-------------------+--------------+----------------+-----------------------+

I'm not sure if this is relevant to the issue, but I thought it may add some more context.


System Details Statamic 3.3.37 Stillat/relationships 1.1.1 PHP: 8.1

Running on a default local valet dev environment

netnakgraham commented 1 year ago

Hi, I am having the exact issue as above, furthermore, when I add a new entry to my "books" collection, I get the following error:

"message": "array_diff(): Argument #1 ($array) must be of type array, int given", "exception": "TypeError", "file": "F:\\GitHub\\childmindinguk\\vendor\\stillat\\relationships\\src\\Comparisons\\ListComparator.php", "line": 34, "trace": [ { "file": "F:\\GitHub\\childmindinguk\\vendor\\stillat\\relationships\\src\\Comparisons\\ListComparator.php", "line": 34, "function": "array_diff" }, ...

System Details Statamic 3.3.37 Stillat/relationships 1.1.1 PHP: 8.1 Users in database local xampp dev environment

It is my understanding that it should be producing a related field of author in the books entry, and an array of related books in the author entry, I am at a bit of a loss as to where the integer is coming from?

Thanks.

JohnathonKoster commented 1 year ago

Should just need to update to 1.1.2 🙂