Updating data in child nodes using EmberFire

32 views
Skip to first unread message

Keith Kelly

unread,
Jun 13, 2016, 10:22:51 AM6/13/16
to Firebase + EmberJS
I am looking to save my user data in my database under the uid that is created when they register.  With the stock code in the Firebase docs you can simply do the following:

firebase.database().ref('users/' + userId).set({
    username
: name,
    email
: email
 
});

How can I save data under a predetermined child node using EmberFire?  When I go to save the data it is generating the id automatically and when I attempt to add the uid to the model call it obviously won't work because that model doesn't exist.

This code creates a new id as expected:

var newAuth = this.store.createRecord('user', {
   username
: name,
   email
: email
});

newAuth
.save().catch(e => {
   console
.log(e.errors);
});


This code fails because the model doesn't exist:

var newAuth = this.store.createRecord('user/' + this.get('session.uid'), {
   username
: name,
   email
: email
});

newAuth
.save().catch(e => {
   console
.log(e.errors);
});

Is there a way to accomplish the latter in EmberFire?



Keith Kelly

unread,
Jun 13, 2016, 10:50:33 AM6/13/16
to Firebase + EmberJS
Never mind I solved my issue.  It is a simple solution.  All I need to do is the id in the store reference like so:

var newAuth = this.store.createRecord('user', {

   id
: this.get('session.uid'),

   username
: name,
   email
: email
});
Reply all
Reply to author
Forward
0 new messages