-
-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synced model with cast on creation not work #1273
Comments
Please include more clear examples for reproducing the behavior. |
Laravel getAttributes doesn't cast the attribute, so it can't create a model with the right field. My workflow is: In tenant the user has the right casted field, because laravel create it. User is synced with CentralUser. When I create a User, your package create a CentralUser and viceversa. Using getAttributes, retrieve the field as text and not cast it to array. Let me know if I was clear now. However, is the behaviour of getAttributes that make it happens. |
To no lose hidden attribute $event->model->makeVisible($event->model->getHidden()); // <------------------
$centralModel = $event->model->getCentralModelName()::create($event->model->attributesToArray());
event(new SyncedResourceChangedInForeignDatabase($event->model, null)); |
It's likely this was fixed in v4. I'll confirm that later. We generally won't change resource syncing behavior in v3 even for small bugs since most fixes require significant breaking changes. |
I have override the method. For me was a big bug because broke my login. When v4 will be released? |
Bug description
Creation of synced model not work properly.
The cast field not works by design using getAttributes.
Use unsetRelations()->attributesToArray()
UpdateSyncedResource.php
Before
After
Steps to reproduce
try to create a synced model with casted field like array
Expected behavior
During creation of synced mode, the casted field has to keep casted
Laravel version
11.35.1
stancl/tenancy version
3.8.5
The text was updated successfully, but these errors were encountered: