mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Query builder is using wrong id with MEMBER OF #5401
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 @bettinz on GitHub (Feb 1, 2017).
Hello, I've a problem with forms in symfony, and I can't understand if it's related to doctrine or symfony.
I've also opened an issue with symfony in order to understand where is the problem.
I have 2 entities: user and stable. I've a table called user_for_stable with user_id and stable_id
So I've created this simple form called "CowType":
In the controller I've:
But the generated query is wrong:
it should be
in stable entity I've:
This code is working as expected:
the generated sql is
Can you help me? Thanks
@lcobucci commented on GitHub (Feb 1, 2017):
@bettinz can you reproduce this in a test case? You can see examples here:
c816d375e8/tests/Doctrine/Tests/ORM/Functional/Ticket@Ocramius commented on GitHub (Feb 1, 2017):
@bettinz I can't understand the issue: please reduce it:
What we basically need is:
@bettinz commented on GitHub (Feb 1, 2017):
Hello first of all, thank for the replies, I haven't created any test so far, so please understand I've to study on how to do that 😄
Basically I've that entities:
What I need to check is if a user is in the list of users for that stable.
So I've used the operator MEMBER OF: is the current user MEMBER OF stable.users?
The generated sql is:
but is wrong on that part:
because need to be
and then
@lcobucci commented on GitHub (Feb 1, 2017):
@bettinz it's not REALLY HARD to create tests, try to do the following:
c816d375e8/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6141Test.php$this->_em->getRepository(Entity::class)->createQueryBuilder('u')->where(':userobj MEMBER OF u.users')->setParameter("userobj", $options['userObj']);)@bettinz commented on GitHub (Feb 1, 2017):
Hello, I've created a simple project in symfony with the problem here:
https://github.com/bettinz/doctrineTest
@lcobucci commented on GitHub (Feb 1, 2017):
@bettinz thanks but it doesn't really help since it doesn't isolate the ORM... could you please try to send the test as instructed?
@bettinz commented on GitHub (Feb 1, 2017):
Honestly I tried without results; I'm still learning symfony and doctrine and test is something really new. I've created this simple project with fixtures in order to help. I hope someone can help me and create a simple test based on my simple project 😃
@Ocramius commented on GitHub (Feb 1, 2017):
See https://github.com/doctrine/doctrine2/blob/master/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
An example project is not something we can work with: the "learning how" bit goes both ways
@bettinz commented on GitHub (Feb 1, 2017):
I don't know if it help or not, but I'm trying to reply your third post:
DQL:
Generated sql:
correct sql
I've only found documentations on tests for doctrine 1.4. I'm sorry if I can't be useful, I'm really trying to create a test
@Ocramius commented on GitHub (Feb 2, 2017):
That's clear now, thanks! We now need to figure out if the problem is in
the mapping definitions or in the DQL transformation
On 2 Feb 2017 00:31, "bettinz" notifications@github.com wrote:
@HeahDude commented on GitHub (Feb 8, 2017):
Hey @bettinz, sorry for the late reply. Maybe you just need to handle
UserandStableas entity in your code.Unless you have a specific need for it, you'd better not have an object in your code to materialize this relation, https://github.com/bettinz/doctrineTest/blob/master/src/AppBundle/Entity/UserForStable.php#L13 should not be needed.
With only this mapping, and without creating a
$usersproperty in theStableclass, the database would still create a join table https://doctrine-orm.readthedocs.io/en/latest/reference/association-mapping.html#many-to-many-unidirectional, and it's up to you to choose to have a bi-directionnal relation.@bettinz commented on GitHub (Feb 8, 2017):
Hello @HeahDude , I usually prefer a "Many-To-One<->One-To-Many" relation with an entity in the middle as explained here http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#many-to-many-unidirectional
In this particular case I also need some extra fields in the middle entity, and I think I can't do the work with a Many To Many.