fetch vs get

25 views
Skip to first unread message

Matt J

unread,
Jul 12, 2015, 12:00:37 AM7/12/15
to der...@googlegroups.com
Hi,
   Just out of curiosity. I have two different possibilities in code:
       
  model.on('change','users.'+userId+".contacts.*.unread", function(contactId,unread) {
      var contacts = model.get('users.' + userId+".contacts");
      var unreadContacts = [];
      var total = 0;
      for(var contact in contacts){
        total+= model.get('users.' + userId+".contacts."+contact+".unread");
        unreadContacts.push(model.get("users."+userId+".messages."+contact));
      }
      model.set("_page.totalUnread", total);
      model.set("_page.unreadContacts", contacts);
    });


Or I could wrap the code in a fetch, does it matter? Does it only do one database call in the fetch scenario? Thanks.

  model.on('change','users.'+userId+".contacts.*.unread", function(contactId,unread) {
       model.fetch("users."+userId, function(err){
           .... above code
       });
    });

Matt J

unread,
Jul 12, 2015, 8:05:35 AM7/12/15
to der...@googlegroups.com
Nvm... I am new to derbyjs, I see I need a fetch otherwise I can't get the data in the first place (there was a different fetch happening on the page that allowed the data to be there).

Out of curiosity, I want the model.change code to run once on page load and then every time on the change, is there a way to do that? Currently I havecopied the code in from of the model.change as well.

I tried putting it in a method, but then I lost the model object somehow. any ideas?
Reply all
Reply to author
Forward
0 new messages