Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDC-1001: Join statement fails #1586

Closed
doctrinebot opened this issue Jan 24, 2011 · 5 comments
Closed

DDC-1001: Join statement fails #1586

doctrinebot opened this issue Jan 24, 2011 · 5 comments
Assignees
Labels

Comments

@doctrinebot
Copy link

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
Copy link
Author

Comment created by @beberlei:

It seems either your mapping files are wrong, can you post the mappings of RoomMember?

@doctrinebot
Copy link
Author

Comment created by rrafal@gmail.com:

I simplified my code to the following and run the test again:

/****

  • @entity

  • @table(name="user")
    /
    class User
    {
    /
    ***

    • @id
    • @GeneratedValue
    • @column(name="user_id", type="integer")
      */
      private $id;

    public function **construct() { }
    public function getId(){ return $this->id; }
    }

/****

  • @entity

  • @table(name="room_member")
    /
    class RoomMember {
    /
    ***

    • @id
    • @GeneratedValue
    • @column(name="room_member_id", type="integer")
      */
      private $id;

    /****

    • @manytoone(targetEntity="User")
    • @joincolumn(name="user_id", referencedColumnName="user_id")
      */
      private $user;

    public function **construct(User $user){
    $this->user = $user;
    }

    /****

    • User who belongs to room.
    • @return 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
Copy link
Author

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
Copy link
Author

Issue was closed with resolution "Invalid"

@doctrinebot
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants