Coder Social home page Coder Social logo

Comments (5)

wtfz avatar wtfz commented on July 24, 2024 1

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.

jonspalmer avatar jonspalmer commented on July 24, 2024

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.

sylvainma avatar sylvainma commented on July 24, 2024

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.

jonspalmer avatar jonspalmer commented on July 24, 2024

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.

kentdahl avatar kentdahl commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.