maccman/spine — pull request #302 by andypetrella (2012-05-14 19:49:37+00:00)
Title: Having sub embed collections support

Hello,

Here is a try to have the support of embed collections in ajax url patterns.

You know like
/users/{userId}/children/{childId}

I tried to have Ajax.getURL to take an extra parameter that is the context of the "url" buildling.

Having that, the "url" overriden property (either on the Class or the Instance) can be a function that takes the context.

So that, while buildling an url you can rely on this new parameter like that

class Child extends Spine.Model
@configure "Child", "name"

@belongsTo 'parent', 'models.User'

@extend Spine.Model.Ajax

@url: (params) => "/rest/users/" + (
if params?.parent? ######### THE GIVEN CONTEXT IS THE PARENT => useful when all is called
encodeURIComponent(params.parent().id) + "/"
else if params?.id? ######### THE GIVEN CONTEXT IS THE CURRENT ITEM => useful when instance.url() is called
encodeURIComponent(params.id) + "/"
else
"" ######### NO CONTEXT
) + "children"

What do you think ?

thanks for your advices

andy