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

Irregular rule for unitOfMeasure to unitsOfMeasure does not work #95

Closed
adam-knights opened this issue Dec 7, 2015 · 18 comments · Fixed by #106
Closed

Irregular rule for unitOfMeasure to unitsOfMeasure does not work #95

adam-knights opened this issue Dec 7, 2015 · 18 comments · Fixed by #106

Comments

@adam-knights
Copy link

I tried adding

inflector.irregular('unitOfMeasure', 'unitsOfMeasure');

To my app and it doesn't work, it hits /api/unitOfMeasure, it should now be hitting /api/unitsOfMeasure

I created a unit test in /tests/unit/inflector-test.js that fails on both asserts in latest master:

test('unit of measure', function(assert) {
  inflector.irregular('unitOfMeasure', 'unitsOfMeasure');

  assert.equal(inflector.singularize('unitsOfMeasure'), 'unitOfMeasure', 'irregular singularization rule was applied');
  assert.equal(inflector.pluralize('unitOfMeasure'), 'unitsOfMeasure', 'irregular pluralization rule was applied');
});

I had a quick debug, it seems to find the irregular rule ok and populate substitution in the for loop, but then I think the return in that loop of return word.replace(rule, substitution); doesn't do the job as word is unitOfMeasure and rule is unitofmeasure, so there is no match due to the casing?

@adam-knights
Copy link
Author

The above research stemmed from me trying to define plurals in DS.RESTAdapter.extend, and this working for all but unitOfMeasure: unitsOfMeasure. I'm guessing this feeds into ember inflector?

@adam-knights
Copy link
Author

@fivetanley Any thoughts on whether this is a bug that would be affecting me defining this in Ember Data, or should I go back to Ember data and post this there?

@stefanpenner
Copy link
Member

We aim todo whatever the rails inflector does, if someone wants to check we can decide if this is a bug or not.

@fsmanuel
Copy link
Contributor

'unitOfMeasure'.pluralize # => "unitOfMeasures"
'unitsOfMeasure'.singularize # => "unitsOfMeasure"

@adam-knights
Copy link
Author

@fsmanuel thats with an irregular rule defined?

@fsmanuel
Copy link
Contributor

@adam-knights rails c i have nothing defined. It's just what the rails inflector does.

have you seen emberjs/data#3802 and here emberjs/data#3888 (comment)

@fsmanuel
Copy link
Contributor

@adam-knights what version of ember-data are you using. still seems to be a problem...

@adam-knights
Copy link
Author

I'm stuck on 1.13.15 currently, happy to revisit/test this when we are able to move upto a newer release

@fsmanuel
Copy link
Contributor

which adapter?

@adam-knights
Copy link
Author

RESTAdapter, so for plural of this example I would do:

export default DS.RESTAdapter.extend(DataAdapterMixin, {
  plurals: {
    unitOfMeasure: 'unitsOfMeasure'
  }
});

@fsmanuel
Copy link
Contributor

@adam-knights if the problem only occurs with the path you can patch pathForType
https://github.com/emberjs/data/blob/v1.13.15/packages/ember-data/lib/adapters/build-url-mixin.js#L319

But i guess the next will be the payload...

@escobera
Copy link

escobera commented Jul 5, 2016

I'm also being affected by this bug:

//rule
inflector.irregular('tipoDocumento', 'tiposDocumento');

//test
Ember.Inflector.inflector.pluralize('tipoDocumento');
=> "tipoDocumento"
Ember.Inflector.inflector.singularize('tiposDocumento');
=> "tiposDocumento"

And to improve this scenario I tested on ActiveSupport

Definition

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'tipoDocumento', 'tiposDocumento'
end

Test

$ rails c
Loading development environment (Rails 3.2.22)
2.2.4 :001 > "tipoDocumento".pluralize
 => "tiposDocumento" 
2.2.4 :002 > "tiposDocumento".singularize
 => "tipoDocumento" 
2.2.4 :003 > 

As you can see the behaviour is different.

@escobera
Copy link

@stefanpenner any new on this one?
I'm still affected by this.
If confirmed as a bug I can help come up with the solution, seems pretty straightforward.

@fsmanuel
Copy link
Contributor

@escobera which version of ember, ember-data and ember-inflector are you using?

@adam-knights
Copy link
Author

Here is a twiddle. In adapters/application.js the plural is defined but not picked up as it continues to try to hit the wrong API. https://ember-twiddle.com/7a1de453247619a45f3b39915ab3be90?fileTreeShown=false&numColumns=2&openFiles=routes.application.js%2C

@fsmanuel
Copy link
Contributor

I'm on it

@fsmanuel
Copy link
Contributor

@adam-knights and @escobera can you try the new version? I guess we have to inform the other addons about the fix.

@adam-knights
Copy link
Author

@fsmanuel thanks - Ember data is ^1.9.4, so when I get a chance i'll clear out my node/bower folders to pull in 1.9.5 and see

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 a pull request may close this issue.

4 participants