I’m currently working on a generic voting bundle for Symfony2, but have stumbled into either a limitation of Doctrine2, or my own understanding of its capabilities.
In this bundle, there is only one Vote entity and it has a one-many relationship with n other objects. I know how I would do this if I had plain SQL (below), but is there something similar I can do to the following in Doctrine2? If not, can you recommend alternative solutions for me to investigate?
CREATE TABLE votes (
vote_id int unsigned not null auto_increment,
target_id int unsigned not null,
target_class varchar(64) not null,
vote_value tinyint(1) not null default 0,
PRIMARY KEY (vote_id)
);
CREATE TABLE voteable_entity_a (
-- whatever columns
);
CREATE TABLE voteable_entity_b (
-- whatever columns
);
I noticed there is Single-Table Inheritance, where I can use a discriminator column, but that is purposed towards having multiple objects based on the highest Vote class. This isn’t quite what I want.
Worst comes to worst, how janky is it to fallback to just using QueryBuilder for everything?
This is is not really supported, i had similar feature requests before but it is rather tricky to support this without exposing the details to the domain model. The following workaround is currently used by Typo3:
http://git.typo3.org/FLOW3/Packages/TYPO3CR.git?a=blob;f=Classes/Domain/Model/ContentObjectProxy.php;h=34f642400c714e16df86f4373bae3e6ca1349320;hb=31de0404ca25c5036e4d4cfd9f9dc55878902afe