Created
May 12, 2015 19:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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