Active
Project:
Backbone
Version:
7.x-1.x-dev
Component:
JS Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
28 Feb 2012 at 13:31 UTC
Updated:
1 Mar 2012 at 16:53 UTC
Add support for collections based on a given node reference field in a given node. Arguments to constructor would be field name and node id, fetch would load all the nodes which are referred to by that field in that node as a collection.
Question: should these collections be children of NodeModel objects with NodeRef properties?
Comments
Comment #1
smira commentedDefinetly a child. It makes sense semantically and eventually it will be useful to inherit some properties that apply to everything in NodeModel.
Comment #2
ethanw commentedIt looks like we'll be implementing a basic "hasMany" relationship then (which makes sense). I'd think this makes the most sense to represent with a Model that has a Collection as a property to hold the various nodereference nodes.
As a first version, I think we need to provide a Drupal.Backbone.NodeRefCollection object and instructions for using it to represent nodes that had nodereference fields. I've included some pseudocode for what that might look like below. Our NodeRefCollection will likely also need a toJSON method that provides JSON in the correct form for the Drupal server/save routines.
This all begins to get us down the road of content-type specific parse, initialize and toJSON functions. Ultimately, we can construct these somewhat dynamically using behaviors, and give Developers the option of using custom created models or generated per-type model classes. For the initial iteration, however, I think we need to give developers the tools they need to create Backbone models that can hold complex field types.
Comment #3
ethanw commentedFor reference, see the Backbone docs on Nested Models & Collections, which details this pattern and mentions others, as well as the Backbone Nested plugin, from the Backbone.js GitHub wiki page.
Comment #4
smira commentedI like it. This approach is more in line with Drupal's entity and field-entity model.
For example the NodeRefCollection can then be applied to fields attached to Nodes, Users, Taxonomy, etc...
i'm still a bit vague on how all this works, so i'm not able to make educated suggestions on the way it should actually work, but i'm very interested in the project and will continue playing with it etc...
Comment #5
ethanw commented