json-server icon indicating copy to clipboard operation
json-server copied to clipboard

Pluralization of relationships

Open jonathanchris opened this issue 11 years ago • 4 comments

I've got a relationship where:

{
  families: [
    { id: 1, name: 'Stevens' }
  ],
  users: [
    { id: 1, name: 'Jon', familyId: 1 }
  ]
}

This doesn't work because of the pluralization of the word families. users would need to have familieId: 1 for this to work. Is there a way to map or customize this?

jonathanchris avatar May 20 '15 19:05 jonathanchris

It's a bug. The project is using https://github.com/geetarista/underscore.inflections especially for this case. But somehow, this feature must have been lost in refactoring.

It's still used though to clean orphans (for examples, if family 1 is deleted, users 1 should be too)

I'll fix that.

PS: nice avatar :)

typicode avatar May 20 '15 21:05 typicode

Awesome, good to know.

I was thinking I could get around it by calling my families property familys and then adding a redirect for the route:

server.use('/families/:id', function (req, res) {
  res.redirect('/familys/' + req.params.id)
});

BTW Thanks for the awesome work, you just saved me a huge amount of time. I'm using this to setup a mock service layer for my project. :hammer:

jonathanchris avatar May 21 '15 00:05 jonathanchris

You're welcome. I'm very happy if my projects can help :) Just released v0.7.9 with the fix. It should be good now.

typicode avatar May 22 '15 00:05 typicode

Closing, feel free to reopen/add if you see other problems.

typicode avatar May 25 '15 13:05 typicode