Hey Cole,

Would it be possible for you to put together a repro of your issue in a
JSFiddle, Plunkr, or CodePen? It's a little hard to figure out how
everything works with just the block of code. The general practice here
would probably be to use $FirebaseArray()
<https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-firebasearray>
on
your /fields/ nodes and overwrite that factory to fetch the data you want
for every new array item. Otherwise, if you want to stick with
$FirebaseObject(), you'll need to work with $watch()
<https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-firebaseobject-watchcallback-context>
which
is less ideal. Hopefully that will get some ideas flowing for you!

Jacob
On Mon, Feb 2, 2015 at 11:41 AM, Cole Pacak wrote:

I've been delving into extending the Angular Fire object factory and am
missing how to call subsequent queries based what is returned from an
initial query.

For example, in data structure below, which I believe I've denormalized,
sites have fields. I'd like to load a site, assign it to scope and then
load the fields that are associated with that site, assigning them to a
separate scope variable.

I was hoping to keep a site and its fields separate in order to avoid
loading data that is at times unnecessary.

Any guidance as to how to structure my factories and their queries would
be really appreciated.

var app = angular.module('myApp', ['firebase']);


app.controller('MyCtrl', function ($scope) {
// load site here as angular fire object
// this works great
$scope.site = SiteFactory('testSite');
// load fields after $scope.site has been resolved
$scope.fieldList = $scope.site.getFieldList();
});


app.factory('SiteFactory', function ($firebase, $FirebaseObject) {
var SiteFactory = $FirebaseObject.$extendFactory({
getFieldList: function() {
var fieldList = [];
angular.forEach(this.fields, function(value, key) {
fieldList.push(FieldFactory(key));
});
return fieldList;
}
});


return function(siteId) {
var ref = new Firebase('
https://flickering-fire-9839.firebaseio.com/').child('sites').child(siteId
<https://flickering-fire-9839.firebaseio.com/>);
var sync = $firebase(ref, { objectFactory: SiteFactory });
return sync.$asObject();
}
});


app.factory('SiteFactory', function ($firebase, $FirebaseObject) {
var FieldFactory = $FirebaseObject.$extendFactory({
// logic to fetch field items here
});


return function(fieldId) {
var ref = new Firebase('
https://flickering-fire-9839.firebaseio.com/').child('fields').child(fieldId
<https://flickering-fire-9839.firebaseio.com/>);
var sync = $firebase(ref, { objectFactory: FieldFactory });
return sync.$asObject();
}
});


Denormalized data structure:
{
"fields" : {
"1a5c6a3e-ae63-4bd8-be6b-ad6944b8db2e" : {
"typeId" : 1,
"weight" : 32
},
"56a72812-8a01-4c20-d9f9-133c32ad3d4c" : {
"typeId" : 1,
"weight" : 29
},
"6403f9c3-bcfb-49b0-bb92-d7433d966182" : {
"typeId" : 2,
"weight" : 33
}
},
"sites" : {
"testSite" : {
"fields" : {
"1a5c6a3e-ae63-4bd8-be6b-ad6944b8db2e" : true,
"56a72812-8a01-4c20-d9f9-133c32ad3d4c" : true,
"6403f9c3-bcfb-49b0-bb92-d7433d966182" : true
},
"header" : {
"bannerUrl" : "
http://www.highinfatuation.com/wp-content/uploads/2012/02/diamond-from-boulders.jpg
",
"logoUrl" : "
http://upload.wikimedia.org/wikipedia/commons/d/d8/Mountain_goat_-_artificial_salt_lick.jpg
",
"title" : "Hey hello there"
}
}
}
}



--
You received this message because you are subscribed to the Google Groups
"Firebase + AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to firebase-angular+unsubscribe@googlegroups.com.
To post to this group, send email to firebase-angular@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/firebase-angular/6753c740-b896-4cc8-97ad-322cd640983d%40googlegroups.com
<https://groups.google.com/d/msgid/firebase-angular/6753c740-b896-4cc8-97ad-322cd640983d%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
To post to this group, send email to firebase-angular@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/CAGcMwsDRLKOHM%3DTvaeFYB9z4eNHYUAhK6peX9_ovhQaP0-gtpg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 2 | next ›
Discussion Overview
groupfirebase-angular @
postedFeb 2, '15 at 9:20p
activeFeb 6, '15 at 3:36a
posts2
users2

2 users in discussion

Jacob Wenger: 1 post Cole Pacak: 1 post

People

Translate

site design / logo © 2021 Grokbase