mirror of
https://github.com/strapi/strapi.git
synced 2025-12-30 00:37:24 +00:00
Set default locale when using Query Engine function createMany
This commit is contained in:
parent
4e53160dcf
commit
3c79572705
3
packages/plugins/i18n/server/bootstrap.js
vendored
3
packages/plugins/i18n/server/bootstrap.js
vendored
@ -13,6 +13,9 @@ const registerModelsHooks = () => {
|
||||
async beforeCreate(event) {
|
||||
await getService('localizations').assignDefaultLocale(event.params.data);
|
||||
},
|
||||
async beforeCreateMany(event) {
|
||||
await getService('localizations').assignDefaultLocale(event.params.data);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { prop, isNil, isEmpty } = require('lodash/fp');
|
||||
const { prop, isNil, isEmpty, isArray } = require('lodash/fp');
|
||||
|
||||
const { getService } = require('../utils');
|
||||
|
||||
@ -11,7 +11,14 @@ const { getService } = require('../utils');
|
||||
const assignDefaultLocale = async (data) => {
|
||||
const { getDefaultLocale } = getService('locales');
|
||||
|
||||
if (isNil(data.locale)) {
|
||||
if (isArray(data) && data.some((entry) => !entry.locale)) {
|
||||
const defaultLocale = await getDefaultLocale();
|
||||
data.forEach((entry) => {
|
||||
if (isNil(entry.locale)) {
|
||||
entry.locale = defaultLocale;
|
||||
}
|
||||
});
|
||||
} else if (isNil(data.locale)) {
|
||||
data.locale = await getDefaultLocale();
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user