Comments (12)
Actually, it works fine using the $strapi.find('categories', { _sort: 'created_at:desc })
and the same applies for any other Strapi parameter (_limit, _sort, _start, etc)
If you wanna use categories, you should take a look at the Strapi guide, where they use Restaurants and Categories, then when you fetch your articles you could do: $strapi.find('articles', { category.name: yourCategoryName })
.
Also, if you are doing $strapi.find('categories', { _sort: 'created_at:desc })
, this will get the articles related to each category with them unless you set them to private in your model json.
Edit: If you wanna get all the articles for a given set of categories, you need to use the 1st Method shown here, in which they pass an array $strapi.find('products', [['categories.name', 'women'], ['categories.name', 'men']])
. Or if you want to get the products
that have both men
and women
as their category, you need to do the 2nd Method shown there await $strapi.find('products', { 'categories.name': ['women', 'men'] })
from strapi.
I would also like to know
from strapi.
Я тоже хотел бы знать
from strapi.
hi guys,
@DragonWhisperer , @Rendxn
i'm used _sort param,
ex: articles: await $strapi.find("articles", { _sort: "created_at:desc" })
I think the other parameters are used the same way
but I would also like to sort the articles into categories,
async fetch() {
this.categories = await this.$strapi.find("categories", {
_sort: "articles.created_at:desc",
});
},
but that doesn't work, can you give me a hint?
from strapi.
The Strapi module is a just a wrapper to call your API. Are you sure GET /categories?_sort=articles.created_at:desc
works?
from strapi.
I'm having a problem here when trying to use _where
. As per the docs here, this should work:
const query = qs.stringify({ _where: { _or: [{ stars: 1 }, { pricing_gt: 30 }] } });
await request(`/restaurant?${query}`);
I've tried this:
params._where = {
_or: [
{name_contains: 'a'},
{description_contains: 'a'},
{serial_contains: 'a'}
]
}
and this:
params._where = qs.stringify({
_or: [
{name_contains: 'a'},
{description_contains: 'a'},
{serial_contains: 'a'}
]
})
with no luck. I get a 404 Bad Request
error with the message: HTTPError: Your filters contain a field '0' that doesn't appear on your model definition nor it's relations
. If I built the query manually, like this:
params['_where[_or][0][name_contains]'] = 'a';
params['_where[_or][1][description_contains]'] = 'a';
params['_where[_or][2][serial_contains]'] = 'a';
It works. I guess there's some problem when building the url with complex params. Maybe the use of qs.stringify
for the whole params object is needed, don't know.
Anyone has been lucky doing something like this?
Thanks!
from strapi.
@luixal You don't need to use qs.stringify
here, the module does it for you, check out the documentation here.
$strapi.find('restaurants', { _where: { _or: [{ stars: 1 }, { pricing_gt: 30 }] } })
from strapi.
@benjamincanac
On my end it not works. Can you please test it?
$strapi.find('restaurants', { _where: { _or: [{ stars: 1 }, { pricing_gt: 30 }] } })
error http://localhost:1337/restaurants?_where=%5Bobject+Object%5D
I think that nested objects not allowed.
from strapi.
@luixal @alexey13 Indeed my bad, it seems that ky
doesn't support complex objects.
You have to use the qs library I guess, is this the one you tried?
from strapi.
Yeah, I use qs and it works nice!
from strapi.
I didn't get it working back in the day, anyway, we had to go other way that fit better our needs. I cannot test it right now but seeing @alexey13 confirmation I'll take it into consideration for next time :)
Thanks!
from strapi.
Por si ha alguien le sirve yo utilize qs, pero cometía el error de pasarlo:
const academy = await this.$strapi.find('collection-example', { queryCollection })
Cuando la forma correcta era usar el cliente http de Strapi puesto que el módulo de Nuxt no soporta nativamente la versión 4 aunque lo diga.
Lo siguiente funcionó para mi:
const results = await this.$strapi.$http.$get('collection-example', { searchParams: queryCollection })
from strapi.
Related Issues (20)
- Error when Typing request parameters variable (Strapi4RequestParams) HOT 2
- How can i use this under server folder ? HOT 1
- How connect Strapi and Nuxt on Remote server
- Nuxt 3 Cookie Disappears on page reload HOT 2
- Where is the 'admin' module option? HOT 1
- Can I customize the Strapi url for only the data requests, yet keep the defaults on everything else?
- Server side request is returning 403
- Generating static output gives localhost adress
- Export types HOT 10
- How to perform transactions in nuxt HOT 1
- How to handle errors when using useAsyncData?
- Problem with useAsyncData when use NuxtLInk
- SSR for user page using useAsyncData & useStrapiAuth (or useStrapiUser)
- How delete with proxy?
- Typescript on pagination.
- Problem with fetch data in production HOT 1
- Strapi v5 Beta
- Looking for maintainers HOT 1
- Mocking strapi with MSW
- Typing response from find HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strapi.