All Projects → JonnyBGod → Loopback Include Through Mixin

JonnyBGod / Loopback Include Through Mixin

Licence: mit
A mixin to enable including Through model properties

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Loopback Include Through Mixin

floggy
Customizable logger for dart and flutter applications.
Stars: ✭ 61 (+306.67%)
Mutual labels:  mixins
Postcss Utilities
PostCSS plugin to add a collection of mixins, shortcuts, helpers and tools for your CSS
Stars: ✭ 293 (+1853.33%)
Mutual labels:  mixins
Dynamix
🍥 A new take on polymorphism in C++
Stars: ✭ 504 (+3260%)
Mutual labels:  mixins
mixomatic
Create mixins which work with instanceof (friendly for unit tests).
Stars: ✭ 21 (+40%)
Mutual labels:  mixins
Juice
Mixins for Life
Stars: ✭ 274 (+1726.67%)
Mutual labels:  mixins
Aspect Injector
AOP framework for .NET (c#, vb, etc)
Stars: ✭ 398 (+2553.33%)
Mutual labels:  mixins
vue-reactive-provide
Plugin/Mixin wrapping Vue's static 'provide/inject' feature allowing to easily pass reactive data to children
Stars: ✭ 113 (+653.33%)
Mutual labels:  mixins
Minecraftdev
Plugin for IntelliJ IDEA that gives special support for Minecraft modding projects.
Stars: ✭ 645 (+4200%)
Mutual labels:  mixins
Apollo Elements
🚀🌛 Use the Launch Platform 👩‍🚀👨‍🚀
Stars: ✭ 278 (+1753.33%)
Mutual labels:  mixins
Csshake
CSS classes to move your DOM!
Stars: ✭ 4,531 (+30106.67%)
Mutual labels:  mixins
Arclight
A Bukkit(1.15/1.16) server implementation on Forge using Mixin. ⚡
Stars: ✭ 262 (+1646.67%)
Mutual labels:  mixins
Vue Turbolinks
A Vue mixin to fix Turbolinks caching
Stars: ✭ 272 (+1713.33%)
Mutual labels:  mixins
Est
EFE Styling Toolkit based on Less
Stars: ✭ 399 (+2560%)
Mutual labels:  mixins
Crucible
Crucible is a Thermos fork containing various patches for bug fixes and performance improvements. Join our discord to stay updated with the project development.
Stars: ✭ 67 (+346.67%)
Mutual labels:  mixins
Mixin
Mixin is a trait/mixin and bytecode weaving framework for Java using ASM
Stars: ✭ 557 (+3613.33%)
Mutual labels:  mixins
loopback-paginator
No description or website provided.
Stars: ✭ 13 (-13.33%)
Mutual labels:  loopback
Loopback Next
LoopBack makes it easy to build modern API applications that require complex integrations.
Stars: ✭ 3,972 (+26380%)
Mutual labels:  loopback
Concur
Sugar for infectious JavaScript inheritance, metaprogramming & mixins
Stars: ✭ 14 (-6.67%)
Mutual labels:  mixins
Potion
_why the lucky stiff's little language (the official repo... until _why returns)
Stars: ✭ 586 (+3806.67%)
Mutual labels:  mixins
Loopback Sdk Builder
Tool for auto-generating Software Development Kits (SDKs) for LoopBack
Stars: ✭ 407 (+2613.33%)
Mutual labels:  loopback

loopback-include-through-mixin

NPM version NPM downloads devDependency Status Build Status

MIT license Gitter Chat

Features

  • include though model properties with queries
  • setup default bahavior
  • use as mixin

Installation

npm install loopback-include-through-mixin --save

How to use

Add the mixins property to your server/model-config.json like the following:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "../node_modules/loopback-include-through-mixin",
      "../common/mixins"
    ]
  }
}

or

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback-include-through-mixin/lib",
      "../common/mixins"
    ]
  }
}

To use with your Models add the mixins attribute to the definition object of your model config.

{
  "name": "app",
  "properties": {
    "name": {
      "type": "string",
    }
  },
  "relations": {
    "users": {
      "type": "hasMany",
      "model": "user",
      "foreignKey": "appId",
      "through": "userRole"
    }
  },
  "mixins": {
    "IncludeThrough": true,
  }
}

Then use in you queries like:

{
  "where": "...",
  "include": "...",
  "includeThrough": true
}
{
  "where": "...",
  "include": "...",
  "includeThrough": {
    "fields": "type"
  }
}

You can also set default behavior in your model definition with options.

{
  "name": "app",
  "properties": {
    "name": {
      "type": "string",
    }
  },
  "relations": {
    "users": {
      "type": "hasMany",
      "model": "user",
      "foreignKey": "appId",
      "through": "userRole"
    }
  },
  "mixins": {
    "IncludeThrough": {
      "relations": [
        "users"
      ],
      "fields": {
        "users": "type"
      }
    },
  }
}

Example of Through Model:

{
  "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"
    }
  }
}

Options

option type description required
relations [String, Object] select relations, can be object with property "name" and "asProperty" false
relations[0].name String name of the relation false
relations[0].asProperty String rename the property that through model will be injected to, default is name of the through model false
fields Key/Value Object similar to filter fields. Key: relation; Value: fields filter. false
  • By setting relations in model definition it will return the though model for the specified relations by default
  • By passing includeThrough in you query filter it will override default fields

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].