I’m working on a project which has entities which have multiple bitmask columns. So for example my User entity has a column specialitiesBitmask. This bitmask will correlate to another table, for example, Specialty. If I wanted to do be able to do something like $user->getSpecialties() what is the best way to do this? I’d need to query Specialty table, and break down bitmask accordingly. However with Doctrine2 you don’t have access to the EntityManager.
I looked around for any solutions, but couldn’t find much. Looking at this you could use a listener to hook the postLoad event and get the EM that way, however that is pretty hacky and not clean.
The only other solution I could think of would be to create other services and do something like $userService->getSpecialtiesForUser($user); however that is going to also not be that clean/efficient as there are a number of columns which are bitmasked.
What do you think is the best way?
Create a
SpecialtyRepository, and implementgetByUser($user). You can find how to do so here and here.Then, to get the specialities of a user, you’d do:
$specialties = $em->getRepository('Specialty')->getByUser($user);