Created
June 27, 2018 10:11
-
-
Save thetutlage/a57f7cfc798a46569573838417efd75d to your computer and use it in GitHub Desktop.
Lucid models relationships
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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