Using auth object not able to fetch hasOne relation data

Hi,

In my post login page, i’m trying to fetch user profile by using hasOne relationship, result in I’m getting null.

async profile({ view, auth }) {
            const { user } = auth
            const userProfile = await user.profile().fetch()
            console.log(userProfile) // null
    }

User model

 profile () {
    return this.hasOne('App/Models/UserProfile' , '_id' ,  'userId')
  }

Profile model

 user() {
    return this.belongsTo('App/Models/User', '_id' , 'userId')
  }

What is _id here?

_id - primarykey of users collection
userId - foreign key of userProfile collection

mongoDb is the database.
The provider which im using is LucidMongoProvider

You must create an issue with the package author. I do not maintain LucidMongoProvider

Okay, thnx.!

But it is working in the below case ,

        const user = await auth.getUser()
        const UserModel = await use('App/Models/User').find(user._id)
        const userProfile = await UserModel.profile().fetch();

Then , I’m not getting why its return null, when I use like below,

const { user } = auth
const userProfile = await user.profile().fetch()
console.log(userProfile) // null

Encontró una solución, me está devolviendo null.