3

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, …)].

3
  • how are you getting records, and what version of Ember Data? Commented Jan 19, 2014 at 0:13
  • Even on a canary build I'm not seeing it, emberjs.jsbin.com/OxIDiVU/148/edit Commented Jan 19, 2014 at 0:16
  • @kingpin2k I tried with Ember Data 1.0 Beta 4 and Beta 5. I'm using RESTAdapter. Commented Jan 19, 2014 at 8:37

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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).

Comments

0

One more thing to notice is that DS.Store implements modelFor() method which you can use to obtain the Model class based on the given string key.

For example: store.modelFor('post');

I think it's worth using that method since it does other initializations as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.