ember.js - Ember data: side-loading hasMany relationship using a non-id field -


i wondering if can side-load hasmany relationship in ember-data - hooked on non-id column. here code snippets-

app.profile = ds.model.extend({     firstname: ds.attr(),     lastname: ds.attr(),     photo: ds.hasmany('photo', {async:true}) });  app.photo = ds.model.extend({     path: ds.attr('string'),     title: ds.attr('string'),     owner: ds.belongsto('user', {async:true}), });   app.profileserializer = ds.restserializer.extend({     attrs:{         photo: {embedded: 'load'}     }, }); 

the json returned localhost:/api/profiles/ is:

[     {         "photos": [             "media/pic3.jpeg",              "media/pic4.jpeg"         ],          "id": "5441b6b2bc8ae304d4e6c10e",          "first_name": "dave",          "last_name": "gordon",          "profile_pic": "media/profilepic.jpg",          "member_since": "2014-01-03t00:00:00",          "membership": "silver",          "theme_pic": "media/profilepic.jpg"     } ] 

as see here, trying hook photos using 'path' field of photo instead of id of photos. can't seem ember send async call. possible tell ember make async call based off of non-id field. feel there should way coz intend send async call based off of custom generated key. appreciated. thank you

i wouldn't think of association, rather property type of array.

you should able change model this:

app.profile = ds.model.extend({     firstname: ds.attr(),     lastname: ds.attr(),     photos: ds.attr() }); 

then should able access property array (possible object) in template.

if necessary, might need create custom transform this:

app.arraytransform = ds.transform.extend({     deserialize:function(value) {        return value;     } }); 

then can do:

app.profile = ds.model.extend({     firstname: ds.attr(),     lastname: ds.attr(),     photos: ds.attr('array') }); 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -