Skip to content

Instantly share code, notes, and snippets.

@kenkeiter
Created March 15, 2013 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenkeiter/5173012 to your computer and use it in GitHub Desktop.
Save kenkeiter/5173012 to your computer and use it in GitHub Desktop.
Coffee script nested resources example (may or may not be working -- kind of pseudo-code).
class User extends Spine.Model
url: ->
'/' + @username
collections: ->
unless @collection_klass?
@collection_klass = _.clone(Collection)
@collection_klass.parent = this
@collection_klass
class Collection extends Spine.Model
@parent = null
@url: ->
@parent.url?() + '/collections'
url: ->
@parent.url?() + '/collections/' + my_id
posts: ->
unless @post_klass?
@post_klass = _.clone(Post)
@post_klass.parent = this
@post_klass
class Post extends Spine.Model
@parent = null
@url: ->
@parent.url?() + '/posts'
url: ->
@parent.url?() + '/posts/' + my_id
class Place extends Spine.Model
@url: ->
'/places'
dean = User.fetch(id: 1)
dean.collections().all() # <- All collections
dean.collections.first().posts().all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment