1
votes

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 a warning

WARNING: Encountered "campus" in payload, but no model was found for model name "campu" (resolved model name using app@serializer:campus:.modelNameFromPayloadKey("campus"))

followed by this 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
  }
}

and 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. I've also tried to move the irregular inflector into the model but am no closer to resolving the issue

I've also tried running the following code in the console before making a call to the store to see what the inflector is set to

var inflector = Ember.Inflector.inflector;
inflector.singularize('campus') // returns "campus"
inflector.pluralize('campus') // returns "campuses"

This issue is extremely frustrating since there doesn't seem to be anyway to resolve it.

1
sorry, forgot to add the adapter type. For the serializer, I'm using the ActiveModelSerializer from github.com/ember-data/active-model-adapter But the application itself uses the RESTAdaptertomoguisuru
inflector.irregular('campus', 'campuses'); is it typo?artych
@Artych, I'm not sure what you mean by 'typo'. The Ember.Inflector.inflector.irregular('campus', 'campuses') should tell Ember that campus is the singular form and it's plural is campuses. This is the expected behavior and is what was happening before updatingtomoguisuru

1 Answers

0
votes

Well, I was able to reproduce this confusing behavior with EmberData-2.0.1 and it looks like a bug in ember-data.

Possible workaround:

//serializers/campus.js
import { ActiveModelSerializer } from 'active-model-adapter';

import Ember from "ember";
import DS from "ember-data";
const { normalizeModelName } = DS;
const { singularize } = Ember.String;

export default ActiveModelSerializer.extend({

  // this is dublication from source but singuralize works as expected
  modelNameFromPayloadKey: function(key) {
    return singularize(normalizeModelName(key));
  }

)};

Link to modelNameFromPayloadKey source code.