CappY
CappY

Reputation: 1580

Doctrine Inheritance and MySQL Join Table Limit

I have a problem with 61 join table limit of mysql. I have 57+ different classes extending Base Class which contain association to comments, likes, tags. And MySQL is crashing when i get most commented. Doctrine has to join whole discriminator maps and comments itself and order by COUNT(comments).

Is there way to fix that ?

And is there another way to achieve comments for different types of entities without inheritance and copying same association all over again?

Here is sample schema of Entities. When I want to add new Entity Type with comments,likes I just extends BaseClass to receive these features.

enter image description here

Upvotes: 0

Views: 292

Answers (1)

Kevin Archer
Kevin Archer

Reputation: 171

If I understand correctly what you're trying to do is have many different entity types which can be commented on.

First thing to do would be to step back from Doctrine and thing about the simplest table structure you would need to accomplish this.

Something like this may suffice:

Comments

 _______________________
| id | type | entity_id |
 ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

It is nice in Doctrine to have bi-directional relationships in your base class for convenience but sometimes they are not the best choice. Maybe it would simplify your architecture to perform a query directly on the comments table by entity type and id.

You may also want to consider removing the Base class and having each entity be standalone.

Since a blog post can exist in a context where it does not have comments (on a blog that doesn't allow commenting for example) then $blog->getComments() wouldn't make much sense.

Making this change you could do something like this instead:

$comments = $commentsRepository->findCommentsForEntity($entity);
$commentsCount = count($comments);

and the repository could generate the needed query passing the entity as the entity_id parameter and setting the required comment type based on the entity type.

Upvotes: 0

Related Questions