Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

using a linked sub-entity collection #11

Closed
apsoto opened this Issue Mar 25, 2013 · 4 comments

Comments

Projects
None yet
2 participants
Contributor

apsoto commented Mar 25, 2013

I've been designing my API to use linked sub-entities for collections so the main response isn't too bloated.
For example:

{
...
entities:[
{
"rel": [ "follows", "collection" ],
"href": "http://api.wurl.dev/api/users/1/follows",
}
],
...
}

It looks like bbSiren assumes a sub-entity with rel 'collection' is a collection of full entity representations, so in my app the collection is empty?

I think that bbSiren should handle a 'collection' entity that is either full or linked. I'll problably implement that and send a pull request, but I wanted to get your input on what your use cases are like for collection sub-entites.

Contributor

apsoto commented Mar 25, 2013

hmm, I may be misunderstanding how things work. I was retrieving the .entities() method that was empty, but I see that if I .get(entity) I get the collection.

I then called fetch() on the collection, but I'm now troubleshooting to see how/why that doesn't look like what I expected.

Contributor

uglymunky commented Mar 26, 2013

I think you will have to set the autoFetch property on your options to "linked". I think the default was to not auto fetch...

Contributor

uglymunky commented Mar 26, 2013

ah, now I'm remembering, wrt collections, to try and be more in line with Backbone Collections, they don't have "attributes" and instead have "meta".

By doing it this way you can use the standard Backbone.Collection .set() and .get() to get and set models on the collections. I haven't fully flushed this out yet...

Contributor

uglymunky commented Jun 29, 2013

This should be working.

A parent entity can reference a child entity that is a collection by doing:

var myCollection = parent.get('myCollection');

You can then do anything you can do with a normal backbone collection, including getting the full collection object when all you have is a linked entity:

myCollection.fetch()

If you have properties on the collection's entity object, those properties will be stored as "meta" on the bbSiren collection:

// To get meta (setting meta is not supported)
myCollection.meta()

@uglymunky uglymunky closed this Jun 29, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment