1

I'm having trouble with a Vue Method that both pushes a new deal to one Firebase ref and sets data in another. The issues lies when the method sets data. My current method is unable to get the key of deal that it is writing to the dealsRef in order to save it in the dealsRel.

Firebase Refs:

// Firebase reference to deals
const dealsRef = db.ref('deals');
// Firebase reference to deal "relations"
const dealsRel = db.ref('dealsRel');

Method:

addDeal() {
  // Push new Deal to Firebase
  dealsRef.push(this.newDeal),
  //Issue is here:
  dealsRel.child(this.newDeal.provider).child( How to get key of object pushed in line above? ).set(true)
},

JSON Structure:

 

deals
    -KjtfMcfuZkP_kKP708x
        provider: "-KQ1if2Zv3R9FdkJz_1_"
        title: "Deal Name"
dealsrel
    -KQ1if2Zv3R9FdkJz_1_" // Provider Firebase ID
        Needs to be "-KjtfMcfuZkP_kKP708x": true //Firebase ID of deal
...

1 Answer 1

2

Was able to solve using Firebase .getKey() like so:

var theKey = dealsRef.push(this.newDeal).getKey()    
dealsRel.child(this.newDeal.provider).child(theKey).set(true)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.