How to create records in ember data without using store?


#1

I’m fetching a list of video channels from API that’s used to create navigation bar. I also have Video model that has embedded channels that it belongs to - these channels don’t necessary have to be the same as those returned by API for the nav bar. The issue is that ember data puts all channels into a single bucket (identity map), so if I use store.find('channel') to get channels for nav bar and later I fetch a video that has some other embedded channels, the list of channels in the nav bar changes.

Is there any easy way to make the list of channels fetched from API “immutable”? I was thinking about using plain $.ajax to avoid going through the store, but I can’t create records directly, only through store.createRecord('channel', data), which is exactly what I’m trying to avoid.

Currently I simply have ArrayController that has content property set to store.find('channel').


#2

Have you looked into the filter method for ember-data? This would allow you to be selective with regards to what model elements you would like returned. The filter also responds to changes in to the store.


#3

Thanks, but I’d actually prefer to have an immutable list of records that doesn’t respond to any changes :slight_smile: For now I simply make jQuery.ajax call and map received objects to Ember.Object. It sucks, so I’m thinking about creating another model like MenuChannel (but with a better name) that would have exactly the same properties like a normal channel, but ember-data would put it into a different basket, thus it wouldn’t be affected by other channels in the store.