mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-3234: Empty properties when filtering collections #4002
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 (Jul 30, 2014).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user diogo.domanski:
I'm facing some troubles when filtering an entity association (ArrayCollection) by using Criteria.
The scenario is the following: I have 3 entities:
The problem is that whenever the Stage::getFieldWorkers() method is invoked, the list of associated field workers is returned correctly, however if I try to retrieve the respective user of any field worker, it is NULL.
For example:
Another example would be if I try to call $stageEntity->toArray() (because it does the same thing as show above).
The database tables are as following:
After hours trying to understand what was wrong, I decided to make a test and modify the Stage::getFieldWorkers() method by removing the filtering Criteria:
By simply doing that, the getUser() method started to return an entity of type User (as expected).
I am not a Doctrine ORM expert, but there seems to be something wrong with ArrayCollection filtering (matching() method)
@doctrinebot commented on GitHub (Jul 30, 2014):
Comment created by diogo.domanski:
The same problem occurs with QueryBuilder. For example:
If I try to iterate over the result of StageRepository::findByFieldWorkerId() and call toArray() of any element, I get the same error. I've even tried to remove the inner join with User entity from query:
@doctrinebot commented on GitHub (Jul 30, 2014):
Comment created by @ocramius:
I suspect that something is wrong in your mappings then...
@doctrinebot commented on GitHub (Jul 31, 2014):
Comment created by diogo.domanski:
Hi Marco,
The mappings are shown above. The only thing I did was to omit some entities/tables properties/columns that don't have to see with the associations - except the field worker (table and Entity) and stage_field_worker table, that are fully presented.
Maybe is important to notice that the field_worker table has only one column (user_id) that is primary key and foreign key (referencing user.id).
Thanks for you support
@doctrinebot commented on GitHub (Jul 31, 2014):
Comment created by @ocramius:
[~diogo.domanski] we can't debug this as it is. We'd need a functional test case to be added to
0650bb954f/tests/Doctrine/Tests/ORM/Functional/Ticketfirst, in order to see the failure@doctrinebot commented on GitHub (Jul 31, 2014):
Comment created by diogo.domanski:
[~ocramius] is there any documentation (tutorial, instructions, guide, etc) that I can use to learn how to write the functional test cases that I need?
@doctrinebot commented on GitHub (Jul 31, 2014):
Comment created by @ocramius:
[~diogo.domanski] you need to look at the existing ones.
For running the test suite:
@doctrinebot commented on GitHub (Aug 20, 2014):
Comment created by diogo.domanski:
I solved the problem by removing the property $id from FieldWorker entity and add annotation @ORM\Id to $user property (in this same entity).
I didn't understand why the previous definition of FieldWorker entity was not working. I have another similar relationship scenario, between 3 different entities, and the error does not occur.
Thanks to all for the support
@doctrinebot commented on GitHub (Oct 19, 2014):
Issue was closed with resolution "Cannot Reproduce"