{"id":17558677,"url":"https://github.com/jonnybgod/loopback-set-through-properties-mixin","last_synced_at":"2025-04-28T10:49:17.720Z","repository":{"id":143887646,"uuid":"75207449","full_name":"JonnyBGod/loopback-set-through-properties-mixin","owner":"JonnyBGod","description":"A mixin to enable setting Through model properties","archived":false,"fork":false,"pushed_at":"2018-04-15T03:53:21.000Z","size":6,"stargazers_count":10,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T03:46:41.543Z","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-30T16:50:52.000Z","updated_at":"2018-04-15T03:53:23.000Z","dependencies_parsed_at":"2023-07-22T00:19:14.175Z","dependency_job_id":null,"html_url":"https://github.com/JonnyBGod/loopback-set-through-properties-mixin","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnyBGod%2Floopback-set-through-properties-mixin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnyBGod%2Floopback-set-through-properties-mixin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnyBGod%2Floopback-set-through-properties-mixin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonnyBGod%2Floopback-set-through-properties-mixin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JonnyBGod","download_url":"https://codeload.github.com/JonnyBGod/loopback-set-through-properties-mixin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251299247,"owners_count":21567181,"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","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:42.652Z","updated_at":"2025-04-28T10:49:17.698Z","avatar_url":"https://github.com/JonnyBGod.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# loopback-set-through-properties-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-set-through-properties-mixin/dev-status.svg)](https://david-dm.org/JonnyBGod/loopback-set-through-properties-mixin#info=devDependencies)\n[![Build Status](https://img.shields.io/travis/JonnyBGod/loopback-set-through-properties-mixin/master.svg?style=flat)](https://travis-ci.org/JonnyBGod/loopback-set-through-properties-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-set-through-properties-mixin/Lobby)\n\n##Features\n\n- set though model properties with queries\n- use as mixin\n\n##Installation\n\n```bash\nnpm install loopback-set-through-properties-mixin --save\n```\n\n##How to use\n\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-set-through-properties-mixin\",\n      \"../common/mixins\"\n    ]\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    \"SetThroughProperties\": true,\n  }\n}\n```\n\nThen use in you queries like:\n\n```js\nrequest(server).post('/apps/1/users')\n  .send({\n    name: 'John',\n    email: 'john@gmail.com',\n    userRole: {\n      type: 'collaborator'\n    }\n  })\n  .expect(200);\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## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/loopback-set-through-properties-mixin.svg\n[npm-url]: https://npmjs.org/package/loopback-set-through-properties-mixin\n[npm-downloads-image]: https://img.shields.io/npm/dm/loopback-set-through-properties-mixin.svg\n[npm-downloads-url]: https://npmjs.org/package/loopback-set-through-properties-mixin\n[bower-image]: https://img.shields.io/bower/v/loopback-set-through-properties-mixin.svg\n[bower-url]: http://bower.io/search/?q=loopback-set-through-properties-mixin\n[dep-status-image]: https://img.shields.io/david/angulartics/loopback-set-through-properties-mixin.svg\n[dep-status-url]: https://david-dm.org/angulartics/loopback-set-through-properties-mixin\n[license-image]: http://img.shields.io/badge/license-MIT-blue.svg\n[license-url]: LICENSE\n[slack-image]: https://loopback-set-through-properties-mixin.herokuapp.com/badge.svg\n[slack-url]: https://loopback-set-through-properties-mixin.herokuapp.com","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnybgod%2Floopback-set-through-properties-mixin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonnybgod%2Floopback-set-through-properties-mixin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonnybgod%2Floopback-set-through-properties-mixin/lists"}