I am currently working on incorporating AngularFire into my Google Firebase Ionic app, and I am encountering difficulties with the database structure and its implementation.
My objective is to have users in the database along with basic information such as their name and email address.
Each user should have the ability to add friends, who will be stored in a list. What is the most effective way to achieve this in the Firebase Database? Should users have a node for their friend list that contains references to other user IDs?
For example:
User
User1
Name
Email
Friends
Friend1
Friend2
Alternatively, should there be a separate "friendships" tree with nodes connecting two user IDs to establish friendships?
Friendships
Friendship1
User1
User2
Friendship2
etc...
In addition, based on the first approach I mentioned and have already implemented, I retrieve my friends using the following method:
var friendsRef = firebase.database().ref('users/' + firebase.auth().currentUser.uid + '/friends');
$scope.friends = $firebaseArray(friendsRef);
While this method works well, the challenge arises when attempting to retrieve additional data associated with each friend, such as their name and email from their respective database locations.
I would greatly appreciate any suggestions or guidance to help me navigate through this issue, as I have been grappling with it for quite some time now. Thank you!