mpociot / laravel-test-factory-helper

Generate Laravel test factories from your existing models
935 stars 87 forks source link

Support multi-database relationships #52

Closed iMusicJJ closed 1 year ago

iMusicJJ commented 4 years ago

Hi,

This PR is mainly created after a short patch allowed us to scratch our own itch. We have an old legacy database and a newer database which is our main datastore.

Some of our relationships are cross-database, and while this isn't traditional, it should now be supported with this patch.

jasonmccreary commented 4 years ago

Cool. I'll take a look at this as I've been meaning to revisit/update this repo.

iMusicJJ commented 4 years ago

Let me know if you need an example. We initially ran into the issue because our Test-Generator Shift failed to create any factories. Luckily it was a quick fix

jasonmccreary commented 4 years ago

Sure. Before/after examples are always good. Can just be a few lines.

iMusicJJ commented 4 years ago

I'll try to describe it here.

Basically it comes down to us establishing a new database a few years ago, along with some new internal systems.

The new database still needed a few of the legacy tables from the old database (which is still very much in use by the old system).

We made a new LegacyModel which they would extend, and they simply had another DB connection.

It looks something like this.

current.materials:

id item_id title
1 9874283 For
2 783245 Bar

legacy.items

id width height
9874283 50 20
783245 120 50

It's not ideal, but others might benefit from it.

It should be a pretty simple fix that just allows the package to use the fully qualified database table name.

I hope that makes sense?

If there's any problems, I can checkout an old commit and run it, to recreate the error.