eloquent-driver icon indicating copy to clipboard operation
eloquent-driver copied to clipboard

Undefined relationship after upgrade to statamic 3.3

Open Micke-Nilsson opened this issue 2 years ago • 6 comments

When I'm visiting /api/collections/{collection}/entries I'm getting "Call to undefined relationship [author] on model [Statamic\Eloquent\Entries\UuidEntryModel]" after upgrade to statamic 3.3

Micke-Nilsson avatar Apr 04 '22 06:04 Micke-Nilsson

After upgrading to Statamic 3.3 I'm experiencing the same where /entries is throwing a RelationNotFoundException, stack trace is here: https://flareapp.io/share/o7AKb1bm#F68

My setup is using the database instead files.

djmenkveld avatar Apr 26 '22 17:04 djmenkveld

Have you tried the new PR branch to see if that would help? https://github.com/statamic/eloquent-driver/pull/42

jackmcdade avatar Apr 26 '22 18:04 jackmcdade

I tried the new PR but it still doesen't work for me. But i found the commit that is causing the problem. https://github.com/statamic/cms/commit/ac70772990dccf560e10dcbdad6495dcc1518840#diff-919d52f8a749cfea24664e41c5b20b5a74117db74af777f9771f755b0b5fc0a5

In src/Http/Controllers/API/CollectionEntriesController.php

return app(EntryResource::class)::collection(
      $this->filterSortAndPaginate($collection->queryEntries()->with($with))
);

If i remove the "->with($with)" like below it works

return app(EntryResource::class)::collection(
      $this->filterSortAndPaginate($collection->queryEntries())
);

Hope that helps //Thanks

Micke-Nilsson avatar Apr 27 '22 08:04 Micke-Nilsson

I also tried the PR, did not resolve it.

djmenkveld avatar May 03 '22 14:05 djmenkveld

@Micke-Nilsson how are you storing users (eloquent or flat file)? I've pushed up a commit here that should work if its eloquent: https://github.com/statamic/eloquent-driver/pull/42/commits/ffb59d4a3bf28102a238271ba3a9e869f70c62cd

Im not happy with it as a long term solution as it doesnt account for when users might be using flat files but it should get over your issue.

ryanmitchell avatar May 06 '22 08:05 ryanmitchell

Thank you for your response. I do store my users in eloquent so your workaround works for me. Thanks

Micke-Nilsson avatar May 06 '22 11:05 Micke-Nilsson

Now that v1 has been released I think you can close this issue?

ryanmitchell avatar Sep 05 '22 06:09 ryanmitchell

v1 solves the problem with the author relationship.

But if you for example create a news collection and a category taxonomie and then add the category to the news blueprint you will still encounter the same problem if you don't manually add the relationship to the Statamic\Eloquent\Entries\EntryModel

Micke-Nilsson avatar Sep 05 '22 13:09 Micke-Nilsson

@Micke-Nilsson can you pull together a sample repository that shows the issue so I can work on a fix?

ryanmitchell avatar Sep 05 '22 13:09 ryanmitchell

Of course I can do that tomorrow

Micke-Nilsson avatar Sep 05 '22 13:09 Micke-Nilsson

@ryanmitchell I agree with @Micke-Nilsson it's also not resolved in my case, if you want I can give you access to my repo, please share your gitlab username

djmenkveld avatar Sep 05 '22 13:09 djmenkveld

@djmenkveld sure, I just signed up, ryanmitchell1

ryanmitchell avatar Sep 05 '22 15:09 ryanmitchell

@ryanmitchell I've just invited you, my setup is a bit different, but you'll figure it out to run it. So, I'm stuck at Statamic v3.3.11 and did not upgrade after. I can't completely recall what I did 1.5 years ago, but I'm also referring from a collection > fieldset > taxonomy > blueprint, since I did not want to repeat myself.

djmenkveld avatar Sep 05 '22 15:09 djmenkveld

@djmenkveld I'm in the project but cant see any code - are you sure my permissions are correct? Can you also ensure the data is included? It would be useful to get clear steps to reproduce the issue to minimise the time to reproduction.

ryanmitchell avatar Sep 05 '22 15:09 ryanmitchell

@ryanmitchell I've upgraded your role from guest to developer. Once running, you should create a test post and you'll able to reproduce it.

djmenkveld avatar Sep 05 '22 15:09 djmenkveld

@Micke-Nilsson any update on a sample repository?

ryanmitchell avatar Sep 07 '22 10:09 ryanmitchell

Yes i have created a repository with instructions to reproduce the error https://github.com/Micke-Nilsson/statamic_issue

Micke-Nilsson avatar Sep 07 '22 12:09 Micke-Nilsson

Wonderful, that was a great sample repository, thank you for the effort.

Fix here: https://github.com/statamic/eloquent-driver/pull/59

ryanmitchell avatar Sep 07 '22 13:09 ryanmitchell

No problem, and thank you for your work

Micke-Nilsson avatar Sep 07 '22 14:09 Micke-Nilsson

@Micke-Nilsson With help of @ryanmitchell I managed to resolve my issue, it works really good.

djmenkveld avatar Sep 07 '22 15:09 djmenkveld

@ryanmitchell I have also verfied that it works, should i close this now?

Micke-Nilsson avatar Sep 08 '22 05:09 Micke-Nilsson

No its ok, it will get closed when it merges.

ryanmitchell avatar Sep 08 '22 05:09 ryanmitchell

Ok thanks a lot for the fix

Micke-Nilsson avatar Sep 08 '22 05:09 Micke-Nilsson

Yes it looks like it

Micke-Nilsson avatar Sep 14 '22 08:09 Micke-Nilsson

@Micke-Nilsson I ended up deleting the comment because I found out it was the same. Fixed manually for now, and awaiting the merge :)

espenlg avatar Sep 14 '22 08:09 espenlg