Hi folks,
Let’s say I have a posts collection.
Post’s item looks like
{
title: ,
date:
…
…
category: [
{…, display: <CAT_URL>, …},
{…, display: <CAT_URL>, …},
…
]
}
Categories is a collection link that can have one or many categories. (Category is also collection)
Now, I want to GET all posts that have category.display = "CAT_1"
It doesn’t work to call /api/collcetions/posts?filter[category.display]=CAT_1
.
It works only if category is not array (multiply: false)
I did not find any info about it. So, could somebody recommend me how to filter by multip collection lists?
Thanks in advance
I found the solution.
Create /config/api/post.php
<?php
$cat = $this->param(‘cat’);
$post = $this->param(‘post’);
if (!$cat || !$post) {
echo “Not found post or cat params…”;
return “Not found post or cat params…”;
}
$entries = cockpit(‘collections’)->find(‘post’, [
‘filter’ => function($document) use ($cat, $post) {
if ($document[‘url’] === $post){
foreach((array)$document[‘category’] as $item) {
if ($item[‘display’] === $cat) return true;
}
}
return false;
}
]);
return $entries;
and itwill be possible to get all posts in category $post with the post url $post by calling get request to /api/post?token=<TOKEN>&cat=<CAT>&post=<POST>
But i need to “expand” collection links. I mean get full information about collection (not {_id: , display: , …}
Have somebody ideas how to to it?