Why hasMany Relation still working even i removed relation in Laravel

a 夏天 提交于 2019-12-25 06:40:57

问题


In the above both models i commented the method itemDestribution() but still it is working


回答1:


This relation displays a Data because of following reasons.

  1. In your ItemDestributionModel, You have set relation with UserModel and ItemModel both.

  2. In your ItemModel and UserModel you haven't declare any public function and add Relation Class.

When you call UserModel it will find hasMany Relationship in ItemDestributionModel and user() function is available with belongsTo relationship.

That's why laravel fetch data without declaring public function. But you should declare relationship inside public function. :)



来源:https://stackoverflow.com/questions/39511218/why-hasmany-relation-still-working-even-i-removed-relation-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!