DDC-2455: Setting classes in the entity manager #3079

Closed
opened 2026-01-22 14:11:42 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (May 16, 2013).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user pcastrotigre:

I am creating my own bundle in Sf2 which will be used for third libraries, but I need to provide some simple and complex queries from this.
For simple queries i have no problem because I set the repository with the class from the third library.
Something like this:

$this->repository = $this->em->getRepository($className);
$result = $this->repository
            ->createQueryBuilder("c")
            ->select('c, d, e')
            ->join("c.groups", "d")
            ->join("d.users", "e")
            ->where("e.id = :userId")
            ->setParameter("userId", $userId);

return $result->getQuery()->getResult();

But when I need complex queries i have to work with the Entity Manager instead of working with the Repository. So tables are named as MyBundle (Group), but not how the third library named (sf_group). As a consequence the SQL throws an error saying that my table does not exist.
This is how I am trying to retrieve:

$query = $this->em->createQuery("SELECT p FROM Groups p");

I sent the className as the entity to avoid this. Something like:

$query = $this->em->createQuery("SELECT p FROM ".$this->className." p");

However i need a lot of queries with JOINs, so i would have to change every entity name, which is not convenient.

What another way could I implemment this?

Thanks for your help.

Originally created by @doctrinebot on GitHub (May 16, 2013). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user pcastrotigre: I am creating my own bundle in Sf2 which will be used for third libraries, but I need to provide some simple and complex queries from this. For simple queries i have no problem because I set the repository with the class from the third library. Something like this: ``` $this->repository = $this->em->getRepository($className); $result = $this->repository ->createQueryBuilder("c") ->select('c, d, e') ->join("c.groups", "d") ->join("d.users", "e") ->where("e.id = :userId") ->setParameter("userId", $userId); return $result->getQuery()->getResult(); ``` But when I need complex queries i have to work with the Entity Manager instead of working with the Repository. So tables are named as MyBundle (Group), but not how the third library named (sf_group). As a consequence the SQL throws an error saying that my table does not exist. This is how I am trying to retrieve: ``` $query = $this->em->createQuery("SELECT p FROM Groups p"); ``` I sent the className as the entity to avoid this. Something like: ``` $query = $this->em->createQuery("SELECT p FROM ".$this->className." p"); ``` However i need a lot of queries with JOINs, so i would have to change every entity name, which is not convenient. What another way could I implemment this? Thanks for your help.
admin added the Bug label 2026-01-22 14:11:42 +01:00
admin closed this issue 2026-01-22 14:11:43 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 26, 2013):

Comment created by @beberlei:

This is a question for the mailinglist.

createQueryBuilder() and createQuery() have exactly the same functionality. Just a different API. You can do the same with both.

@doctrinebot commented on GitHub (May 26, 2013): Comment created by @beberlei: This is a question for the mailinglist. createQueryBuilder() and createQuery() have exactly the same functionality. Just a different API. You can do the same with both.
Author
Owner

@doctrinebot commented on GitHub (May 26, 2013):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (May 26, 2013): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3079