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

Which hook to use? #436

Closed
musicformellons opened this issue Sep 3, 2018 · 4 comments
Closed

Which hook to use? #436

musicformellons opened this issue Sep 3, 2018 · 4 comments

Comments

@musicformellons
Copy link
Contributor

After a discard and a keepInArray hook I get this result:

{
  "total": 1,
  "limit": 100,
  "skip": 0,
  "data": [
    {
      "point_id": 1,
      "city": "test",
      "PointPhotos": [
        {
          "photo": {
            "photo_id": 4,
            "user_id": 1,
            "url": "test",
            "created_at": "2018-09-03T11:14:09.355Z",
            "updated_at": "2018-09-03T11:14:09.355Z"
          }
        },
        {
          "photo": {
            "photo_id": 2,
            "user_id": 2,
            "url": "test",
            "created_at": "2018-09-03T11:14:09.275Z",
            "updated_at": "2018-09-03T11:14:09.275Z"
          }
        }
      ]
    }
  ]
}

How can I get rid of the photo keys, so I end up with this?:

{
  "total": 1,
  "limit": 100,
  "skip": 0,
  "data": [
    {
      "point_id": 1,
      "city": "test",
      "PointPhotos": [
        {
		"photo_id": 4,
		"user_id": 1,
		"url": "test",
		"created_at": "2018-09-03T11:14:09.355Z",
		"updated_at": "2018-09-03T11:14:09.355Z"
        },
        {
		"photo_id": 2,
		"user_id": 2,
		"url": "test",
		"created_at": "2018-09-03T11:14:09.275Z",
		"updated_at": "2018-09-03T11:14:09.275Z"
        }
      ]
    }
  ]
}
@eddyystop
Copy link
Collaborator

That is a rather unusual special need. You'll have to write your own hook for it, which would be straightforward.

@musicformellons
Copy link
Contributor Author

This is more of a background, so maybe not uncommon as I think may people shy away from using belongsToMany join tables using sequelize.

@eddyystop
Copy link
Collaborator

eddyystop commented Sep 3, 2018

The alterItems hook may be of use to you. You can reformat records as you want with it. https://feathers-plus.github.io/v1/feathers-hooks-common/#alteritems

@musicformellons
Copy link
Contributor Author

Thanks. You were right, though. This can and should be solved in Sequelize (which I use).

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

No branches or pull requests

2 participants