angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Can not push data into a one-to-many relation

Open leandrit1 opened this issue 8 years ago • 5 comments

Hi,

I am trying to accomplish a one to many relationship, for example the user will have many posts, each posts must be saved under its uid, so I am passing the uid to a collection (which does not exist "item") but I think firebase will take care of it and create it once we send it through the push. So, I want to PUSH some data which will belong to the user but the creation of the data is not happening.

import { AngularFireList, AngularFireDatabase} from 'angularfire2/database';

constructor(private afl:AngularFireList, private afdb:AngularFireDatabase) {}

addItem(data, uid) { console.log('Data: ', data, 'UID: ', uid); const itemsRef = this.afdb.list(items/${uid}); itemsRef.push(data); }

I am new to the firebase and hopefully someone can give me a hand here.

Thanks

leandrit1 avatar Apr 17 '18 00:04 leandrit1

Hi xkLander I tested your code and modified the itemsRef for it to work. Also im calling this code from what would be firebase service to handle the request.

addItem(data, uid) {
console.log('Data: ', data, 'UID: ', uid);
const itemsRef = this.afdb.list('items/'+uid);
itemsRef.push(data);
}

Try this instead worked for me.

anasbaddyr avatar Apr 17 '18 08:04 anasbaddyr

Hi Anas, thanks for trying to help but still it is not working :/

leandrit1 avatar Apr 17 '18 09:04 leandrit1

If it doesn't work then my guess would be that there is something wrong with your firebase configuration and not with the code. Good luck!

anasbaddyr avatar Apr 17 '18 09:04 anasbaddyr

Thanks for the help, will look into the configs now.

leandrit1 avatar Apr 17 '18 09:04 leandrit1

Going to close as it's not a bug with the library. Feel free to continue to discuss here.

jamesdaniels avatar May 04 '18 20:05 jamesdaniels