How Eloquent determines the foreign key of the relationship?

Posted 1 year ago by CDNxL

The documentation says:

Eloquent determines the foreign key of the relationship based on the model name.

but in the HasRelationship class in the belongsTo method, I can see this comment

If no foreign key was supplied, we can use a backtrace to guess the proper foreign key name by using the name of the relationship function, which when combined with an "_id" should conventionally match the columns.

So.. the documentation is wrong?

I've tested it and is how it works exactly? (I already know how to set it manually)


Please sign in or create an account to participate in this conversation.