local-ch / lhs

⚛️ REST services accelerator: Rails gem providing an easy, active-record-like interface for http (hypermedia) json services
GNU General Public License v3.0
137 stars 3 forks source link

`.includes()` does not care about `has_one`-relation #389

Open ryabrody opened 4 years ago

ryabrody commented 4 years ago

When we have following structure:

{
  "href": "http://api.test/localch-accounts/p62qM5p0NK_qryO52Ze",
  "id": "p62qM5p0NK_qryO52Ze",
  ...
  "language": "de",
  "created_date": "2015-06-30T09:54:59.858+02:00",
  "claims": {
    "href": "http://api.test/localch-accounts/p62qM5p0NK_qryO52Ze/claims",
    "items": [
      {
        "href": "http://api.test/localch-accounts/p62qM5p0NK_qryO52Ze/claims/A00OhenWd_Z5RWnxDE7mqA",
        "localch_account": {
          "href": "http://api.test/localch-accounts/p62qM5p0NK_qryO52Ze"
        },
        "place": {
          "href": "http://api.test/places/A00OhenWd_Z5RWnxDE7mqA"
        },
   ...
}

Then one claim can have one place. When we now use include:

User.includes([claims: :place]).find('p62qM5p0NK_qryO52Ze')

LHS does not know if the relation between claims and place is singular it always presumes that the relation is plural and requests the first brach of places with:

GET http://api.test/places/A00OhenWd_Z5RWnxDE7mqA?limit=100

As the relation between place and claims is singular i would expect that LHS requests the place as following:

GET http://api.test/places/A00OhenWd_Z5RWnxDE7mqA

LHS should not do limit=100 when in the model thehas_one relation explicitly is set as described here: https://github.com/local-ch/lhs#has_one.