Getting E_CANNOT_OVERRIDE RELATION error

Hi all,
sorry to bother you, but I don’t find any suitable response to my issue neither on this forum, neither on Google.

I have a Message model for my messages table to store chats between users.
Here’s how I defined the model with its relationships.

'use strict'

const Model = use('Model')

class Message extends Model {

  project() {
    return this.belongsTo('App/Models/Project')
  }

  sender() {
    return this.belongsTo('App/Models/User', 'from_id')
  }

  receiver() {
    return this.belongsTo('App/Models/User', 'to_id')
  }

}

module.exports = Message

And here is the controller function to get conversations between two users, the one currently connected and another one for example.

async getUserConversations({auth, request, response}) {
    try {
      let myConversations = await Message.query()
        .where('from_id', auth.user.id)
        .orWhere('to_id', auth.user.id).with('receiver')
        .with('project').with('sender')
        .fetch()

      return response.json(myConversations)

    } catch (e) {
      console.log(e)
      return response.json([])
    }
  }

This is the error I’m facing:

 RuntimeException: E_CANNOT_OVERRIDE_RELATION: Trying to eagerload receiver relationship twice

Help me please !

2 Likes

@virk @romain.lanz please I need your help!

Facing same problem. any solution yet?