为什么即使我在Laravel中删除了关系,仍然有很多关系仍在工作 [英] Why hasMany Relation still working even i removed relation in Laravel
问题描述
在上面的两个模型中,我都评论了方法itemDestribution(),但它仍然有效
In the above both models i commented the method itemDestribution() but still it is working
推荐答案
由于以下原因,该关系显示数据.
This relation displays a Data because of following reasons.
-
在您的
ItemDestributionModel
中,您已经设置了与UserModel
和ItemModel
的关系.
In your
ItemDestributionModel
, You have set relation withUserModel
andItemModel
both.
在您的ItemModel
和UserModel
中,您没有声明任何公共函数并添加关系类.
In your ItemModel
and UserModel
you haven't declare any public function and add Relation Class.
当您调用UserModel
时,它将在ItemDestributionModel
中找到hasMany
关系,并且user()
函数可用于belongsTo
关系.
When you call UserModel
it will find hasMany
Relationship in ItemDestributionModel
and user()
function is available with belongsTo
relationship.
这就是为什么laravel在不声明公共功能的情况下获取数据的原因.但是您应该在公共函数内部声明关系. :)
That's why laravel fetch data without declaring public function. But you should declare relationship inside public function. :)
这篇关于为什么即使我在Laravel中删除了关系,仍然有很多关系仍在工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!