Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird Collection Name Due to Mongoose utils.toCollectionName #2957

Closed
rawkode opened this issue Jul 2, 2023 · 4 comments
Closed

Weird Collection Name Due to Mongoose utils.toCollectionName #2957

rawkode opened this issue Jul 2, 2023 · 4 comments
Assignees
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@rawkode
Copy link

rawkode commented Jul 2, 2023

Link to reproduction

https://github.com/rawkode/payload/tree/bug/pluralize

To Reproduce

Create a CollectionConfig with a slug of people.

Describe the Bug

Inspect the mongoDB tables and one will be called "peoples"

I tracked this down to utils.toCollectionName in mongoose, which in turn calls pluralize, available here.

This could be by-passed by providing a variable on CollectionConfig to specify the collection name, which would then be passed to Schema() via schemaOptions

Payload Version

1.9.5

@rawkode rawkode added the status: needs-triage Possible bug which hasn't been reproduced yet label Jul 2, 2023
@AlessioGr
Copy link
Member

Related PR (not merged yet): #2836

Might also disable this by default in 2.0, though that's not decided yet

@rawkode
Copy link
Author

rawkode commented Jul 2, 2023

Maybe 2.0 would be a good opportunity to make the current config of:

export const People: CollectionConfig = {
	slug: "people",
	labels: { singular: "Person", plural: "People" },
	graphQL: { singularName: "Person", pluralName: "People" },
}

more streamlined:

export const People: CollectionConfig = {
	slug: "people",
        singular: "person",
        plural: "people",
	
        // Infer these from above
        // labels: { singular: "Person", plural: "People" },
	// graphQL: { singularName: "Person", pluralName: "People" },
}

@jmikrut
Copy link
Member

jmikrut commented Jul 2, 2023

OK so the team and I just talked about this a little bit - and as of now we are hoping to be as declarative as possible here, so that developers have as much flexibility as possible regarding slug, the database name, labels used in admin / error messages, etc.

We are also moving toward a database adapter pattern, meaning that any Mongoose-specific properties should be scoped to the future Mongoose adapter itself, and not present in the main Payload config. So that will have some ramifications regarding how we solve this.

We will definitely resolve this one way or another very soon. Thank you for bringing this up!

@lablancas
Copy link
Contributor

@jmikrut I am working on a prototype to migrate to Payload with an existing MongoDB. I have been using camel case for my collection names, but it seems like the slug set for a CollectionConfig is being converted to lowercase due to the Mongoose model name conversion. Is there any changes coming that will allow for setting the collection name in the CollectionConfig to allow for overriding the conversion. Just checking before I look into renaming my collections.

@payloadcms payloadcms locked and limited conversation to collaborators Jul 31, 2023
@jmikrut jmikrut converted this issue into discussion #3103 Jul 31, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants