I’m working with two plugins: Kikioboeru/Blog and FinlayDaG33k/Comments.
The Kikioboeru/Blog plugin has a model named Articles.
This plugin is not aware of the FinlayDaG33k/Comments plugin (this is by design).
Now in a query for the Articles table, I want to include the comments that are associated with them.
However, I cannot do it like this, because again, the Blog plugin is not aware of the Comments plugin (and as such, it doesn’t have a hard-coded association):
My question is, is there a way to add this association from the FinlayDaG33k/Comments plugin?
The FinlayDaG33k/Comments plugin is “aware” of the Kikioboeru/Blog plugin but the Kikioboeru/Blog plugin is not aware of the FinlayDaG33k/Comments plugin.
How about subclassing the Table class yourself, and adding the required HasMany association in your subclass initialize method? I’ve not tried this myself, just an idea…
I’ve came to that idea ye by doing it with an extend, however, since only the parent class (the table in Kikioboeru/Blog) will be loaded, the child class’ (FinlayDaG33k/Comments) initialize method will not be ran :\
I could load the table from the Comments plugin (instead of the one in the Blog plugin) but this means the Blog plugin will become “aware” (more like dependent) of the Comments plugin, which is not something we want :\
Write a listener for one of the system startup events, and build a more intelligent function that can handle this for all required models? Still a bit of a mess, but maybe more self-contained, and potentially one that doesn’t require code changes when you add new models; it might iterate the Table folder and find tables that have a certain flag set, caching the resulting list?