Select column using DQL using EntityManager.select() method

111 views
Skip to first unread message

Rico Leuthold

unread,
Feb 20, 2011, 8:47:11 AM2/20/11
to flextrine
Hi,

I would like to get all the id's of an entity class.

This is the code I thought would be right:

_em.select("SELECT m.id FROM " + QueryUtil.getDQLClass( Box ) + " m ")
[...]

The query fails with errors:

[20-Feb-2011 14:32:59] PHP Warning: spl_object_hash() expects
parameter 1 to be object, array given in /Library/WebServer/micemeta/
php/lib/flextrine-0.7.3/web/lib/Flextrine/Tools/AssociationWalker.php
on line 59
[20-Feb-2011 14:32:59] PHP Warning: Attempt to assign property of non-
object in /Library/WebServer/micemeta/php/lib/flextrine-0.7.3/web/lib/
Flextrine/Tools/AssociationWalker.php on line 62
[20-Feb-2011 14:32:59] PHP Warning: get_class() expects parameter 1
to be object, array given in /Library/WebServer/micemeta/php/lib/
flextrine-0.7.3/web/lib/Flextrine/Tools/AssociationWalker.php on line
68
[20-Feb-2011 14:32:59] PHP Warning: class_parents() [<a
href='function.class-parents'>function.class-parents</a>]: object or
string expected in /Library/WebServer/micemeta/php/lib/doctrine-orm/
Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222
[20-Feb-2011 14:32:59] PHP Warning: array_reverse() expects parameter
1 to be array, boolean given in /Library/WebServer/micemeta/php/lib/
doctrine-orm/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222
[20-Feb-2011 14:32:59] PHP Warning: Invalid argument supplied for
foreach() in /Library/WebServer/micemeta/php/lib/doctrine-orm/Doctrine/
ORM/Mapping/ClassMetadataFactory.php on line 222

Running the query without the column specified, e.g. :

_em.select("SELECT m FROM " + QueryUtil.getDQLClass( Box ) + " m ")

... works.

Am I doing something wrong, or is this a limitation of flextrine?

Thanks
- rico


ccapndave

unread,
Feb 21, 2011, 9:03:02 AM2/21/11
to flextrine
Hey Rico,

At present it is only possible to select entities, not scalar values.
A workaround for this would be to implement the DQL query on the
server and use callRemoteMethod to execute it, as a remote method can
return any type.

However, are you sure that you want to be getting all the ids into the
Flex application rather than the boxes themselves, as this (usually)
defeats the purpose of having an ORM in the first place?

Dave

Dave Keen

unread,
Feb 21, 2011, 10:04:51 AM2/21/11
to flex...@googlegroups.com
Hey Rico,

Fair enough - there are definitely a few situations where direct access to the id are important, and it sounds like this is one of them :)  And yes - $this->em is the actual EntityManager created and used by the rest of the backend (in 0.8.* I think its created in Config.php).  So you can use $this->em directly in your remote methods.

Good luck!

Dave

On 21/02/2011 15:36, Rico Leuthold wrote:
Hi Dave,

I understand your objection. But in this case, the id's are needed in a dataProvider for a TextInput with an auto-completion feature. And since the entities are many and large, I wanted to load just the information needed.

Just a small follow up question. Is the $this->em EntityManager exactly the same as one created like $entityManager = \Doctrine\ORM\EntityManager::create($conn, $config, $evm); 
From the code - and my understanding - it should be the same. I just wanted to make sure before I'm trying to implement such a remote method.

Thank you again
- rico


On 21.02.2011, at 15:03, ccapndave wrote:

No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.872 / Virus Database: 271.1.1/3456 - Release Date: 02/20/11 20:34:00

Rico Leuthold

unread,
Feb 21, 2011, 9:36:27 AM2/21/11
to flex...@googlegroups.com
Hi Dave,

I understand your objection. But in this case, the id's are needed in a dataProvider for a TextInput with an auto-completion feature. And since the entities are many and large, I wanted to load just the information needed.

Just a small follow up question. Is the $this->em EntityManager exactly the same as one created like $entityManager = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
From the code - and my understanding - it should be the same. I just wanted to make sure before I'm trying to implement such a remote method.

Thank you again
- rico


On 21.02.2011, at 15:03, ccapndave wrote:

ccapndave

unread,
Mar 2, 2011, 5:49:26 AM3/2/11
to flextrine
Hey Rico,

This feature has been implemented in Flextrine 0.9 using hydration
modes in queries.

Check the 'Scalar queries' section of
https://github.com/ccapndave/flextrine/wiki/Complex-queries-and-DQL
for details.

Dave

Rico Leuthold

unread,
Mar 2, 2011, 12:04:04 PM3/2/11
to flex...@googlegroups.com
Hi Dave,

Thank you for the implementation and information.

- rico

Reply all
Reply to author
Forward
0 new messages