How to express relationships which are an attribute of an embedded document?


Lets assume my primary resource is a classifier, whose model is as such:

Classifier {
    name: string
    match {
       user: User <-- relationship
       date: datetime

Having user and date under match is strictly semantics - they could just have well been called match_user and match_date, and my question would be void.

My question is - should I GET /classifiers and wish to include their match’s user - should I use ?include=match.user? Should it appear as match.user under relationships? This is the most consistent way of doing things, though would slightly strain the API provider since it would have to understand that match is not a relationship, rather an embedded document.


For now, your best options are to either make a match a separate resource, and then have a match relationship pointing on Classifier, or (less elegant) to split up the match fields, and put match_date as an attribute and match_user as a relationship.

For more cohtext on this limitation, and some of the efforts to change it (which are still ongoing but paused for the moment), see issue #383 and its precursor #238


Thanks, Ethan. In this specific case creating a relationship is wasteful and adds unnecessary complexity at the model level (Classifiers will never share matches). Will have to go with match_user, match_date.


Ok, glad at least something works! Hopefully we’ll get a more elegant solution to this soon :slight_smile: