Skip to content
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

Don't require singularized type: (hasMany might be the last remaining place) #5475

Closed
nathanhammond opened this issue May 23, 2018 · 2 comments
Labels
feature-suggestion 🏷️ feat This PR introduces a new feature

Comments

@nathanhammond
Copy link
Member

nathanhammond commented May 23, 2018

The only way to configure around this requires knowing about ember-inflector and ensuring that you get the inflector rules in place prior to relationship instantiation. Asking somebody to know about initializers and ember-inflector when they're just starting to configure Ember Data for the first time is another papercut that continues the "Ember Data is hard" trope.

Offending code:
https://github.com/emberjs/data/blob/e3a24f6/addon/-private/system/relationship-meta.js#L10

Everything else about Ember Data is customizable given normalizeModelName except for this one singularization behavior. Nothing internal to Ember Data requires singularization, nothing about the hasMany signature implies that we should allow users to pluralize the model name.

The explanation I can come up with for this feature is that it reads nicer in English in the model definition. But having N ways to accomplish a task is not a good API:

// No cheating, tell me which model this uses:
hasMany('people')

// Here's a hint, this one uses the same model:
hasMany('persons')

// And so does this one:
hasMany('person')

// All of them do the same thing, but in only one case is it
// crystal clear where the backing files are.

We already don't recommend this; the current Ember Data docs use the actual model name when defining a hasMany relationship:
https://guides.emberjs.com/release/models/relationships/

So let's fix this. Proposal:

  • Automatic singularization of hasMany should be deprecated. It's a mechanical change, so it's easy for users to do. And we already have a place where it's super-easy to insert a deprecation.
@runspired
Copy link
Contributor

Nothing internal to Ember Data requires singularization, nothing about the hasMany signature implies that we should allow users to pluralize the model name.

This isn't strictly true. We did to work recently to begin attempting to allow this, but there are still pitfalls everywhere and we assert that you've normalized at most entry points for this reason.

@runspired runspired changed the title hasMany forces you through singularize hasMany might be the last remaining place that enforces singularize Jun 3, 2018
@runspired runspired changed the title hasMany might be the last remaining place that enforces singularize Don't require singularized type: (hasMany might be the last remaining place) Jun 3, 2018
@runspired
Copy link
Contributor

Covered by emberjs/rfcs#740 and emberjs/rfcs#739

@runspired runspired added feature-suggestion 🏷️ feat This PR introduces a new feature and removed Feature labels Sep 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-suggestion 🏷️ feat This PR introduces a new feature
Projects
None yet
Development

No branches or pull requests

2 participants