Closed guoyunhe closed 1 year ago
Hey! 👋🏻
Adonis uses convention over configuration, which relies on predefined conventions for naming and structuring code. In your example, the foreign key is not automatically detected because it does not adhere to these conventions. So, you'll need to specify the foreign key's name manually.
📚 https://docs.adonisjs.com/guides/models/relationships#custom-relationship-keys
Package version
Node.js and npm version
Sample Code (to reproduce the issue)
I have two models:
Game
model hasboxartImageId
, which loads anImage
asboxartImage
. However, if I write@belongsTo(() => Image)
, loading relation will fail:So I have to use
@belongsTo(() => Image, { foreignKey: 'boxartImageId' })
. It works. But not as straight-forward as Laravel.BONUS (a sample repo to reproduce the issue)
https://github.com/guoyunhe/rgi-api