mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-1001: Join statement fails #1247
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 (Jan 24, 2011).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user rrafal@gmail.com:
I tried to execute this DQL statement:
SELECT u FROM RoomMember m JOIN m.user u WHERE m.room = :roomId
It failed with this error:
class_parents(): object or string expected
Doctrine/ORM/Mapping/ClassMetadataFactory.php:222
Doctrine/ORM/Mapping/ClassMetadataFactory.php:245
Doctrine/ORM/Mapping/ClassMetadataFactory.php:169
Doctrine/ORM/EntityManager.php:247
Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:223
Doctrine/ORM/Internal/Hydration/ObjectHydrator.php:76
Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:98
Doctrine/ORM/AbstractQuery.php:527
I rewrite the query like this, and it works:
SELECT u FROM RoomMember m , User u WHERE m.user = u AND m.room = :roomId
Let me know if you need more information.
Rafal - rrafal@gmail.com
@doctrinebot commented on GitHub (Jan 25, 2011):
Comment created by @beberlei:
It seems either your mapping files are wrong, can you post the mappings of RoomMember?
@doctrinebot commented on GitHub (Jan 25, 2011):
Comment created by rrafal@gmail.com:
I simplified my code to the following and run the test again:
/****
@Entity
@Table(name="user")
/
class User
{
/***
*/
private $id;
public function **construct() { }
public function getId(){ return $this->id; }
}
/****
@Entity
@Table(name="room_member")
/
class RoomMember {
/***
*/
private $id;
/****
*/
private $user;
public function **construct(User $user){
$this->user = $user;
}
/****
*/
public function getUser(){
return $this->user;
}
}
$query = $this->em->createQuery('SELECT u FROM RoomMember m , User u WHERE m.user = u');
$query->execute();// No problem
$query = $this->em->createQuery('SELECT u FROM RoomMember m JOIN m.user u');
$query->execute();// Error
I also tried to recreated this problem using the repository version of doctrine. I created same entities in sandbox environment (doctrine2-orm/tools/sandbox). I'm getting a different error message:
PHP Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Semantical Error] line 0, col -1 near 'SELECT u FROM': Error: Cannot select entity through identification variables without choosing at least one root entity alias.' in doctrine2-orm/lib/Doctrine/ORM/Query/QueryException.php:47
Stack trace:
#0 doctrine2-orm/lib/Doctrine/ORM/Query/Parser.php(425): Doctrine\ORM\Query\QueryException::semanticalError('line 0, col -1 ...')
#1 doctrine2-orm/lib/Doctrine/ORM/Query/Parser.php(335): Doctrine\ORM\Query\Parser->semanticalError('Cannot select e...')
#2 doctrine2-orm/lib/Doctrine/ORM/Query/Parser.php(281): Doctrine\ORM\Query\Parser->assertSelectEntityRootAliasRequirement()
#3 doctrine2-orm/lib/Doctrine/ORM/Query.php(203): Doctrine\ORM\Query\Parser->parse()
#4 doctrine2-orm/lib/Doctrine/ORM/Query.php(223): Doctrine\ORM\Query->_parse()
#5 /home/rrafal/Develo in doctrine2-orm/lib/Doctrine/ORM/Query/QueryException.php on line 47
I'll attache my code from sandbox.
Thank you for help.
@doctrinebot commented on GitHub (Jan 26, 2011):
Comment created by @beberlei:
Ah yes, the query you want to do is not possible. I have only seen that now. You have to select the "m" if you have RoomMember in the FROM clause. That is what the exception in the sandbox is about. Are you using an older version of Doctrine (RC1 or less) for your project? The exception is realtively new
@doctrinebot commented on GitHub (Jan 26, 2011):
Issue was closed with resolution "Invalid"
@doctrinebot commented on GitHub (Jan 26, 2011):
Comment created by rrafal@gmail.com:
Ok, thanks for the explanation. I'll just used the alternative DQL, it works perfectly:
SELECT u FROM RoomMember m , User u WHERE m.user = u
I'm using doctrine ORM 2.0.0