Comments (7)
As I understand it doesn't support abstract base type at this moment.
from single-table-inheritance.
@a-komarev I'm not sure if this will help you, but after posting this message last year, I ended up writing a simplistic version myself. It's not fancy, but it worked for what I needed. https://github.com/oldtimeguitarguy/eloquent-single-table-inheritance
from single-table-inheritance.
Thanks for sharing your work @oldtimeguitarguy, but it doesn't work with abstract base class too :(
from single-table-inheritance.
@oldtimeguitarguy I'm as confused as @a-komarev as to how this is different :)
What is broken with abstract base classes? It's not an area I've explored much but it doesn't sound like it would be a terribly hard problem to fix. Do you have stack traces or failing test cases that you can attach so we can track this down?
from single-table-inheritance.
Itโs not really that different. I was just throwing an alternative into the mix. I was pretty adamant about having an abstract base class at first, but Eloquent donโt play that game. ;-)
In the end, I found the concrete base class to be more powerful anyway. You can make a request on behalf of the base class and it will return a collection of child classes, matched by their db definition.
from single-table-inheritance.
@bostanio you cannot instantiate abstract class. So if Base class is abstract there is no way to pass it to relation.
I think the only way to deal with it - provide factory class to relation which will decide which subclass should be instantiated.
from single-table-inheritance.
I'd like to be able to support it but its very painful given the Illuminate internals. The trade off isn't particularly worth it for the relatively simple cost of having non abstract classes
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.