FabienPennequin / FPNTagBundle

This bundle allows to tag your Doctrine entities easily
http://knpbundles.com/FabienPennequin/FPNTagBundle
76 stars 50 forks source link

Doctrine query #30

Open akorti opened 10 years ago

akorti commented 10 years ago

Hello how can i do to join an entity to a specific tag in a doctrine query builder? I tried to do this $qb->select('s') ->from('MyBundle:Site', 's') ->leftJoin( 'MyBundle:Tagging', 't', \Doctrine\ORM\Query\Expr\Join::WITH, 't.resource_id = s.id' ) but I get an error message => MyBundle\Entity\Tagging has no field or association named resource_id.

Someone have any idea?

Thank you in advance.

gvoxel commented 10 years ago

Hey. Maybe we should get the tags using the method loadTagging ()?

lakiboy commented 10 years ago

Tagging functionality is separated from your models. There is no database (Doctrine) reference between your Entity and tagging facility. IOW you can't join tagging from your entity as you wanted, hence the error.

Instead you can do 2 things:

1) Use TagRepository::getResourceIdsForTag() - this will give back IDs for your entities you could use in your search query.

2) If you absolutely want a single query you can construct it with sub select. I already answered a similar question here - https://github.com/FabienPennequin/FPNTagBundle/issues/28