Adonis Lucid Polymorphic
Polymorphic Relations support for Adonis Lucid ^4.1.0.
Installation
- Add package:
$ npm i adonis-lucid-polymorphic --save
or
$ yarn add adonis-lucid-polymorphic
- Register providers inside the your bootstrap/app.js file.
const providers = ... 'adonis-lucid-polymorphic/providers/PolymorphicProvider' ...
Examples
Table Structure
posts
id - integer
title - string
body - text
videos
id - integer
title - string
url - string
comments
id - integer
body - text
commentable_id - integer
commentable_type - string
Model Structure
// App/Model/Post'use strict' const Model = static { return '@provider:Morphable' } { return this } moduleexports = Post
// App/Model/Video'use strict' const Model = static { return '@provider:Morphable' } { return this } moduleexports = Video
// App/Model/Comment'use strict' const Model = static { return '@provider:Morphable' } { return this } moduleexports = Video
API
morphTo(relatedModels, [primaryKey], [relatedPrimaryKey], [morphIdKey], [morphTypeKey])
... static { return '@provider:Morphable' } { return this } ...
morphMany(relatedModel, [primaryKey], [morphIdKey], [morphTypeKey])
... static { return '@provider:Morphable' } { return this } ...
morphOne(relatedModel, [primaryKey], [morphIdKey], [morphTypeKey])
... static { return '@provider:Morphable' } { return this } ...
Credits
Support
Having trouble? Open an issue!
License
The MIT License (MIT). Please see License File for more information.