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

1.13.9 causes application with price object to call singular of api rather than plural, fine in 1.13.8 #3655

Closed
adam-knights opened this issue Aug 14, 2015 · 4 comments

Comments

@adam-knights
Copy link
Contributor

With 1.13.8 I could browse to http://localhost:4200/products/1 in my app.

And CLI would show get calls as:

GET /api/products/1 304 0.672 ms - -

GET /api/prices/1 304 0.451 ms - -
GET /api/prices/2 304 0.361 ms - -
GET /api/prices/3 304 0.297 ms - -

GET /api/accounts/4 304 0.357 ms - -
GET /api/accounts/5 304 0.271 ms - -
GET /api/accounts/7 304 0.488 ms - -

With Ember data 1.13.9 its asking for price rather than prices:

GET /api/products/1 304 3.418 ms - -

GET /api/price/1 404 22.919 ms - 24
GET /api/price/2 404 19.800 ms - 24
GET /api/price/3 404 14.895 ms - 24

All of my other plurals seem to work fine.

I've debugged the issue in my browser and from what I can see it is an issue in the inflector when pluralize is used by the _buildUrl method. In inflector.js in inflect: function (word, typeRules, irregular) there is this.rules.uncountable. And in the uncountable object there is rice: true.

There is a loop in there:

for (rule in this.rules.uncountable) {
  if (lowercase.match(rule + "$")) {
    return word;
  }
}

When the rule hits 'rice' it hits the return and returns price rather than prices to pluralize.

If you need more info from my debugging please let me know, should these preset rules be getting in there? If yes then rice should not effect price.

The product model:

export default DS.Model.extend({
  code: DS.attr('string'),
  name: DS.attr('string'),
  measurementUnit: DS.belongsTo('measurementUnit', {async: true}),
  miscellaneous: DS.attr('boolean'),
  prices: DS.hasMany('price', {async: true}),
  orderItems: DS.hasMany('orderItem', {async: true})
});

The price model:

export default DS.Model.extend({
  account: DS.belongsTo('account', {async: true}),
  product: DS.belongsTo('product', {async: true}),
  value: DS.attr('number'),
  creationDate: DS.attr('date'),
  orderItems: DS.hasMany('orderItem', {async: true})
});

I'm more than happy to debug this to

@adam-knights
Copy link
Contributor Author

This looks related to emberjs/ember-inflector#85 - it's just whether the issue is with inflector or what ember data passes to inflector?

Edit: I'm fairly certain the issue will need an inflector fix.

@adam-knights
Copy link
Contributor Author

This was fixed in v1.9.1 of inflector and can be closed when data has it.

@adam-knights
Copy link
Contributor Author

@bmac This appears to be fixed in 1.13.10 for me, am I right in thinking when you released 1.13.10 because package.json has "ember-inflector": "^1.9.0" the caret will allow the release to have picked up 1.9.1? Thanks for the release btw.

@bmac
Copy link
Member

bmac commented Oct 7, 2015

That is correct. Ember Data not explicitly requires ^1.9.2 so I'm going to close this issue. Feel free to re-open if there is still a problem.

@bmac bmac closed this as completed Oct 7, 2015
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

No branches or pull requests

2 participants