Spine.js relations questions (controllers, and destroying children when destroying the parent)

259 Views Asked by At

I'm trying to figure out how relations work with regards to controllers; the relations documentation is pretty thin and doesn't touch on this. I'm modelling Categories and Links; each Category can have many links associated with it, and each Link must belong to a Category.

Here's a jsFiddle with a basic example: http://jsfiddle.net/grahamb/pTEvj/

First, I'm not entirely sure I have my controllers set up properly. The rest of my app is using the "element pattern" as described in the docs, so I've tried to do the same here. I have a Categories controller that handles creating new Categories, and a CategoriesItem controller manages the individual categories (updates, destroys, etc). The same goes for the Link model; it has a Links controller and a LinksItem controller. When I instantiate a new Categories controller, it creates a new Links controller to go with it.

I'm having an issue with binding to the destroy event on LinksItem; my destroy() function isn't firing when the button is clicked. It appears to be a DOM element scope issue; I can't see my delete button's element from within this.el inside the controller. I'm not sure how to resolve this.

Finally, a question about destroying a parent. When I call destroy on a Category model, it orphans the associated Link models. Right now I'm manually destroying the Link models when the destory is called on the Category - is this the right way to do it? This issue on GH suggests that there's nothing built-in to take care of this: https://github.com/maccman/spine/issues/291

0

There are 0 best solutions below