ryangjchandler / orbit

A flat-file database driver for Eloquent. πŸ—„
MIT License
872 stars 39 forks source link

Empty many to many relationships cause an exception #116

Open johncarter- opened 2 years ago

johncarter- commented 2 years ago

When accessing empty model many to many relationships you get a SQLSTATE[HY000]: General error: 1 no such table: the_pivot_table_name exception.

How to replicate

  1. Clone https://github.com/johncarter-/laravel-orbit-many-to-many

  2. Switch to the issue/many-to-many-no-such-table branch.

  3. Run php artisan test --filter it_can_handle_empty_many_to_many_relationships tests/Feature/OrbitalManyToManyTest.php

johncarter- commented 2 years ago

If you create then delete a pivot model to sort of "initialise" the "table"/directory it works. See the follow up test in that branch.

I took a bit of source dive 🀿, but after a while trying to figure it out I didn't know my arse from my elbow. πŸ€·β€β™‚οΈ

ryangjchandler commented 2 years ago

@johncarter- Yeah, the codebase is a bit messy right now. My 2.x branch is much cleaner, I think. This might be something I put on hold fixing until then though, it'll probably be a couple of weeks.

Do you need this functionality for a project right now?

johncarter- commented 2 years ago

Oh I didn't mean there was anything wrong with your code 😯 I just meant I was in over my head.

I can use the create and delete workaround for now, no pressure at allπŸ‘Œ

ryangjchandler commented 2 years ago

@johncarter- Sweet!