Associations and hierarchical data

10 views
Skip to first unread message

jrfeenst

unread,
Oct 5, 2010, 11:06:56 AM10/5/10
to JavaScriptMVC
I'm looking to implement hasMany and belongsTo type of associations. I
saw the jquery/model/association plugin and I'm curious if there are
any examples beyond the test cases? I'm specifically looking at doing
some lazy loading of a hierarchical data structure (basically a
filesystem).

Any other suggestions on implementing a hierarchical model while
providing for lazy loading?

Thanks,
Joel

Justin Meyer

unread,
Oct 5, 2010, 11:45:32 AM10/5/10
to javasc...@googlegroups.com
Joel,
  I'm almost done writing up the model plugin, but I haven't quite finished it b/c the model layer is almost impossible to write up all use cases, including this one.  

  The associations are typically used for the opposite of lazy-loading -> loading a instance with its associations at one time.

  My guess is that you want to get a file and open it's children.  I don't think you need associations for this.  What you probably want is something like:

$.Model.extend("Entry",{

},{
  children : function(success, error){
   var self = this;
    if(this._children){
      success(this._children);
    }else{
      this.Class.findAll({parentId: this.id}, function(entries){  
        self._children = entries;
        success(entries);
     })
    }
  }
})



Justin Meyer

Jupiter Consulting
\Development\Training\Support
847-924-6039
justin...@gmail.com



--
You received this message because you are subscribed to the Google Groups "JavaScriptMVC" group.
To post to this group, send email to javasc...@googlegroups.com.
To unsubscribe from this group, send email to javascriptmv...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javascriptmvc?hl=en.


Reply all
Reply to author
Forward
0 new messages