Doctrine Query Class Not in Entity Directory
Asked Answered
O

1

2

My Entity directory for my bundle is getting quite large. I'd like to be able to group my classes into sub-directories. For example, all forum related classes in Entity/Forum/. I've been able to do this relatively successfully, but I don't know how to do a doctrine query now.

The following doesn't work.

SELECT fp
FROM AcmeMainBundle:ForumPost fp
WHERE 1

How do I query an entity not directly in the Entity Folder?

Outsert answered 10/1, 2014 at 19:0 Comment(7)
Doctrine entities need to be in their own unique file. class User {} in User.php (or however you name it)Marthamarthe
Each entity would still be in its own unique file. I am just trying to add sub-directories to the Entity folder so it could be more organized. Or is that wrong and I should just keep all entities directly in the entity folder? (I realize now that I worded it incorrectly. I'll fix that now in the original post)Outsert
AcmeMainBundle:Forum/PostEldenelder
@Cerad, I get the error: "Class Acme\MainBundle\Entity\ForumPost does not exist" when I do $em->createQuery('SELECT f FROM AcmeMainBundle:Forum\ForumPost')->getResult();Outsert
Forward slash, not backslashEldenelder
@Cerad, when I do: 'SELECT f FROM AcmeMainBundle:Forum/ForumPost f', I get: "[Semantical Error] line 0, col 41 near 'AcmeMainBundle:Forum/ForumPost': Error: Class 'Acme\MainBundle\Entity\Forum' is not defined."Outsert
I suppose you could try AcmeMainBundle:Forum\\ForumPost (two back slashes).Eldenelder
Y
3
SELECT fp
FROM AcmeMainBundle:Forum\ForumPost fp
WHERE 1

This will work as long as you have changed the namespace of the entities you are moving to a seperate folder, for example Acme\MainBundle\Entity\Forum\ForumPost

Yonatan answered 10/1, 2014 at 19:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.