https://github.com/jonnybgod/loopback-set-through-properties-mixin
A mixin to enable setting Through model properties
https://github.com/jonnybgod/loopback-set-through-properties-mixin
loopback loopback-mixin mixin mixins node nodejs
Last synced: 5 months ago
JSON representation
A mixin to enable setting Through model properties
- Host: GitHub
- URL: https://github.com/jonnybgod/loopback-set-through-properties-mixin
- Owner: JonnyBGod
- License: mit
- Created: 2016-11-30T16:50:52.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-04-15T03:53:21.000Z (over 7 years ago)
- Last Synced: 2025-04-12T03:46:41.543Z (6 months ago)
- Topics: loopback, loopback-mixin, mixin, mixins, node, nodejs
- Language: JavaScript
- Size: 5.86 KB
- Stars: 10
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# loopback-set-through-properties-mixin
[![NPM version][npm-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-downloads-url]
[](https://david-dm.org/JonnyBGod/loopback-set-through-properties-mixin#info=devDependencies)
[](https://travis-ci.org/JonnyBGod/loopback-set-through-properties-mixin)[![MIT license][license-image]][license-url]
[](https://gitter.im/loopback-set-through-properties-mixin/Lobby)##Features
- set though model properties with queries
- use as mixin##Installation
```bash
npm install loopback-set-through-properties-mixin --save
```##How to use
Add the mixins property to your server/model-config.json like the following:
```json
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"../node_modules/loopback-set-through-properties-mixin",
"../common/mixins"
]
}
}```
To use with your Models add the mixins attribute to the definition object of your model config.
```json
{
"name": "app",
"properties": {
"name": {
"type": "string",
}
},
"relations": {
"users": {
"type": "hasMany",
"model": "user",
"foreignKey": "appId",
"through": "userRole"
}
},
"mixins": {
"SetThroughProperties": true,
}
}
```Then use in you queries like:
```js
request(server).post('/apps/1/users')
.send({
name: 'John',
email: 'john@gmail.com',
userRole: {
type: 'collaborator'
}
})
.expect(200);
```Example of Through Model:
```json
{
"name": "userRole",
"properties": {
"type": {
"type": "string",
"required": true,
"default": "owner",
"description": "owner | administrator | collaborator"
}
},
"validations": [],
"relations": {
"app": {
"type": "belongsTo",
"model": "app",
"foreignKey": "appId"
},
"user": {
"type": "belongsTo",
"model": "user",
"foreignKey": "userId"
}
}
}
```## License
[MIT](LICENSE)
[npm-image]: https://img.shields.io/npm/v/loopback-set-through-properties-mixin.svg
[npm-url]: https://npmjs.org/package/loopback-set-through-properties-mixin
[npm-downloads-image]: https://img.shields.io/npm/dm/loopback-set-through-properties-mixin.svg
[npm-downloads-url]: https://npmjs.org/package/loopback-set-through-properties-mixin
[bower-image]: https://img.shields.io/bower/v/loopback-set-through-properties-mixin.svg
[bower-url]: http://bower.io/search/?q=loopback-set-through-properties-mixin
[dep-status-image]: https://img.shields.io/david/angulartics/loopback-set-through-properties-mixin.svg
[dep-status-url]: https://david-dm.org/angulartics/loopback-set-through-properties-mixin
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg
[license-url]: LICENSE
[slack-image]: https://loopback-set-through-properties-mixin.herokuapp.com/badge.svg
[slack-url]: https://loopback-set-through-properties-mixin.herokuapp.com