1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 16:14:03 +00:00

Syncing resources fails when table structures differ

When syncing resources, this line $centralModel = $event->model->getCentralModelName()::create($event->model->getAttributes()); fails in two situations:

1. when there are column(s) in tenant table that are not in central table.
2. when there is already a row in central table with same id as the id generated while creating the model on tenant table(With ID i mean primary key which my differ from Global ID column).

With this change, only syncedAttributes will be used while creating the model on central table. unfortunately, with this we lose the ability to populate the row with default values and all required columns must be on $syncedAttributes, but is the only way I could get it to work.
This commit is contained in:
Elísio Leonardo 2021-06-26 15:34:32 +02:00 committed by GitHub
parent 1a5300ab4f
commit 0d423ecddd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,7 +60,7 @@ class UpdateSyncedResource extends QueueableListener
} else {
// If the resource doesn't exist at all in the central DB,we create
// the record with all attributes, not just the synced ones.
$centralModel = $event->model->getCentralModelName()::create($event->model->getAttributes());
$centralModel = $event->model->getCentralModelName()::create($syncedAttributes);
event(new SyncedResourceChangedInForeignDatabase($event->model, null));
}
});