Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model#typeKey undefined when using Ember Data 1.0 Beta

Tags:

ember.js

I'm trying to update my Ember.js app to Ember Data 1.0 Beta. What I have is working with Ember Data 0.14. With the new version I need to manually set typeKey for a model in order for the REST request to have proper path.

I have simple model:

App.Product = DS.Model.extend
name: DS.attr('string')

In Ember Data 1.0 Beta I need to add this in order to get it to work:

App.Product.typeKey = 'product'

Otherwise buildURL method always get passed undefined [buildURL(type.typeKey, …)].

like image 764
iRonin Avatar asked Aug 01 '26 01:08

iRonin


2 Answers

I ran into an issue very similar to this just yesterday. For some reason, I was able to get the typeKey for one of my models, but not the other three. It seemed like some kind of issue with the application not being fully loaded or ready. After the page loaded, I was able to get the typeKey for all four models just fine. See if you can't get the same result. I just had to rearrange a bit of my code to make it work correctly. Hopefully you can do the same.

like image 199
GJK Avatar answered Aug 03 '26 15:08

GJK


The problem was caused by using model class instead of its string name in store finder method:

Should be @store.find('product') instead of @store.find(App.Product).

like image 23
iRonin Avatar answered Aug 03 '26 15:08

iRonin