Making Cake\ORM\Association\BelongsToMany plugin aware

This is related to Case #9016 and this stackoverflow question.

I have a custom connection in a plugin and when I try to use a HABTM join table it uses the default connection instead of the plugin connection. The Model/Table has the defaultConnectionName() set to the plugin database.

I’ve been digging through the code, and while there’s a partially working patch from Case #9016, it’s not truly plugin aware and I’m not sure how to get the current plugin at that point.

It seems to me that if the join table was loaded wherever the tableLocator (called in BelongsToMany/junction line 179) was originally populated, that would also solve the problem. As far as I can tell, only the main tables are loaded and the join tables are created on the fly.

Hopefully that makes sense. :slight_smile:

I’m more than happy to keep digging, but I could use some pointers.

M