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

Improve Serializer.pluralize to guess more plurals #919

Closed
wants to merge 1 commit into from

Conversation

teddyzeenny
Copy link
Contributor

I changed the pluralize / singularize functions to guess more common cases, so we can reduce the need for configure('plurals') to a minimum.

Two main things I did:

  • Made sure if we define a plural for criterion, pluralize can guess the plural for system_criterion
  • Added more common cases such as words ending in y, s, x ... etc

@sly7-7
Copy link
Contributor

sly7-7 commented Apr 25, 2013

I wonder if in long term, we should rely on an extenral lib, like https://github.com/stefanpenner/ember-inflector/
If I remember well, that's what @stefanpenner and @wycats plans... but not sure...

@teddyzeenny
Copy link
Contributor Author

An external lib like @stefanpenner 's inflector is necessary to cover all possibilities. However the amount of code required makes it very difficult for it to be introduced into core, and using an external lib would be the best option.

My PR is an attempt to cover as many possibilities as possible with as little amount of code possible. Since Ember.js always aims to reduce as much configuration as possible, I think it would be good to have a smarter pluralization function built into core (although obviously not perfect due to the size limitation).

IMO the amount of code added in this PR is small compared to the amount of configuration that will be eliminated.

@sly7-7
Copy link
Contributor

sly7-7 commented Apr 26, 2013

This makes sense, ATM this is probably a good compromise. Thanks :)

@seanrucker
Copy link

Would this work for words that are the same in both the singular and plural form? E.g. "series". Ember does not like it if the singular and plural form are the same. The _pluralizeAliases method barfs out an error.

DS.RESTAdapter.configure('plurals', { series: 'series' });

It gives me the error:

Uncaught Error: assertion failed: The 'series' alias has already been defined 

@seanrucker
Copy link

Probably a separate issue from this, but I think we need something similar to Rails support for "uncountables".

http://markembling.info/2011/06/uncountable-nouns-rails-3-resource-routing

@stefanpenner
Copy link
Member

@teddyzeenny we should collab on this

@seanrucker
Copy link

I started digging into the issue with uncountable model names and came across a race condition in the serializer.

#928

@pangratz
Copy link
Member

Would this work for words that are the same in both the singular and plural form? E.g. "series". Ember does not like it if the singular and plural form are the same. The _pluralizeAliases method barfs out an error.

DS.RESTAdapter.configure('plurals', { series: 'series' });
It gives me the error:

Uncaught Error: assertion failed: The 'series' alias has already been defined

I've got hit by this one too ...

@stefanpenner
Copy link
Member

I think we need a true inflector with rules or we will just end up with inconsistencies.

@teddyzeenny
Copy link
Contributor Author

@stefanpenner agreed, closing this for now, until we come up with a more comprehensive solution; which would probably be based on your inflector.

@stefanpenner
Copy link
Member

@teddyzeenny sounds good.

@seanrucker
Copy link

I created a PR for the smallest possible fix for the uncountable issue: #940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants