{"action":"created","issue":{"url":"https://api.github.com/repos/feathers-plus/feathers-hooks-common/issues/420","repository_url":"https://api.github.com/repos/feathers-plus/feathers-hooks-common","labels_url":"https://api.github.com/repos/feathers-plus/feathers-hooks-common/issues/420/labels{/name}","comments_url":"https://api.github.com/repos/feathers-plus/feathers-hooks-common/issues/420/comments","events_url":"https://api.github.com/repos/feathers-plus/feathers-hooks-common/issues/420/events","html_url":"https://github.com/feathers-plus/feathers-hooks-common/pull/420","id":345182260,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA0Mzk4MDY4","number":420,"title":"Added `keepInArray` hook to keep fields from a nested array","user":{"login":"dekelev","id":4444781,"node_id":"MDQ6VXNlcjQ0NDQ3ODE=","avatar_url":"https://avatars2.githubusercontent.com/u/4444781?v=4","gravatar_id":"","url":"https://api.github.com/users/dekelev","html_url":"https://github.com/dekelev","followers_url":"https://api.github.com/users/dekelev/followers","following_url":"https://api.github.com/users/dekelev/following{/other_user}","gists_url":"https://api.github.com/users/dekelev/gists{/gist_id}","starred_url":"https://api.github.com/users/dekelev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dekelev/subscriptions","organizations_url":"https://api.github.com/users/dekelev/orgs","repos_url":"https://api.github.com/users/dekelev/repos","events_url":"https://api.github.com/users/dekelev/events{/privacy}","received_events_url":"https://api.github.com/users/dekelev/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-07-27T10:53:58Z","updated_at":"2018-08-04T20:11:43Z","closed_at":"2018-08-04T19:51:00Z","author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/feathers-plus/feathers-hooks-common/pulls/420","html_url":"https://github.com/feathers-plus/feathers-hooks-common/pull/420","diff_url":"https://github.com/feathers-plus/feathers-hooks-common/pull/420.diff","patch_url":"https://github.com/feathers-plus/feathers-hooks-common/pull/420.patch"},"body":"### Problem\r\nThe `keep` hook does a great job for its intended purpose, but it won't work for nested arrays. for example, finding a record with one-to-many or many-to-many ORM relations.\r\n\r\n### Solution\r\nThis new `keepInArray` hook works like `keep`, but it accepts 2 arguments. the first is a dot notation string type field and the second is an array of field names to keep from it.\r\n\r\n### Usage\r\n\r\nData structures:\r\n```js\r\n{ \r\n  users: [\r\n    {\r\n      name: 'John',\r\n      secret: 'doNotKeep',\r\n      dept: 'Accounting',\r\n      address: {\r\n        city: 'New York',\r\n        secret: 'doNotKeep'\r\n      }\r\n    }\r\n  ],\r\n  owner: 'Jane Doe'\r\n}\r\n\r\n{\r\n  account: {\r\n    users: [\r\n      {\r\n        name: 'John',\r\n        secret: 'doNotKeep',\r\n        dept: 'Accounting',\r\n        address: {\r\n          city: 'New York',\r\n          secret: 'doNotKeep'\r\n        }\r\n      }\r\n    ],\r\n    owner: 'Jane Doe'\r\n  }\r\n}\r\n```\r\n\r\nUsing hook:\r\n``` js\r\nconst { keepInArray } = require('feathers-hooks-common');\r\n    \r\nmodule.exports = { after: {\r\n  create: keepInArray('users', ['name', 'dept', 'address.city']),\r\n  find: keepInArray('account.users', ['name', 'dept', 'address.city']),\r\n} };\r\n```\r\n\r\nData structures after using hook:\r\n```js\r\n{ \r\n  users: [\r\n    {\r\n      name: 'John',\r\n      dept: 'Accounting',\r\n      address: {\r\n        city: 'New York'\r\n      }\r\n    }\r\n  ],\r\n  owner: 'Jane Doe'\r\n}\r\n\r\n{\r\n  account: {\r\n    users: [\r\n      {\r\n        name: 'John',\r\n        dept: 'Accounting',\r\n        address: {\r\n          city: 'New York'\r\n        }\r\n      }\r\n    ],\r\n    owner: 'Jane Doe'\r\n  }\r\n}\r\n```\r\n\r\nAdded tests and [PR](https://github.com/feathers-plus/docs/pull/43) to the feathers-plus docs."},"comment":{"url":"https://api.github.com/repos/feathers-plus/feathers-hooks-common/issues/comments/410474670","html_url":"https://github.com/feathers-plus/feathers-hooks-common/pull/420#issuecomment-410474670","issue_url":"https://api.github.com/repos/feathers-plus/feathers-hooks-common/issues/420","id":410474670,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMDQ3NDY3MA==","user":{"login":"eddyystop","id":1553311,"node_id":"MDQ6VXNlcjE1NTMzMTE=","avatar_url":"https://avatars3.githubusercontent.com/u/1553311?v=4","gravatar_id":"","url":"https://api.github.com/users/eddyystop","html_url":"https://github.com/eddyystop","followers_url":"https://api.github.com/users/eddyystop/followers","following_url":"https://api.github.com/users/eddyystop/following{/other_user}","gists_url":"https://api.github.com/users/eddyystop/gists{/gist_id}","starred_url":"https://api.github.com/users/eddyystop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddyystop/subscriptions","organizations_url":"https://api.github.com/users/eddyystop/orgs","repos_url":"https://api.github.com/users/eddyystop/repos","events_url":"https://api.github.com/users/eddyystop/events{/privacy}","received_events_url":"https://api.github.com/users/eddyystop/received_events","type":"User","site_admin":false},"created_at":"2018-08-04T20:11:43Z","updated_at":"2018-08-04T20:11:43Z","author_association":"MEMBER","body":"Published as 4.16.0"}}
{"actor":{"display_login":"eddyystop"}}