0
votes

I'm migrating a serializer to new ember cli modules.

I have a function that uses underscore, pluralize, and some find method of enumerable utils, but they are not current available inside the module.

How do you enable or import this to be accesible from my serializer?

import DS from 'ember-data';

function findGroupableItem(item, payload){
   var associationKey = item.groupable_type.underscore().pluralize();
   return payload[associationKey].find(function(object){
       return object.id === item.groupable_id;
   });
};

export default DS.ActiveModelSerializer.extend({
     extract: function(store, type, payload, id, requestType){
          //do something with findGroupableItem
     }
});
1

1 Answers

-1
votes

You could just use the Ember.String functions:

import Ember from 'ember';
import DS from 'ember-data';

const { String: { pluralize, underscore } };

And your code becomes:

let associationKey = pluralize(underscore(item.groupable_type));