Search code examples
phpdoctrine-ormdoctrinenette

Doctrine many-to-many join without association


Currently I'm working on doctrine module for favorites which can be reusable in any project and for any entity.

However there is problem with JOINs. I followed this article about dynamic mappings and it works great.. Well almost.

I've got User, Article and FavoriteItem entities, where Article entity can be added to favorites. Probably link to that github project with readme would be better (link).

The problem is mainly in that method which should return FavoriteItem by User and IFavoritableEntity, which in our example will be Article. As you can see, that method uses native query, but is it possible to use DQL? I know that I would have to use join to table without association, but it seems that doctrine can do that just for one-to-many/many-to-one associations.. I'm right? Or is there any other way how to do that in DQL?

Also do you think there is any way at all how to select in one query (DQL) all IFavoritableEntities by one User? I just can't imagine any.

Thank you


Solution

  • So I found other option which is add possibility to extend FavoriteItem entity where I'm able to add field with association to eg. Article::favorites field.