mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 15:44:59 +00:00
Add nameToCollectionName
This commit is contained in:
parent
6cf3c76195
commit
9cb7035ade
@ -7,7 +7,7 @@ const pluralize = require('pluralize');
|
||||
|
||||
const contentTypeService = require('./ContentTypes');
|
||||
const { formatAttributes, convertAttributes } = require('../utils/attributes');
|
||||
const { nameToSlug } = require('../utils/helpers');
|
||||
const { nameToSlug, nameToCollectionName } = require('../utils/helpers');
|
||||
|
||||
/**
|
||||
* Formats a component attributes
|
||||
@ -121,7 +121,9 @@ const createSchema = infos => {
|
||||
connection,
|
||||
collectionName:
|
||||
collectionName ||
|
||||
`components_${nameToSlug(category)}_${pluralize(nameToSlug(name))}`,
|
||||
`components_${nameToCollectionName(category)}_${nameToCollectionName(
|
||||
pluralize(name)
|
||||
)}`,
|
||||
attributes: convertAttributes(attributes),
|
||||
};
|
||||
};
|
||||
|
||||
@ -8,6 +8,7 @@ const generator = require('strapi-generate');
|
||||
|
||||
const componentService = require('./Components');
|
||||
const { formatAttributes, convertAttributes } = require('../utils/attributes');
|
||||
const { nameToCollectionName } = require('../utils/helpers');
|
||||
|
||||
const deleteAllRelations = ({ modelName, plugin }) => {
|
||||
const contentTypeUpdates = Object.keys(strapi.contentTypes).map(uid => {
|
||||
@ -263,7 +264,7 @@ const createContentTypeSchema = infos => ({
|
||||
'default'
|
||||
),
|
||||
collectionName:
|
||||
infos.collectionName || `${_.snakeCase(pluralize(infos.name))}`,
|
||||
infos.collectionName || `${nameToCollectionName(pluralize(infos.name))}`,
|
||||
info: {
|
||||
name: infos.name,
|
||||
description: infos.description,
|
||||
|
||||
@ -58,15 +58,15 @@ describe('Component Service', () => {
|
||||
test('Generats normalized uids', () => {
|
||||
expect(
|
||||
createComponentUID({ category: 'default', name: 'some char' })
|
||||
).toBe('default.some_char');
|
||||
).toBe('default.some-char');
|
||||
|
||||
expect(
|
||||
createComponentUID({ category: 'default', name: 'some-char' })
|
||||
).toBe('default.some_char');
|
||||
).toBe('default.some-char');
|
||||
|
||||
expect(
|
||||
createComponentUID({ category: 'default', name: 'Some Char' })
|
||||
).toBe('default.some_char');
|
||||
createComponentUID({ category: 'defaultTest', name: 'Some Char' })
|
||||
).toBe('default-test.some-char');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -28,8 +28,11 @@ const deepTrimObject = attribute => {
|
||||
*/
|
||||
const nameToSlug = name => slugify(name, { separator: '-' });
|
||||
|
||||
const nameToCollectionName = name => slugify(name, { separator: '_' });
|
||||
|
||||
module.exports = {
|
||||
escapeNewlines,
|
||||
deepTrimObject,
|
||||
nameToSlug,
|
||||
nameToCollectionName,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user