Coder Social home page Coder Social logo

Model subclass using SingleTableInheritanceTrait returns model indicated by parent's $singleTableSubclasses? about single-table-inheritance HOT 4 CLOSED

jonspalmer avatar jonspalmer commented on July 24, 2024
Model subclass using SingleTableInheritanceTrait returns model indicated by parent's $singleTableSubclasses?

from single-table-inheritance.

Comments (4)

jonspalmer avatar jonspalmer commented on July 24, 2024

My guess is that you haven't set $singleTableType correctly in all the subclasses. It needs to be unique for every subclass. For example If UserRole1 and API\UserRole1 shared the same value then its likely that you get the behavior you describe. A little hard to tell without more of the details.

from single-table-inheritance.

domhnallw avatar domhnallw commented on July 24, 2024

@bostanio : Yep, I do have the same $singleTableType in (for example) UserRole1 and API\UserRole1 - I was doing that entirely on purpose. Basically, for each UserRole<n> there's an API\UserRole<n> which adds some extra bits used when rendering the data in those models to JSON for return as part of this API I'm building. But for all intents and purposes they're the same class, and should refer to the same model.

What I was hoping for was if I attempt to invoke MyNamespace\API\Models\User::find(...), then I should get a subclass in the MyNamespace\API\Models\ namespace, and similarly if I invoke MyNamespace\Models\User::find(...) that it should return a subclass in the MyNamespace\Models namespace. What you're saying suggests that's not feasible, at least the way I'm doing things now, is that right?

from single-table-inheritance.

domhnallw avatar domhnallw commented on July 24, 2024

For clarity, I have exactly six subclasses as shown in the example. For each of these subclasses, MyNamespace\Models\UserRole<n> is subclassed as MyNamespace\API\Models\UserRole<n>, adding some methods and such but is otherwise the same model...

from single-table-inheritance.

domhnallw avatar domhnallw commented on July 24, 2024

Giving up on the idea of subclassing the models, thanks for the help!

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.