Using AngularFire, is it possible to create relational style databases? Or access unique identifiers?

I saw this Firebase blog post explaining the best way to create relational data objects using my platform. I am struggling to translate these concepts into AngularFire, their integration with the AngularJS platform.

In particular, I am trying to display two related datasets that have a one-way pointer reference, similar to the way they described this in this example from their post:

var commentsRef = new Firebase("https://awesome.firebaseio-demo.com/comments"); var linkCommentsRef = new Firebase("https://awesome.firebaseio-demo.com/links/comments"); linkCommentsRef.on("child_added", function(snap) { commentsRef.child(snap.name()).once("value", function() { // Render the comment on the link page. )); }); 

Question: Is it possible if the current integration with AngularFile makes pointer-type links to other data objects? And if so, can you give an example?

Edit: I feel that I can solve these problems if I can just access the unique identifiers generated by AngularFire for my data [see below]. How do I access them?

enter image description here

+4
source share
2 answers

Great question!

You need access to unique identifiers, and we recently added a function that will give you access to it through angularFireCollection : https://github.com/firebase/angularFire/pull/26 .

If you use the implicit synchronization method ( angularFire ), then you already have access to the keys, if you specify the 4th argument, which sets the type of the collection to "Object":

 function MyController($scope, angularFire) { var url = 'https://awesome.firebaseio-demo.com/comments'; var promise = angularFire(url, $scope, 'comments', {}); promise.then(function() { var id = '-lw2NDTiZMFvzEWmSnYn'; console.log($scope.comments[id]); }); } 

Hope this helps!

+1
source

Yes, you can access the ID! Use the code below!

 var chru; var ref = new Firebase("https://myapp.firebaseio.com/users/"); var sync = $firebase(ref); var users= syncSelect.$asArray(); $scope.users= users; users.$loaded().then(function() { chru = users.length; }); $scope.specificIdOnSelect = function() { var jj; for (jj = 0; jj < chru; jj++) { var keyer = users.$keyAt(jj); var rec = users.$getRecord(keyer); if ($scope.userSelected== rec.name) { alert("Unique Key of " + $scope.users+ " is " + users.$keyAt(jj)); } } }; $scope.allIds = function() { var jj; for (jj = 0; jj < chru; jj++) { var keyer = users.$keyAt(jj); var rec = users.$getRecord(keyer); alert("Unique Key of " + $scope.users+ " is " + users.$keyAt(jj)); } }; 
0
source

Source: https://habr.com/ru/post/1484004/


All Articles