Skip to content
This repository

pluralize a little smarter #463

wants to merge 1 commit into from

5 participants

Mehul Kar Trek Glowacki Stefan Penner Tim Evans Tom Dale
Mehul Kar

No description provided.

Trek Glowacki

I almost wish we'd move RESTAdapter out of core or just label it as an example... but maybe I'm just bitter because my data needs are so crazy I can't use RESTAdapter

Mehul Kar

@trek I really like that idea actually. But if that were to happen a warning when starting the app would be nice.

Stefan Penner

@tim-evans i need to send a PR or make it a standalone plugin, but this might be useful.

Tim Evans

IMO, I'd make this a standalone plugin. SC does this ( I think the best approach would be to take the SC code and convert it to Ember code.

Tom Dale

Thanks for the pull request, but I'm going to have to decline this bad boy.

If we are going to do this, we should do it right and use a full-blown inflector library, like the one @stefanpenner mentioned above.

As much as I'd like to ship an inflector library with Ember, I think doing so would rank pretty high on the HHWWGT Index (How Hard Would We Get Trolled). We intentionally left this hook as dumb as possible so people will use something more appropriate for their needs.

There are some people who disagree with me, but whether it's built-in or available as a drop-in plugin, I think we need to use a battle-tested inflection library and not build it up ad-hoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 06, 2012
Mehul Kar mehulkar pluralize a little smarter 77e96b6
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 7 additions and 1 deletion. Show diff stats Hide diff stats

  1. +7 1 packages/ember-data/lib/adapters/rest_adapter.js
8 packages/ember-data/lib/adapters/rest_adapter.js
@@ -271,7 +271,13 @@ DS.RESTAdapter = DS.Adapter.extend({
271 271 // define a plurals hash in your subclass to define
272 272 // special-case pluralization
273 273 pluralize: function(name) {
274   - return this.plurals[name] || name + "s";
  274 + var plural;
  275 + if (name.slice(-1) === 'y') {
  276 + plural = name.slice(0, -1) + "ies";
  277 + } else {
  278 + plural = name + "s";
  279 + }
  280 + return this.plurals[name] || plural;
275 281 },
276 282
277 283 rootForType: function(type) {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.