ember.js - How to use the hooks offered by Ember Data -


i trying utilize hooks commented on through ember data source code, can't seem implement methods in way called.

i trying use keyforpolymorphictype hook in ds.jsonserializer, a hook can use in serializer subclass customize how polymorphic association's name converted key type. , here how have set up

var jsonserializer = ds.jsonserializer.extend({   keyforpolymorphictype: function(name) {     debugger   } }) var serializer = jsonserializer.create()  ds.restadapter.configure('serverdemo.component', {   alias: 'component' });  serverdemo.adapter = ds.restadapter.extend({   bulkcommit: false   ,serializer: serializer });   serverdemo.store = ds.store.extend({   revision: 12,   adapter:  serverdemo.adapter.create() }); 

if offer guidance on how use hooks sprinkled throughout source, helpful

edit

here models

serverdemo.note = ds.model.extend   title: ds.attr 'string'   content: ds.attr 'string'   index: ds.attr 'number'   noteable: ds.belongsto 'serverdemo.noteable'  serverdemo.noteable = ds.model.extend   note_ids: ds.hasmany 'serverdemo.note'  serverdemo.part = serverdemo.noteable.extend   rack_pos: ds.attr 'number'   server_config_id: ds.belongsto 'serverdemo.serverconfig'   partable: ds.belongsto 'serverdemo.partable', { polymorphic: true }   note_ids: ds.hasmany 'serverdemo.note'   semanticrackpos: (->     "rack_pos_#{this.get('rack_pos')}"   ).property('rack_pos')  serverdemo.partable = ds.model.extend   part_ids: ds.hasmany 'serverdemo.part'  serverdemo.component = serverdemo.partable.extend   back_image: ds.attr 'string'   cols: ds.attr 'number'   rows: ds.attr 'number'   front_image: ds.attr 'string'   name: ds.attr 'string' 

you're on right track. suggest inherit ds.restserializer instead of ds.jsonserializer.

my guess testing code against models don't implement correctly polymorphic association.

take @ test: https://github.com/emberjs/data/blob/master/packages/ember-data/tests/integration/belongs_to_test.js#l119

at top of file, can see how store, adapter, serializer , models set up.

update (after describe models).

one thing pay attention to, rest serializer camelize/decamelize attributes. not doing it. (server_config_id -> serverconfig)

attributes associations have name describes model, not attribute id in json (note_ids -> notes)

you have working that:

serverdemo.note = ds.model.extend   title: ds.attr 'string'   content: ds.attr 'string'   index: ds.attr 'number'   noteable: ds.belongsto 'serverdemo.noteable', {polymorphic: true}  serverdemo.noteable = ds.model.extend   notes: ds.hasmany 'serverdemo.note'  serverdemo.part = serverdemo.noteable.extend   rack_pos: ds.attr 'number'   serverconfig: ds.belongsto 'serverdemo.serverconfig'   partable: ds.belongsto 'serverdemo.partable', {polymorphic: true}   semanticrackpos: (->     "rack_pos_#{this.get('rack_pos')}"   ).property('rack_pos')  serverdemo.partable = ds.model.extend   parts: ds.hasmany 'serverdemo.part'  serverdemo.component = serverdemo.partable.extend   back_image: ds.attr 'string'   cols: ds.attr 'number'   rows: ds.attr 'number'   front_image: ds.attr 'string'   name: ds.attr 'string' 

it unclear me if design looking there no need polymorphic associations. reduce number of models define.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -