mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-908: Foreign key column not available when using EntityRepository::findBy() #1127
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Dec 1, 2010).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user rrafal@gmail.com:
I have 2 tables: Message and User. Message has a foreign key (user_id) to User table. I defined it as a many-to-one unidirectional relationship. Message knows about its user, but user doesn't know about its messages. I want to select all messages with some user_id. I can do this with DQL Query but not with ORM EntityRepository.
When I call EntityRepository::getBy() I receive Doctrine\ORM\ORMException: Unrecognized field: user. Example:
$em->getRepository('Message')->findBy( array("user" => 5) );
I do expect to be able to do the above. It would be much easier then writing DQL quires. It would be convenient if I could to this too:
$user = $em->getRepository('user')->find(5);
$em->getRepository('Message')->findBy( array("user" => $user) );
For this simple example, I could change the relationship to bi-directional and use User entity. However, the requests I write in practice are more complex. They involve filtering results on other fields and pagination.