Build a Twitter Clone With Adonis and Vue

User and Replies Relationship

A user can reply multiple times to a tweet, while a single reply can only belongs to a particular user. This is a one-to-many relationship. Open app/Models/User.js and add the code below to it:

// app/Models/User.js

replies () {
    return this.hasMany('App/Models/Reply')

Then define the inverse relationship on the Reply model. Open app/Models/Reply.js and add the code below to it:

// app/Models/Reply.js

user () {
    return this.belongsTo('App/Models/User')

Like this article? Follow @ammezie on Twitter