mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-144: Class table inheritance: Attempt to insert an entity class that does not add any properties to the class hierarchy fails. #178
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 (Nov 13, 2009).
Jira issue originally created by user reinier.kip:
When using class table inheritance, insertion of an entity class that does not add any properties to the class hierarchy (e.g. when it only (re)implements a method) fails.
My case is more or less like this:
FlowElement { $property; }
abstract Expression extends FlowElement { abstract method(); }
Operand extends Expression { $moreProperties; method(); }
When storing an instance of Operand, Doctrine does not store a record for Expression into its table (it does prepare a statement for this):
@doctrinebot commented on GitHub (Nov 13, 2009):
Comment created by reinier.kip:
This issue is solved when I add a property to Expression.
@doctrinebot commented on GitHub (Dec 17, 2009):
Comment created by romanb:
In that particular case, since Expression is abstract and can not be instantiated, wouldnt it make sense to just not map it? There would be just 2 tables then.
This works fine for me:
The story is a bit different if the class is instantiable (not abstract), i.e. if you want to do sth like this:
Even though it might be arguable whether that makes a lot of sense to map that class to a table just to do that.
Whats your opinion?
@doctrinebot commented on GitHub (Dec 17, 2009):
Comment created by romanb:
Not all classes in a hierarchy must be mapped, maybe you didnt know that. There can be transient or mapped superclasses in the middle of a mapped hierarchy.
@doctrinebot commented on GitHub (Dec 17, 2009):
Comment created by reinier.kip:
That makes sense. I can't imagine I wouldn't have tried it back then. Your case reflects the case I have and works, so it seems this is not a bug.
I think you're right about mapping a class that only has methods. If a class offers only methods, but has no state whatsoever, it doesn't make sense to persist it.
But if maybe - in some kind of weird edge case - someone would want to do that, would this 'feature' greatly impact performance (aside additional tables/records in the database) or greatly complicate the code? If this is merely the case of changing one line here and there (not saying that could not impact performance), this case would be possible, but not recommended.
Hope I make sense...
@doctrinebot commented on GitHub (Dec 17, 2009):
Comment created by romanb:
I think this should be possible. The issue mainly is that since the class has no fields on its own the changeset is currently empty during persisting and thus the table gets no insert. I dont know yet how hard it is to solve this but it should be solved at some point. But as this is certainly not critical I've moved down the priority a bit. I hope you're ok with that.
@doctrinebot commented on GitHub (Dec 18, 2009):
Comment created by reinier.kip:
I agree.
@doctrinebot commented on GitHub (Dec 18, 2009):
Comment created by romanb:
It was in my way. Should be fixed now.
@doctrinebot commented on GitHub (Dec 18, 2009):
Issue was closed with resolution "Fixed"