Extending Attachment model with extra JOIN clause in add-on

llk

Member
In this thread, I asked about a feature to allow extra joins in Model/Attachment.php. In his response, Chris D says:
...Arguably, there'd be nothing stopping an add-on from adding in their own joins, even in XF1...
But how can this be done, without modifying core XF files?
 

Mike

XenForo developer
Staff member
It depends what method you're trying to extend. If there isn't a "hook" point of sorts, you'd be replacing the method in question with custom code. In a method like getAttachments(), you'd extend prepareAttachmentFetchOptions and either adjust the calling code to have your join or "piggyback" so that your data is fetched when you need it.
 

llk

Member
There's no hook, no (that's what I proposed in my other thread, but it seems like a no-go).

For the alternative method, you're suggesting copying some of the code from XF's Attachment model into my subclass and then modifying it there, right? Not ideal, but better than hacking core XF files I suppose.
 

llk

Member
See the other thread I linked-- I'm trying to update the [bd] Attachment Store addon so it doesn't have to store its backend config options in every row of xf_attachment_data, and can instead store them in a separate table (but without generating additional queries).

So the queries in getAttachmentsByContentIds, getAttachmentById, etc. would need to be modified with an extra JOIN clause.
 
Top