Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use em-select to fill a hasMany #122

Open
flyrev opened this issue Jun 30, 2016 · 3 comments
Open

Use em-select to fill a hasMany #122

flyrev opened this issue Jun 30, 2016 · 3 comments

Comments

@flyrev
Copy link
Contributor

flyrev commented Jun 30, 2016

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.

@GCorbel
Copy link
Contributor

GCorbel commented Jul 4, 2016

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.

@flyrev
Copy link
Contributor Author

flyrev commented Jul 5, 2016

No luck.

I created a repo for it: https://github.com/flyrev/ember-rapid-forms-select-hasMany

@spruce spruce added the bug label Jul 5, 2016
@spruce
Copy link
Member

spruce commented Aug 3, 2016

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.

@spruce spruce added enhancement and removed bug labels Oct 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants