Closed gxxcastillo closed 11 years ago
I haven't been using the 'rel' attribute as a url, but there's nothing prescribing it should be either (like the 'self' link). I just find it too verbose to do so, but that's an api implementor's decision.
If using the backbone collection.get(id) semantics, then using a rel is probably not the correct identifier to use as there is no uniqueness constraint specified for the rel attribute. I think the entity would have to have a property named 'id' to match the backbone collection semantics.
If you are referring to the model.get(attribute) method, then I think that should only apply to properties, and use a getEntity(rel) method to get at the sub-entities. Backbone-relational looks like it follows a similar pattern with it's getRelation()/getRelations() methods.
The closest thing to an id that Siren prescribes is the 'self' link's href attribute.
I agree, the href value is the closest thing to a unique id as specified by Siren. In addition backbone provides its own "cid", and an API implementor may choose to add an "id" property.
Regarding Collections: In the absence of an "id", we currently follow suit with Backbone and a user can get a model from a collection using the model's "cid".
Regarding Models: Before yesterday, sub-entities were direct properties of the bbSiren model, for consistency with Backbone, however, I moved those sub-entities to now be reference-able via .get() just like any other property. I like this because it keeps things simple and there is less to "figure out". What is the benefit of using getRelation()/getRelations() as apposed to just using .get()?
Don't have any practical experience with bbSiren yet, so just keep going as you are and we'll see how it goes when I get around to using it.
There is the .entities() method which filters by className and rel.
You can also use the standard backbone notation: .get() to get an entity by its "name"
A name can be defined by:
a) setting a "name" on the object
b) setting a rel of "name:
Some additional thinking is needed around what name to use when referencing sub-entities from within an entity.
The current solution is to use the "rel" attribute but strip off everything before the last slash. However, this has some limitations since a rel is a "global" relationship definition and identifying a sub-entity should, ideally, be local to the given entity.
Given the example provided on the Siren readme:
I would want to do:
and not: