Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Questions about model associations

$
0
0
The only thing I can get to work is a hasMany. Let's say I have a object model like so

Book hasMany Chapters
  1. Book = can.Model "Book", {
  2.       ...
  3.       attributes:
  4.             chapters: "Chapter.models"
  5.        }, {}
  6. Chapter = can.Model "Chapter", {
  7.       ...
  8.       attributes:
  9.             book: "Book.model"
  10.        }, {}
I provide the json for a book with the chapters embedded and it works fine. But I don't have chapterInstance.book. I have tried adding a book_id to the chapter json, but this doesn't help and I really don't like doing that. What am I doing wrong?

Finally, I find the example in the docs quite confusing, as it sets the attributes on a can.Observe instance, in a declaration that I haven't really seen before. Is this a typo or am I missing something?

Viewing all articles
Browse latest Browse all 3491

Trending Articles