
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
adonis-lucid-morphable
Advanced tools
Polymorphic Relations support for Adonis Lucid ^4.1.0.
$ npm i adonis-lucid-polymorphic --save
or
$ yarn add adonis-lucid-polymorphic
const providers = [
...
'adonis-lucid-polymorphic/providers/PolymorphicProvider',
...
]
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
// App/Model/Post
'use strict'
const Model = use('Lucid')
class Post extends Model {
static get traits () {
return ['@provider:Morphable']
}
comments () {
return this.morphMany('App/Models/Comment', 'id', 'commentable_id', 'commentable_type')
}
}
module.exports = Post
// App/Model/Video
'use strict'
const Model = use('Lucid')
class Video extends Model {
static get traits () {
return ['@provider:Morphable']
}
comments () {
return this.morphMany('App/Models/Comment', 'id', 'commentable_id', 'commentable_type')
}
}
module.exports = Video
// App/Model/Comment
'use strict'
const Model = use('Lucid')
class Comment extends Model {
static get traits () {
return ['@provider:Morphable']
}
commentable () {
return this.morphTo([
'App/Models/Post', 'App/Models/Video'
], 'id', 'id', 'commentable_id', 'commentable_type')
}
}
module.exports = Video
...
class Comment extends Model {
static get traits () {
return ['@provider:Morphable']
}
commentable () {
return this.morphTo([
'App/Models/Post', 'App/Models/Video'
], 'id', 'id', 'commentable_id', 'commentable_type')
}
}
...
...
class Post extends Model {
static get traits () {
return ['@provider:Morphable']
}
comments () {
return this.morphMany('App/Models/Comment', 'id', 'commentable_id', 'commentable_type')
}
}
...
...
class Publication extends Model {
static get traits () {
return ['@provider:Morphable']
}
content () {
return this.morphOne('App/Models/Content', 'id', 'contentable_id', 'contentable_type')
}
}
...
Having trouble? Open an issue!
The MIT License (MIT). Please see License File for more information.
FAQs
Adonis Lucid ^4.1.0 Polymorphic Relations Support.
We found that adonis-lucid-morphable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.