ember-rapid-forms
ember-rapid-forms copied to clipboard
Use em-select to fill a hasMany
Let's say that a user should choose his favorite artist, yet, we're not going to use the name but rather a reference to another artist.
{{em-select
label="Artist"
property="artist"
content=artists
optionValuePath="id"
optionLabelPath="name"
prompt="Who's your favorite artist?"
}}
So, we have // models/artist.js export default Model.extend({ name: attr('string') })
// models/user.js export default Model.extend({ artists: hasMany('artist', { embedded: 'always', async: true }) });
Now, if I pass store.findAll('artist') to the dropdown, and try to update it, we will get the following: Assertion Failed: You must pass an array of records to set a hasMany relationship
How can I make it work if I want to update a relationship on an object instead of just a value? Preferably what I would want in this example is to either overwrite the list entirely by the selected dropdow, or append to it.
Hi and sorry for the late answer (I forgot you).
Can you try to use propertyIsModel=true
attribute? You will have something like :
{{em-select
label="Artist"
property="artist"
content=artists
optionValuePath="id"
optionLabelPath="name"
prompt="Who's your favorite artist?"
propertyIsModel=true
}}
I think it will work.
No luck.
I created a repo for it: https://github.com/flyrev/ember-rapid-forms-select-hasMany
For a quick workaround (for belongsTo)
artistId: Ember.computed({
get: function() {
return this.get('artist.id');
},
set: function(key, value) {
if(value){
this.set('artist', this.store.peekRecord('artist', value));
}
return value;
}
}),
I gonna look a little further into it to find out how to do this the best way.