mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-244: Inheritance Breaks on Property-less Objects #300
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 @doctrinebot on GitHub (Jan 7, 2010).
Jira issue originally created by user mridgway:
I've tried several different methods to be able to achieve this without any success. I want to be able to map to objects that don't necessarily contain database properties.
Example:
In this example using JOINED as the InheritanceType, createSchema will execute without error but when I try to load a model of type Test, it says "Base table or view not found: 1146 Table 'db.test' doesn't exist".
If I try this with a SINGLE_TABLE InheritanceType on Block, I get "The table with name 'block' already exists." when executing createSchema (I assume because it sees Block twice as an entity super class).
We should be able to have classes that don't have any database properties inherit from classes that do without creating empty tables in the database.
Is there a way to do this?
@doctrinebot commented on GitHub (Jan 7, 2010):
Comment created by romanb:
Well, for DynamicBlock, just dont map it as an entity. Remove @Entity.
For Test, well, thats a special case I guess. I will set up a test when I find the time.
If no subclasses have any new persistent fields SINGLE_TABLE would indeed be the best thing to do. The error you report makes me curious. You get this on an empty database? Can you create a separate ticket for that one?
@doctrinebot commented on GitHub (Jan 7, 2010):
Comment created by romanb:
DDC-144 might be of interest to you, too.
@doctrinebot commented on GitHub (Jan 7, 2010):
Comment created by mridgway:
Hi Roman, thanks for the link, it looks like it's a very similar issue.
-When I remove @Entity from a DynamicBlock, I get "Class is not a valid entity or mapper super class" when I try to persist a Test object. This is probably because it doesn't see DynamicClass as an Entity even though it's a child of one.- Nevermind. I get the SQL issue when I try to load a Test. I'll create a new issue for this.
The SINGLE_TABLE example is on an empty table. I'll test it out with classes that DO have properties and see if that fixes it. I'll also create a new report for this.
@doctrinebot commented on GitHub (Jan 7, 2010):
Comment created by romanb:
To clarify what should currently work / not work:
http://trac.doctrine-project.org/browser/trunk/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC144Test.php
You can see there that DDC144Expression is not mapped at all and only two tables are generated.
An entity in class table inheritance (JOINED) that does not have any properties of its own is currently expected to get a table anyway if I remember correctly. That table would just have a primary key column that is linked to the parent. This is an area for possible improvement. If the class is abstract (and has no persistent fields) the extra table for that class can be easily avoided by not mapping that class at all, as seen in DDC-144.
Single table inheritance (SINGLE_TABLE) should not have any issues, whether subclasses have additional persistent fields or not. If there are issues with it, you need to create tickets for them.
Are you using the latest version from trunk or the last release point (alpha3)? DDC-144 is only fixed in trunk, so not in the alpha3 release.
Thanks for your help.
@doctrinebot commented on GitHub (Jan 7, 2010):
Comment created by romanb:
I attached a test case that works flawlessly, even though it creates the (arguably unnecessary) tables for the subclasses.
@doctrinebot commented on GitHub (Jan 8, 2010):
Comment created by mridgway:
The errors I was getting turned out to be a lingering discriminator-mapped class.
@doctrinebot commented on GitHub (Jan 8, 2010):
Issue was closed with resolution "Fixed"
@doctrinebot commented on GitHub (Dec 13, 2015):
Imported 1 attachments from Jira into https://gist.github.com/ffe321ef0b74272b3d11