{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback/issues/2075","repository_url":"https://api.github.com/repos/strongloop/loopback","labels_url":"https://api.github.com/repos/strongloop/loopback/issues/2075/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback/issues/2075/comments","events_url":"https://api.github.com/repos/strongloop/loopback/issues/2075/events","html_url":"https://github.com/strongloop/loopback/issues/2075","id":134179569,"number":2075,"title":"How can I Implement recursive join using loopback self relations?","user":{"login":"katherdx","id":11048401,"avatar_url":"https://avatars.githubusercontent.com/u/11048401?v=3","gravatar_id":"","url":"https://api.github.com/users/katherdx","html_url":"https://github.com/katherdx","followers_url":"https://api.github.com/users/katherdx/followers","following_url":"https://api.github.com/users/katherdx/following{/other_user}","gists_url":"https://api.github.com/users/katherdx/gists{/gist_id}","starred_url":"https://api.github.com/users/katherdx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/katherdx/subscriptions","organizations_url":"https://api.github.com/users/katherdx/orgs","repos_url":"https://api.github.com/users/katherdx/repos","events_url":"https://api.github.com/users/katherdx/events{/privacy}","received_events_url":"https://api.github.com/users/katherdx/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/strongloop/loopback/labels/triage","name":"triage","color":"eb6420"}],"state":"open","locked":false,"assignee":{"login":"jannyHou","id":12554153,"avatar_url":"https://avatars.githubusercontent.com/u/12554153?v=3","gravatar_id":"","url":"https://api.github.com/users/jannyHou","html_url":"https://github.com/jannyHou","followers_url":"https://api.github.com/users/jannyHou/followers","following_url":"https://api.github.com/users/jannyHou/following{/other_user}","gists_url":"https://api.github.com/users/jannyHou/gists{/gist_id}","starred_url":"https://api.github.com/users/jannyHou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jannyHou/subscriptions","organizations_url":"https://api.github.com/users/jannyHou/orgs","repos_url":"https://api.github.com/users/jannyHou/repos","events_url":"https://api.github.com/users/jannyHou/events{/privacy}","received_events_url":"https://api.github.com/users/jannyHou/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2016-02-17T05:02:14Z","updated_at":"2016-02-18T22:14:12Z","closed_at":null,"body":"How to create parent child hierarchy using self-join in strongloop. I have created model name as menu.\r\n\r\n```\r\nmenu.json\r\n{\r\n  \"name\": \"Menu\",\r\n  \"base\": \"PersistedModel\",\r\n  \"strict\": false,\r\n  \"idInjection\": false,\r\n  \"options\": {\r\n    \"validateUpsert\": true\r\n  },\r\n  \"properties\": {\r\n    \"MenuID\": {\r\n      \"type\": \"Number\",\r\n      \"id\": true,\r\n      \"required\": true\r\n    },\r\n    \"Name\": {\r\n      \"type\": \"string\"\r\n    },\r\n    \"ParentMenuID\": {\r\n      \"type\": \"Number\"\r\n    }\r\n  },\r\n  \"validations\": [],\r\n  \"relations\": {\r\n\r\n    \"menus\": {\r\n      \"type\": \"hasMany\",\r\n      \"model\": \"Menu\",\r\n      \"foreignKey\": \"ParentMenuID\",\r\n    }\r\n  },\r\n  \"acls\": [],\r\n  \"methods\": {}\r\n}\r\n```\r\n**Table data like:**\r\n```\r\nmenuId  Name     ParentID\r\n1       parent      0\r\n2       child       1\r\n3      grandchild   2 \r\n```  \r\nI tried REST API call using filter, but I am getting one level of data like http://localhost:3000/api/Menus/?filter[include]=menus\r\n\r\n```\r\n [\r\n  {\r\n    \"MenuID\": 1,\r\n    \"Name\": \"parent\",\r\n    \"ParentMenuID\": 0,\r\n    \"menus\": [\r\n      {\r\n        \"MenuID\": 2,\r\n        \"Name\": \"child\",\r\n        \"ParentMenuID\": 1\r\n      }\r\n    ]\r\n  },\r\n  {\r\n    \"MenuID\": 2,\r\n    \"Name\": \"child\",\r\n    \"ParentMenuID\": 1,\r\n    \"menus\": [\r\n      {\r\n        \"MenuID\": 3,\r\n        \"Name\": \"grandchild\",\r\n        \"ParentMenuID\": 2\r\n      }\r\n    ]\r\n  },\r\n  {\r\n    \"MenuID\": 3,\r\n    \"Name\": \"grandchild\",\r\n    \"ParentMenuID\": 2,\r\n    \"menus\": []\r\n  }\r\n]\r\n```\r\n**But I Expected Output Like:**\r\n\r\n```\r\n[\r\n  {\r\n    \"MenuID\": 1,\r\n    \"Name\": \"parent\",\r\n    \"ParentMenuID\": 0,\r\n    \"menus\": [\r\n      {\r\n        \"MenuID\": 2,\r\n        \"Name\": \"child\",\r\n        \"ParentMenuID\": 1,\r\n        \"menus\": [\r\n          {\r\n            \"MenuID\": 3,\r\n            \"Name\": \"grandchild\",\r\n            \"ParentMenuID\": 2\r\n          }\r\n        ]\r\n      }\r\n    ]\r\n  }\r\n]\r\n```\r\nPlease suggest any idea or example.\r\n"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback/issues/comments/185946266","html_url":"https://github.com/strongloop/loopback/issues/2075#issuecomment-185946266","issue_url":"https://api.github.com/repos/strongloop/loopback/issues/2075","id":185946266,"user":{"login":"jannyHou","id":12554153,"avatar_url":"https://avatars.githubusercontent.com/u/12554153?v=3","gravatar_id":"","url":"https://api.github.com/users/jannyHou","html_url":"https://github.com/jannyHou","followers_url":"https://api.github.com/users/jannyHou/followers","following_url":"https://api.github.com/users/jannyHou/following{/other_user}","gists_url":"https://api.github.com/users/jannyHou/gists{/gist_id}","starred_url":"https://api.github.com/users/jannyHou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jannyHou/subscriptions","organizations_url":"https://api.github.com/users/jannyHou/orgs","repos_url":"https://api.github.com/users/jannyHou/repos","events_url":"https://api.github.com/users/jannyHou/events{/privacy}","received_events_url":"https://api.github.com/users/jannyHou/received_events","type":"User","site_admin":false},"created_at":"2016-02-18T22:14:11Z","updated_at":"2016-02-18T22:14:11Z","body":"hey @katherdx I created a sandbox to implement your expected nest output:\r\nhttps://github.com/jannyHou/loopback-sandbox/tree/nest-include\r\n\r\n- `npm install`\r\n- open localhost:3000/explorer\r\n- GET /menus with filter: \r\n```\r\n{\r\n   \"include\":{\r\n      \"relation\":\"menus\",\r\n      \"scope\":{\r\n         \"include\":{\r\n            \"relation\":\"menus\"\r\n         }\r\n      }\r\n   }\r\n}\r\n```\r\n\r\n\r\nResponse data:\r\n```\r\n[\r\n  {\r\n    \"name\": \"menu1\",\r\n    \"id\": 1,\r\n    \"menus\": [\r\n      {\r\n        \"name\": \"menu2\",\r\n        \"id\": 2,\r\n        \"menuId\": 1,\r\n        \"menus\": [\r\n          {\r\n            \"name\": \"menu3\",\r\n            \"id\": 3,\r\n            \"menuId\": 2\r\n          }\r\n        ]\r\n      }\r\n    ]\r\n  },\r\n  {\r\n    \"name\": \"menu2\",\r\n    \"id\": 2,\r\n    \"menuId\": 1,\r\n    \"menus\": [\r\n      {\r\n        \"name\": \"menu3\",\r\n        \"id\": 3,\r\n        \"menuId\": 2,\r\n        \"menus\": []\r\n      }\r\n    ]\r\n  },\r\n  {\r\n    \"name\": \"menu3\",\r\n    \"id\": 3,\r\n    \"menuId\": 2,\r\n    \"menus\": []\r\n  }\r\n]\r\n```"}}