diff --git a/docs/3.x.x/guides/filters.md b/docs/3.x.x/guides/filters.md index 315401fd59..c4760cfc01 100644 --- a/docs/3.x.x/guides/filters.md +++ b/docs/3.x.x/guides/filters.md @@ -24,6 +24,7 @@ Easily filter results according to fields values. - `_gt`: Greater than - `_lte`: Lower than or equal to - `_gte`: Greater than or equal to + - `_in`: Include in array - `_contains`: Contains - `_containss`: Contains case sensitive @@ -37,6 +38,9 @@ Find products having a price equal or greater than `3`. `GET /products?price_gte=3` +Find multiple product with id 3, 6, 8 +`GET /products?id_in=3&id_in=6&id_in=8` + ::: note You can't use filter to have specific results inside relation, like "Find users and only their posts older than yesterday" as example. If you need it, you can modify or create your own service or use [GraphQL](./graphql.md#query-api). ::: diff --git a/packages/strapi-hook-mongoose/lib/index.js b/packages/strapi-hook-mongoose/lib/index.js index 529743a023..4daf8faa68 100644 --- a/packages/strapi-hook-mongoose/lib/index.js +++ b/packages/strapi-hook-mongoose/lib/index.js @@ -160,6 +160,28 @@ module.exports = function (strapi) { } else { this._mongooseOptions.populate[association.alias].path = `${association.alias}.ref`; } + } else { + if (!this._mongooseOptions.populate) { + this._mongooseOptions.populate = {}; + } + + // Images are not displayed in populated data. + // We automatically populate morph relations. + if (association.nature === 'oneToManyMorph' || association.nature === 'manyToManyMorph') { + this._mongooseOptions.populate[association.alias] = { + path: association.alias, + match: { + [`${association.via}.${association.filter}`]: association.alias, + [`${association.via}.kind`]: definition.globalId + }, + options: { + sort: '-createdAt' + }, + select: undefined, + model: undefined, + _docs: {} + }; + } } next(); }); @@ -554,4 +576,4 @@ module.exports = function (strapi) { }, relations); return hook; -}; \ No newline at end of file +}; diff --git a/packages/strapi/bin/strapi-new.js b/packages/strapi/bin/strapi-new.js index 707a7bbe35..87a11ce1b4 100644 --- a/packages/strapi/bin/strapi-new.js +++ b/packages/strapi/bin/strapi-new.js @@ -61,6 +61,7 @@ module.exports = function (name, cliArguments) { settings: { client: cliArguments.dbclient, host: cliArguments.dbhost, + srv: cliArguments.dbsrv, port: cliArguments.dbport, database: cliArguments.dbname, username: cliArguments.dbusername, diff --git a/packages/strapi/bin/strapi.js b/packages/strapi/bin/strapi.js index 4aa5d87cdd..03dad62503 100755 --- a/packages/strapi/bin/strapi.js +++ b/packages/strapi/bin/strapi.js @@ -56,6 +56,7 @@ program .option('--debug', 'Display database connection error') .option('--dbclient ', 'Database client') .option('--dbhost ', 'Database host') + .option('--dbsrv ', 'Database srv') .option('--dbport ', 'Database port') .option('--dbname ', 'Database name') .option('--dbusername ', 'Database username')