Anonymous
Фильтр Strapi по связанным пользователям в Strapi во взаимоотношениях «многие ко многим»
Сообщение
Anonymous » 28 окт 2025, 05:34
Код: Выделить всё
const projects = await strapi.entityService.findMany('api::project.project', {
filters: { users: { id: { $eq: userId } } },
populate: ['tenant', 'users'],
});
приведенный выше код работает нормально, но когда я пытаюсь запустить это rest api
/api/projects?populate[0]=user&populate[1]=tenant&filters[users][id][$eq]=35
схема разрешений пользователя
Код: Выделить всё
{
"kind": "collectionType",
"collectionName": "up_users",
"info": {
"name": "user",
"description": "",
"singularName": "user",
"pluralName": "users",
"displayName": "User"
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"username": {
"type": "string",
"minLength": 3,
"unique": true,
"configurable": false,
"required": true
},
"email": {
"type": "email",
"minLength": 6,
"configurable": false,
"required": true
},
"provider": {
"type": "string",
"configurable": false
},
"password": {
"type": "password",
"minLength": 6,
"configurable": false,
"private": true,
"searchable": false
},
"resetPasswordToken": {
"type": "string",
"configurable": false,
"private": true,
"searchable": false
},
"confirmationToken": {
"type": "string",
"configurable": false,
"private": true,
"searchable": false
},
"confirmed": {
"type": "boolean",
"default": false,
"configurable": false
},
"blocked": {
"type": "boolean",
"default": false,
"configurable": false
},
"role": {
"type": "relation",
"relation": "manyToOne",
"target": "plugin::users-permissions.role",
"inversedBy": "users",
"configurable": false
},
"mobileNo": {
"type": "biginteger",
"unique": true
},
"tenant": {
"type": "relation",
"relation": "manyToOne",
"target": "api::tenant.tenant",
"inversedBy": "users"
},
"projects": {
"type": "relation",
"relation": "manyToMany",
"target": "api::project.project",
"mappedBy": "users"
}
}
}
схема модели проекта
Код: Выделить всё
{
"kind": "collectionType",
"collectionName": "projects",
"info": {
"singularName": "project",
"pluralName": "projects",
"displayName": "Project"
},
"options": {
"draftAndPublish": false
},
"pluginOptions": {},
"attributes": {
"name": {
"type": "string",
"unique": true
},
"tenant": {
"type": "relation",
"relation": "manyToOne",
"target": "api::tenant.tenant",
"inversedBy": "projects"
},
"description": {
"type": "text"
},
"users": {
"type": "relation",
"relation": "manyToMany",
"target": "plugin::users-permissions.user",
"inversedBy": "projects"
}
}
}
я получаю ошибку проверки
подробности
:
{key: "users", путь: "users", источник: "query", параметр: "filters"
message
:
"Неверный ключ пользователей"
name
:
"ValidationError"
status
:
400
Подробнее здесь:
https://stackoverflow.com/questions/798 ... lationship
1761618872
Anonymous
[code]const projects = await strapi.entityService.findMany('api::project.project', { filters: { users: { id: { $eq: userId } } }, populate: ['tenant', 'users'], }); [/code] приведенный выше код работает нормально, но когда я пытаюсь запустить это rest api /api/projects?populate[0]=user&populate[1]=tenant&filters[users][id][$eq]=35 схема разрешений пользователя [code]{ "kind": "collectionType", "collectionName": "up_users", "info": { "name": "user", "description": "", "singularName": "user", "pluralName": "users", "displayName": "User" }, "options": { "draftAndPublish": false }, "pluginOptions": {}, "attributes": { "username": { "type": "string", "minLength": 3, "unique": true, "configurable": false, "required": true }, "email": { "type": "email", "minLength": 6, "configurable": false, "required": true }, "provider": { "type": "string", "configurable": false }, "password": { "type": "password", "minLength": 6, "configurable": false, "private": true, "searchable": false }, "resetPasswordToken": { "type": "string", "configurable": false, "private": true, "searchable": false }, "confirmationToken": { "type": "string", "configurable": false, "private": true, "searchable": false }, "confirmed": { "type": "boolean", "default": false, "configurable": false }, "blocked": { "type": "boolean", "default": false, "configurable": false }, "role": { "type": "relation", "relation": "manyToOne", "target": "plugin::users-permissions.role", "inversedBy": "users", "configurable": false }, "mobileNo": { "type": "biginteger", "unique": true }, "tenant": { "type": "relation", "relation": "manyToOne", "target": "api::tenant.tenant", "inversedBy": "users" }, "projects": { "type": "relation", "relation": "manyToMany", "target": "api::project.project", "mappedBy": "users" } } } [/code] схема модели проекта [code]{ "kind": "collectionType", "collectionName": "projects", "info": { "singularName": "project", "pluralName": "projects", "displayName": "Project" }, "options": { "draftAndPublish": false }, "pluginOptions": {}, "attributes": { "name": { "type": "string", "unique": true }, "tenant": { "type": "relation", "relation": "manyToOne", "target": "api::tenant.tenant", "inversedBy": "projects" }, "description": { "type": "text" }, "users": { "type": "relation", "relation": "manyToMany", "target": "plugin::users-permissions.user", "inversedBy": "projects" } } } [/code] я получаю ошибку проверки подробности : {key: "users", путь: "users", источник: "query", параметр: "filters" message : "Неверный ключ пользователей" name : "ValidationError" status : 400 Подробнее здесь: [url]https://stackoverflow.com/questions/79801617/strapi-filter-by-related-users-in-strapi-in-many-to-many-relationship[/url]