DDC-908: Foreign key column not available when using EntityRepository::findBy() #1127

Open
opened 2026-01-22 13:03:04 +01:00 by admin · 0 comments
Owner

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.

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.
admin added the Bug label 2026-01-22 13:03:04 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1127