Multiple belongsToMany

Is there a (simple) way to have multiple belongsToMany associations ?

The goal is to tag everything.

So, I have a Tags table and would like it to be associated with Articles, Categories, Images etc.

There used to be a tagEverything (I don’t remember the name exactly) plugin but it was cake 2 only.

You can add as many belongsToMany associations as you see fit. Or did you mean a single association that pulls in all related entities of any type?

Yes, a single association.
I just want to be able to tag any content, whatever type it can be.

Seems like creating an association that uses a custom finder might be the way to go? Never tried, so I can’t provide sample code; give it a shot and see how it works?

Another option would be to have multiple associations, and a virtual field with a custom _get function that combines them all?

Another option could be to not treat the tags as entity itself, but use a TagBehavior and a TagTrait (for controllers) to simply use/include it into any model/controller…

This way, you could have a tags-column on any entity to store the tags and can provide common search/add/edit/delete functions to models and controllers with minimum effort.

Thank you for the ideas.
It seems to be the best solution.
I’ll let you know.

Apologies about reviving an old thread. Just ignore.

I chose to do so, however, because the solution to this question is now documented in the other thread I recently created, I figured as an aid anyone doing searches on how to do this, I should post a link to the other thread here: