I have two models: NoteItem
and TaskItem
. Both extends from AbstractStreamItem
:
abstract class AbstractCommentsItem
{
…
}
class CommentItem extends AbstractCommentsItem
{
…
}
class TaskItem extends AbstractCommentsItem
{
…
}
Now I want to get repository of both models in one getRepository
command.
Is it possible somehow? I thought about single table inheritance, but not sure if it's the right approach.
Yes, Single Table Inheritance is a valid solution here. You will be able to do:
$entityManager->getRepository(AbstractCommentsItem::class);
to get a single repository for all subtypes.
I'm actually doing that in my current project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.