I would like to use ember routes and models to build some "ambitious" web apps.
Here's what I'm trying to do. I have a book and author model. While showing a list of author resources, if the user clicks on an author, display via a nested route all the books by that author. So I'd like to treat the author id (or name) as the dynamic segment to pass to the book model. But there seems to be a limitation whereby dynamic segments must be the primaryKey of the current model, no other model attributes or models can be used.
Do I need to write a custom de/serializer? If so, an example fiddle applicable to this scenario would be much appreciated.
Here is some example code describing what i'm trying to do, with specific questions appearing in comments.
Authors.hbs template
<div class="span3">
<h4>Books</h4>
<ul class="unstyled">
{{#each model}}
{{#linkTo 'authors.books' this}}<li>
{{name}} <small>{{date dob}}</small> <small> {{origin}}</small>
</li>{{/linkTo}}
{{/each}}
</ul>
</div>
<div class="span8">
{{outlet}}
</div>
initialize.coffee
@resource 'books', ->
@resource 'book', {path: ':cube_id'}
@resource 'authors', ->
@resource 'AUTHOR', {path: ':AUTHOR_id'}
# QUESTION How to make the next line retrieve books-by-author from the book model?
@route 'books', {path: '/books/:author_id'}
AuthorRoute
module.exports = App.AuthorsRoute = Em.Route.extend
model: ->
App.Author.find()
BookRoute
module.exports = App.BooksRoute = Em.Route.extend
model: ->
App.Book.find()
# QUESTION How should the model be extended to allow for lookup by attribute?
# model: (params) ->
# App.Book.find { author: params.book_id }
Author model
module.exports = App.Author = DS.Model.extend
name: DS.attr 'string'
origin: DS.attr 'string'
dob: DS.attr 'date'
Book model
module.exports = App.Book = DS.Model.extend
name: DS.attr 'string'
author: DS.attr # QUESTION How to wire together models here?
#author: DS.belongsTo 'App.Author'
publisher: DS.attr 'string'
published: DS.attr 'date'