lundi 22 mai 2017

createRecord with custom ID in emberjs 2.x and Firebase 3.x

Until now, I saved all my data with the following line of code:

saveUser(params) {
      let newUser = this.store.createRecord('user', params);
      newUser.save();
      this.transitionTo('index');

This worked fine, but didn't allow for custom ID's in firebase, so I changed it into:

saveUser(params) {
      let newUser = this.store.createRecord('user', {
        id: params.loginId,
        name: params.name,
        nickname: params.nickname,
        imageUrl: params.imageUrl,
        email: params.email
      });
      newUser.save();
      this.transitionTo('index');

Processes them exactly as I want them to be stored on the Firebase database, so no problem there. I'm wondering though, and not finding any solution on the web, how I can combine the two, so that I don't have to bind every param. It's bound to give problems when I add/remove model properties. Something I'm looking for would look like this (pseudo, yes I tried it, didn't work!):

let newUser = this.store.createRecord('user', {id: params.loginId}, params);

In short, I'm looking for the dynamic properties of ('model', params), but with the option to manually adjust 1 (or more) records without having to type out all of the params.

Thanks in advance !




Aucun commentaire:

Enregistrer un commentaire