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 model name not being applied to return results #3802

Closed
tomoguisuru opened this issue Sep 28, 2015 · 15 comments
Closed

Irregular model name not being applied to return results #3802

tomoguisuru opened this issue Sep 28, 2015 · 15 comments

Comments

@tomoguisuru
Copy link

In my project, I have a inflector setup for a model with an irregular name, campus
For some reason, after updating from Ember CLI 0.2.7 to Ember CLI 1.13.8, the inflector is no longer being applied to the model.

When trying to access the store, this.store.findRecord('campus', params['campus_id']), I get the following error

No model was found for 'campu' Error: No model was found for 'campu'

The return payload looks something like this

{
  campus: {
    id: 1,
    name: "Default Campus"
  },
  meta: {
    total: 1,
    page: 1
  }
}

I have been using an initializer with previous success

import Ember from 'ember';

export function initialize(/* registry, application */) {
  var inflector = Ember.Inflector.inflector;
  inflector.irregular('campus', 'campuses');
}

export default {
  name: 'inflections',
  initialize: initialize
};

I've tried updating to the most recent version of Ember Data, 1.13.13, and updating the ember inflector to 1.9.3 but am no closer to resolving the issue

I'm assuming this is a bug since the store is showing correctly as campus and fails when a singular record is return as above since checking the singularization/pluralization seems to work fine

var inflector = Ember.Inflector.inflector;
inflector.singularize('campus') // returns "campus"
inflector.pluralize('campus') // returns "campuses"
@tomoguisuru
Copy link
Author

I forgot to add this warning that comes before the error
WARNING: Encountered "campus" in payload, but no model was found for model name "campu" (resolved model name using deployment@serializer:campus:.modelNameFromPayloadKey("campus"))

@pangratz
Copy link
Member

pangratz commented Oct 7, 2015

#3730 seems related. Can you test moving the definitions into app/app.js and check if it would work, as suggested in the issue?

@pangratz
Copy link
Member

pangratz commented Oct 7, 2015

After further digging I found #3655 (comment), which suggests to update the dependency for ember-inflector in package.json to the latest version. Can you give this a try?

@tomoguisuru
Copy link
Author

@pangratz at the time of submitting this ticket, I mentioned that I was already using 1.9.3 of the ember-inflector. I also tried using 1.9.0, 1.9.1, and 1.9.2 without any success.

As far as moving the inflectors into app/app.js, I have not tried that yet since I gave up on trying to upgrade my project

@remkoboschker
Copy link

I can confirm that putting the irregular ( or not in english) inflections in both an initializer and in app.js solves singularization / pluralization issues using json:api. This not seems very good practice though. Can anyone advise where they should go? Perhaps I can work on fixing the issue from there.

@bmac
Copy link
Member

bmac commented Oct 12, 2015

Putting irregular inflections into an initializer seems like the right way to go. I think we should try to find out why that use case broke.

@bmac
Copy link
Member

bmac commented Oct 21, 2015

@tomoguisuru I just created a sample Ember CLI project to try to re-create your issue and I was unable to reproduce it. Do you mind looking at this repo and letting me know what I'm missing? https://github.com/bmac/inflector-test

Thanks

@christophermlne
Copy link

@bmac I am having the same issue, with the same words ('campus'/'campuses').

In your example app there are no relationships. If you had, for example a Program model that could have many campuses, you'd see the app start to break and the errors will complain variously about there being no model called 'campuse' or no model called 'campu'...

If anyone wants access to my code to try to figure this one out, let me know and i'll grant access. (Code has to stay private unfortunately). This is actually the second Ember app where I've had to deal with this. The other app is using an older version of Ember and is fine...

@bmac
Copy link
Member

bmac commented Nov 4, 2015

@christophermlne do you mind testing out Ember Data 2.2.0-beta.3?

Prs #3887 and #3888 were recently merged which I suspect was contributing to this issue.

@christophermlne
Copy link

I will try to do as you ask but it may not be until next week sometime.

In the interim I was able to get this to work by doing adding the inflector rules to app.js as was suggested earlier in this thread.

@remkoboschker
Copy link

@bmac The prs #3887 and #3888 do not seem to make any difference. I have spotted a difference with your test project https://github.com/bmac/inflector-test . You are not using the json-api json in your mocks https://github.com/bmac/inflector-test/blob/master/server/mocks/campuses.js also I'm using mirage. Perhaps this helps.

@evandavey
Copy link

Might be related. I am using a polymorphic model (with base class pcbprimitive) . When the type/sub-model is 'pcbvia', the instance is of type pcbprimitive. When I change the type/sub-model to 'pcbviax' it works as expected at the instance is of type 'pcbviax'. So seems like it could be related to the 'a' at the end of the model name. Before I made a backend change, Ember was also asking for model 'pcbvium' whenever it encountered type 'pcbvia'.

@wecc
Copy link
Contributor

wecc commented Oct 22, 2016

Is this problem still present in current versions of Ember/Ember Data?

@christophermlne
Copy link

I will retest.

On Fri, Oct 21, 2016, 8:15 PM Christoffer Persson notifications@github.com
wrote:

Is this problem still present in current versions of Ember/Ember Data?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#3802 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AA9hbVMcxBU3TvnRnDg2yL6hT6z7z4Mrks5q2VWbgaJpZM4GFFNB
.

@stefanpenner
Copy link
Member

This seems to have gone stale, if it is still an issue a reproduction on latest would be great, or even better a failing test.

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

No branches or pull requests

8 participants