[Question] Is this kind of inheritance possible? #5434

Closed
opened 2026-01-22 15:07:43 +01:00 by admin · 1 comment
Owner

Originally created by @valepu on GitHub (Feb 27, 2017).

Originally assigned to: @Ocramius on GitHub.

I'm not sure how to call it, but i have a situation where rows in one table provide default values for rows into another table which can override them.
I have asked this on Stackoverflow but got no answer: http://stackoverflow.com/questions/42432689/extend-doctrine-2-model-with-new-values-for-fields

base_item

    Id | val1 | val2 | val3
    -----------------------
    1  |  a   |  b   |  c

item

    Id | base | val1 | val2 | val4
    -------------------------------
    3  |  1   |   z  | NULL | d

the base column is a foreign key to base_item.
I'd like to create a model where item's class extends base_item and if the same field is declared in both tables then it behaves this way:

If item's value is null then use base_item's one (in this example item.val2 is "b"), otherwise use item's value (in this example item.val1 is "z").

So, i was wondering if this kind of behavior is natively supported by Doctrine (or some extension) using some kind of inheritance or i just have to manually implement it in my model

Originally created by @valepu on GitHub (Feb 27, 2017). Originally assigned to: @Ocramius on GitHub. I'm not sure how to call it, but i have a situation where rows in one table provide default values for rows into another table which can override them. I have asked this on Stackoverflow but got no answer: http://stackoverflow.com/questions/42432689/extend-doctrine-2-model-with-new-values-for-fields > base_item > > ``` > Id | val1 | val2 | val3 > ----------------------- > 1 | a | b | c > ``` > > item > > ``` > Id | base | val1 | val2 | val4 > ------------------------------- > 3 | 1 | z | NULL | d > ``` > > > the `base` column is a foreign key to `base_item`. > I'd like to create a model where item's class extends base_item and if the same field is declared in both tables then it behaves this way: > > If item's value is null then use base_item's one (in this example `item.val2` is "b"), otherwise use item's value (in this example `item.val1` is "z"). > So, i was wondering if this kind of behavior is natively supported by Doctrine (or some extension) using some kind of inheritance or i just have to manually implement it in my model
admin added the Won't FixQuestion labels 2026-01-22 15:07:43 +01:00
admin closed this issue 2026-01-22 15:07:43 +01:00
Author
Owner

@Ocramius commented on GitHub (Feb 27, 2017):

Not supported: you will most probably need a prePersist or preUpdate listener to do that manually.

Closing as wontfix

@Ocramius commented on GitHub (Feb 27, 2017): Not supported: you will most probably need a `prePersist` or `preUpdate` listener to do that manually. Closing as `wontfix`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5434