So i have 2 tables with both having association belongsToMany to each other. The join table between these 2 has some additional fields and one of them is foreign key to third table. My question is how can i load this association of _jointData between these 2 tables?
Example:
Table Articles belongs to many Tags and Tags belongs to many Articles. Join table for both is ArticlesTags which has columns: article_id, tag_id and additional field image_id which is connected with Images table. When in controller, how can I conatin() so that _joinData in view contains not just image_id but the Image object as well?
I’m afraid you misunderstood my question… if i do like you said I’m gonna have _joinData and be able to access it like you said but i will only have accessible image_id and not image entity with all data. Your line Articles->find()->contain([‘Tags’]) will give me array of Tag entities for that article but not the image entity from _joinData which represents repository ArticlesTags.
Hmm let me try to reformulate the question: Imagine that articles have images like you said, but also imagine that this jointable ArticlesTags has Images as well… which are not the same. I need the image object from ArticlesTags table… not the Articles table? Check the screenshot above… i need the images from middle table, not the left one. (they are not the same)
owhh… i see you the image object loaded inside _joinData, right?
to what i know _joinData will only contain the data of joinTable, article_id, tag_id, image_id. with some extra field to keep the data inside the joinTable it self or if you need to use join columns outside of the conventions, e.g (HasMany Through)