Skip to content

Instantly share code, notes, and snippets.

@thetutlage
Created June 27, 2018 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thetutlage/a57f7cfc798a46569573838417efd75d to your computer and use it in GitHub Desktop.
Save thetutlage/a57f7cfc798a46569573838417efd75d to your computer and use it in GitHub Desktop.
Lucid models relationships
const Model = use('Model')
class User extends Model {
posts () {
return this.hasMany('App/Models/Post')
}
}
class Post extends Model {
author () {
return this.belongsTo('App/Models/User')
}
categories () {
return this.belongsToMany('App/Models/Category')
}
}
class Category extends Model {
posts () {
return this.belongsToMany('App/Models/Post')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment