Laravel的多态关系是否也适用于真正的多态性? [英] Are Laravel's Polymorphic Relations also suitable for true polymorphism?
问题描述
为了更好地解释自己:Laravel.com上的示例展示属于视频和帖子的评论 的关系.但是,我说的是规范:不属于父表,而是成为规范. ( Subtyping )使用Laravel的 一个非常基本(并且可能很糟糕)的示例. 有趣的问题. 利用Laravel提供的多态关系,完全可以满足您的要求.但是,您指的是表继承,这就是鱼的全部. 您可以让您的 这确实取决于您将如何使用它.您会像查询 To explain myself better: the examples on Laravel.com showcase a relation of comments belonging to both videos and posts. However I'm talking about specification: not belonging to, but being a specification of the parent table. (Subtyping) Is using Laravel's A very basic (and potentially bad) example. Interesting question. It is entirely possible to do what you require, with the polymorphic relation that Laravel provides. You however, are referring to table inheritance which is whole other kettle of fish. You could have your It really depends exactly on how you'll be using this. Will you be going through 这篇关于Laravel的多态关系是否也适用于真正的多态性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!Polymorphic Relations
还是最好的方法吗? /p>
Animal
模型具有可以是Fish
或Mamal
的多态关系,或者您可以让Fish
和Mamal
属于Animal
,并创建传递-通过模型.animals
表一样浏览Animal
,还是要从孩子那里走?Polymorphic Relations
still the best approach?Animal
model have a polymorphic relationship that can either be Fish
or Mamal
, or you could have Fish
and Mamal
belong to an Animal
, and create a pass-through model.Animal
as in querying the animals
table, or will you be going from the children?