Skip to content

Add support for polymorphic has-many associations #13

@jamesarosen

Description

@jamesarosen

It's possible to "fake" a polymorphic association by using a "class" whose constructor is really a factory method for other classes. Unfortunately, this falls short when the different classes have different parse methods. I suggest the following syntax:

MyBlog.Post = SC.Resource.define({
  comments: {
    type: SC.ResourceCollection,
    itemType: function(json) { return SC.get('MyBlog.%@'.fmt(json.type)); },
    url: '/posts/%@/comments'
  }
})

If itemType is a function, it is called with each of the data objects in turn to get the parser and constructor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions