mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Doctrine SINGLE TABLE inheritance #4937
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ghost on GitHub (Dec 15, 2015).
Originally assigned to: @Ocramius on GitHub.
/** * @ORM\Column(type="integer", options={"default" = 0}) */ private $soft_views_yesterday = 0; /** * @ORM\Column(type="integer", nullable=FALSE, options={"default" = 0}) */ private $views_yesterday = 0; /** * @ORM\Column(type="integer", options={"default" = 0}) */ private $flag_growth = 0;Hi I have extended an entity and it seems every field that I pass into it whether I add the nullable tag still keeps it as allow null in the table structure.
Also on a side note when I am creating the entity I use the generated setter and it ignore the value I change it to.
Any help will be amazing as this is making me fall into the deep depths of doctrine depression.
Thanks,
Harry
@DHager commented on GitHub (Dec 15, 2015):
I assume that means there are two PHP classes that each contain Doctrine metadata (e.g. annotations) What do the parent/child both look like?
@ghost commented on GitHub (Dec 15, 2015):
Here are the two entities
This is the base one:
And this is the one that extends it:
The base entity is in a package and then the extended one is in the website bundle - just to clear up the name space differences 👍
Thanks!!
@kitsunet commented on GitHub (Dec 15, 2015):
In a single table inheritance you cannot extend with non nullable fields because any other inherited class that doesn't have the fields would fail to persist.
@DHager commented on GitHub (Dec 15, 2015):
@HarryWiseman There's something wrong with your code-paste. I'm only seeing the tail ends of each class with all the methods, not the important part which is the class-declaration and the variable-declarations.
As @kitsunet mentions, you may be running afoul of:
@Ocramius commented on GitHub (Dec 16, 2015):
Fixed the pasted bit.
@Ocramius commented on GitHub (Dec 16, 2015):
@kitsunet in a single table inheritance, all fields in child tables MUST be nullable, as they will be only filled for sub-type records. If they were non-nullable, you wouldn't be able to insert any data for a parent type (or any sibling type).
Also, PLEASE REDUCE code snippets when pasting them: it took me more to read and find the problem in the code examples than to actually reach the conclusion.
This is expected behavior, closing.
@kitsunet commented on GitHub (Dec 16, 2015):
@HarryWiseman I think the above mention of me was in fact for you...
@Ocramius commented on GitHub (Dec 16, 2015):
@kitsunet sorry!
@kitsunet commented on GitHub (Dec 16, 2015):
@Ocramius No worries :)