How to use findOrCreate in relationships

I have a user table, and a user address table.

so in the change of address route I would like to make some con

Find Or Create

I already have the relationship done ../Models/User.js

address() {
  return this.hasOne('App/Models/UserAddress')

Note: the relationship is working

await user.posts().fetch()

it works perfectly

but the code below doesn’t work

const user = await User.findOrFail(
const data = await request.only([


but this generates an error

user.address (...). findOrCreate is not a function

could someone tell me the best way to do this Find Or Create in relationships?

1 Like