Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referencing an entities sub-entities #4

Closed
gxxcastillo opened this issue Feb 26, 2013 · 4 comments
Closed

Referencing an entities sub-entities #4

gxxcastillo opened this issue Feb 26, 2013 · 4 comments
Labels
Milestone

Comments

@gxxcastillo
Copy link
Contributor

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:

order.get('items')

and not:

order.get('order-items')
@apsoto
Copy link
Contributor

apsoto commented Feb 26, 2013

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.

@gxxcastillo
Copy link
Contributor Author

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()?

@apsoto
Copy link
Contributor

apsoto commented Feb 26, 2013

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.

@gxxcastillo
Copy link
Contributor Author

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:'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants