hi there i have post tag relation collection and using it to solve many-to-many relation.
i’m trying to filter tags which is related exact post but i cant figure it out to filter by collection link _id
this is a snippet to show what i want to achieve
if (COCKPIT_API_REQUEST) {
$app->on('collections.find.after.posts', function ($name, &$entries) use ($app) {
foreach ($entries as &$entry) {
$id = $entry["_id"];
$tags = $this->module('collections')->find('tags',['_id' => $id]);//problem on filter
if (!empty($tags)) {
// foreach ($tags as &$tag) {
// $entry["linked"][]=$tag;
// }
} else {
$entry["linked"][]="";
}
}
});
}
related field is post and i need to filter post[_id] field
i tried
[‘post’][’_id] // no result
[‘post._id’ => $id] //all results no filter
[[‘account._id’] => $id] //Illegal offset type
i found solution posting here for someone needs
My goal was getting all posts with related tags included in this request (prevent from makng second request)
so 1st collection is
post
2nd collection
tags
3rd collection is
post-tags-relation
with snippets below i’m getting post entries and getting related tags for each post and adding them to the post entry.to filter relation collection i need to filter “_id” which is located