CDNxL

How Eloquent determines the foreign key of the relationship?

Posted 11 months 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 true..so how it works exactly? (I already know how to set it manually)

Thanks.

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

Reply to

Use Markdown with GitHub-flavored code blocks.