Created
March 15, 2013 20:49
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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