Skip to content

Instantly share code, notes, and snippets.

@katowulf
Created May 12, 2015 19:50
Show Gist options
  • Save katowulf/f2e19f656536c0279303 to your computer and use it in GitHub Desktop.
Save katowulf/f2e19f656536c0279303 to your computer and use it in GitHub Desktop.
Firebase: Join an index of companies a user belongs to the data for the companies and display the results
var fb = new Firebase('https://<INSTANCE>.firebaseio.com');
var idxRef = fb.child('users/kato/companies');
var dataRef = fb.child('companies');
idxRef.on('child_added', function(userSnap) {
dataRef.child(userSnap.key()).once('value', function(snap) {
console.log('user ' + userSnap.key() + ' belongs to company ' + snap.key());
});
});
var fb = new Firebase('https://<INSTANCE>.firebaseio.com');
var dataRef = Firebase.util.NormalizedCollection(
[fb.child('users/kato/companies'), 'idx'],
[fb.child('companies'), 'company']
)
.select(
{key: 'idx.$key', alias: 'uid'},
'company.name'
)
.ref();
dataRef.on('child_added', function(snap) {
var data = snap.val();
console.log('user ' + data.uid + ' belongs to company ' + data.name);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment