{"id":17558689,"url":"https://github.com/jonnybgod/loopback-include-through-mixin","last_synced_at":"2026-03-27T04:51:25.729Z","repository":{"id":13890154,"uuid":"75207360","full_name":"JonnyBGod/loopback-include-through-mixin","owner":"JonnyBGod","description":"A mixin to enable including Through model properties","archived":false,"fork":false,"pushed_at":"2022-12-30T17:44:44.000Z","size":1442,"stargazers_count":14,"open_issues_count":23,"forks_count":10,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-05T00:47:44.089Z","etag":null,"topics":["loopback","loopback-mixin","mixin","mixins","node","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JonnyBGod.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-30T16:49:43.000Z","updated_at":"2020-07-13T11:57:55.000Z","dependencies_parsed_at":"2023-01-11T18:41:12.627Z","dependency_job_id":null,"html_url":"https://github.com/JonnyBGod/loopback-include-through-mixin","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/JonnyBGod/loopback-include-through-mixin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnyBGod%2Floopback-include-through-mixin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnyBGod%2Floopback-include-through-mixin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnyBGod%2Floopback-include-through-mixin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnyBGod%2Floopback-include-through-mixin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JonnyBGod","download_url":"https://codeload.github.com/JonnyBGod/loopback-include-through-mixin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnyBGod%2Floopback-include-through-mixin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267417615,"owners_count":24083838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["loopback","loopback-mixin","mixin","mixins","node","nodejs"],"created_at":"2024-10-21T10:08:44.947Z","updated_at":"2026-03-27T04:51:24.074Z","avatar_url":"https://github.com/JonnyBGod.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# loopback-include-through-mixin\n\n[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-downloads-url]\n[![devDependency Status](https://david-dm.org/JonnyBGod/loopback-include-through-mixin/dev-status.svg)](https://david-dm.org/JonnyBGod/loopback-include-through-mixin#info=devDependencies)\n[![Build Status](https://img.shields.io/travis/JonnyBGod/loopback-include-through-mixin/master.svg?style=flat)](https://travis-ci.org/JonnyBGod/loopback-include-through-mixin)\n\n[![MIT license][license-image]][license-url]\n[![Gitter Chat](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/loopback-include-through-mixin/Lobby)\n\n## Features\n\n- include though model properties with queries\n- setup default bahavior\n- use as mixin\n\n## Installation\n\n```bash\nnpm install loopback-include-through-mixin --save\n```\n\n## How to use\n\nAdd the mixins property to your server/model-config.json like the following:\n\n```json\n{\n  \"_meta\": {\n    \"sources\": [\n      \"loopback/common/models\",\n      \"loopback/server/models\",\n      \"../common/models\",\n      \"./models\"\n    ],\n    \"mixins\": [\n      \"loopback/common/mixins\",\n      \"../node_modules/loopback-include-through-mixin\",\n      \"../common/mixins\"\n    ]\n  }\n}\n```\n\nor\n\n```json\n{\n  \"_meta\": {\n    \"sources\": [\n      \"loopback/common/models\",\n      \"loopback/server/models\",\n      \"../common/models\",\n      \"./models\"\n    ],\n    \"mixins\": [\n      \"loopback/common/mixins\",\n      \"loopback-include-through-mixin/lib\",\n      \"../common/mixins\"\n    ]\n  }\n}\n```\n\nTo use with your Models add the mixins attribute to the definition object of your model config.\n\n```json\n{\n  \"name\": \"app\",\n  \"properties\": {\n    \"name\": {\n      \"type\": \"string\",\n    }\n  },\n  \"relations\": {\n    \"users\": {\n      \"type\": \"hasMany\",\n      \"model\": \"user\",\n      \"foreignKey\": \"appId\",\n      \"through\": \"userRole\"\n    }\n  },\n  \"mixins\": {\n    \"IncludeThrough\": true,\n  }\n}\n```\n\nThen use in you queries like:\n\n```json\n{\n  \"where\": \"...\",\n  \"include\": \"...\",\n  \"includeThrough\": true\n}\n```\n\n```json\n{\n  \"where\": \"...\",\n  \"include\": \"...\",\n  \"includeThrough\": {\n    \"fields\": \"type\"\n  }\n}\n```\n\nYou can also set default behavior in your model definition with options.\n\n```json\n{\n  \"name\": \"app\",\n  \"properties\": {\n    \"name\": {\n      \"type\": \"string\",\n    }\n  },\n  \"relations\": {\n    \"users\": {\n      \"type\": \"hasMany\",\n      \"model\": \"user\",\n      \"foreignKey\": \"appId\",\n      \"through\": \"userRole\"\n    }\n  },\n  \"mixins\": {\n    \"IncludeThrough\": {\n      \"relations\": [\n        \"users\"\n      ],\n      \"fields\": {\n        \"users\": \"type\"\n      }\n    },\n  }\n}\n```\n\nExample of Through Model:\n\n```json\n{\n  \"name\": \"userRole\",\n  \"properties\": {\n    \"type\": {\n      \"type\": \"string\",\n      \"required\": true,\n      \"default\": \"owner\",\n      \"description\": \"owner | administrator | collaborator\"\n    }\n  },\n  \"validations\": [],\n  \"relations\": {\n    \"app\": {\n      \"type\": \"belongsTo\",\n      \"model\": \"app\",\n      \"foreignKey\": \"appId\"\n    },\n    \"user\": {\n      \"type\": \"belongsTo\",\n      \"model\": \"user\",\n      \"foreignKey\": \"userId\"\n    }\n  }\n}\n```\n\n## Options\n\n| option | type | description | required |\n| ------ | ---- | ----------- | -------- |\n|relations| [String, Object] | select relations, can be object with property \"name\" and \"asProperty\" | false |\n|relations[0].name|String|name of the relation |false|\n|relations[0].asProperty|String|rename the property that through model will be injected to, default is name of the through model |false|\n|fields| Key/Value Object |  similar to filter fields. Key: relation; Value: fields filter. | false |\n\n\n\n- By setting relations in model definition it will return the though model for the specified relations by default\n- By passing **includeThrough** in you query filter it will override default **fields**\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/loopback-include-through-mixin.svg\n[npm-url]: https://npmjs.org/package/loopback-include-through-mixin\n[npm-downloads-image]: https://img.shields.io/npm/dm/loopback-include-through-mixin.svg\n[npm-downloads-url]: https://npmjs.org/package/loopback-include-through-mixin\n[bower-image]: https://img.shields.io/bower/v/loopback-include-through-mixin.svg\n[bower-url]: http://bower.io/search/?q=loopback-include-through-mixin\n[dep-status-image]: https://img.shields.io/david/angulartics/loopback-include-through-mixin.svg\n[dep-status-url]: https://david-dm.org/angulartics/loopback-include-through-mixin\n[license-image]: http://img.shields.io/badge/license-MIT-blue.svg\n[license-url]: LICENSE\n[slack-image]: https://loopback-include-through-mixin.herokuapp.com/badge.svg\n[slack-url]: https://loopback-include-through-mixin.herokuapp.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnybgod%2Floopback-include-through-mixin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonnybgod%2Floopback-include-through-mixin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnybgod%2Floopback-include-through-mixin/lists"}