Comments (5)
I would like to add a workaround for others who have the same issue. You can use saveQuietly()
to save the model without dispatching any event (skip saving
method in the package observer). However, you need to manually re-update the updated_at (or other column other than single table column) using new instance to dispatch the saving
event back for other observer.
$instance = Model::find($id);
$instance->type = '\Other\Type\Class';
$instance->saveQuietly();
$newInstance = Model::find($id);
$newInstance->update['updated_at' => now()]; // manually update to trigger other observer
In my use case, I used the subclass for historical record in my approval process. When new record type approved, it will switched to current type and previous current type will switched to historical type.
from single-table-inheritance.
That isn't really how the plugin works. The type column is infer from the Class of the Model object. What is the use case for trying to change it like this?
from single-table-inheritance.
I have one table users
et I use Nanigans/single-table-inheritance on it to host two models: Users
and Members
. I have the column type
to set which class a row belongs to (user
or member
).
I want to convert some rows from model User to Member (when a user gets advanced permissions on my application). So, I was thinking about changing the type
column directly for that, from user
to member
.
So you think I am using Nanigans/single-table-inheritance in a wrong way?
from single-table-inheritance.
If you have a User that you want to turn into a Member I think you'd want to create and Member model from the User model with the same properties and importantly the same id and then save that back.
from single-table-inheritance.
Since I ran into the same kind of issue, I'd just like to note that I ended up using the global update functionality of Eloquent instead. Something like:
Model::where('id', '=', $id)->update(['type' => 'other']);
This seems to work well so far.
from single-table-inheritance.
Related Issues (20)
- "Field 'type' doesn't have a default value" when saving a model HOT 3
- Update Readme HOT 1
- One record two types. HOT 3
- Can we set the type of model using the base model? HOT 5
- hasMany relation doesn't work for parent class
- Can't create a new record directly form the base class HOT 10
- Broken link in README - Mark Smith's website is gone HOT 1
- Laravel 5.7 Support HOT 6
- Type is not inserted when using Laravel factories HOT 1
- Travis Builds are failing HOT 2
- Laravel 5.8 support
- Support the Eloquent `retrieved` event HOT 1
- Cannot insert record HOT 6
- V0.8.6 causes incorrect attributes to be set HOT 11
- Laravel 6.0 support HOT 1
- Eager loading child model relationship HOT 2
- Enhence performance when querying root model of subclasses HOT 5
- PHP hangs when parent and child inheritance is not setted properly. HOT 3
- `newFromBuilder` does not maintain mutated attributes HOT 2
- onlyTrashed()->forceDelete() seems to lose the SingleTableInheritance scope, deletes way more than intended HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from single-table-inheritance.