CakePHP 关联、可容纳和线程

发布于 2024-12-27 14:18:24 字数 541 浏览 2 评论 0原文

您好,我有几个关于协会及其在案件中如何发挥作用的问题 复杂的 find() 调用。

  • 如果我有一个模型Post和一个模型Comment,后者有一个parent_id字段 我想获取一篇带有相关评论的帖子,我是否只需执行一个 find('threaded', ...)Post 本身上,否则会导致错误,因为 Post 不会 有parent_id吗?我特别关心可包含+线程查找。 (这 我在这里给出的示例是我实际需要实现的简化版本)

  • 关联名称的意义是什么? Containable 是否适用于关联名称 或型号名称? (我想知道这一点的原因是因为我试图通过特定于条件的模型关联来实现多态模型,通常对同一模型有多个关联)

Hi I've got a couple of questions regarding associations and how they play in cases
of complex find() calls.

  • If I've got a model Post and a model Comment with the latter having a parent_id field
    and I want to fetch a post with its associated comments threaded, do I simply perform a
    find('threaded', ...) on Post itself or will this result in an error because Post doesn't
    have a parent_id? I am particularly concerned about a Containable + Threaded find. (the
    example I give here is a simplified version of what I actually need to implement)

  • What is the significance of Association Names? Does Containable work on association names
    or model names? (the reason I want to know this is because I'm trying to implement polymorphic models by having condition-specific model associations, often having multiple associations to the same model)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯 2025-01-03 14:18:24
  • 认为,containable 不支持在包含的模型上进行线程查找。例如,您的 comments 表中可能有一个 post_id 列,并执行以下操作:

    $this->注释->find('线程', array(
    '条件' =>大批(
    'post_id'=>; 5)));

  • 虽然书上可能说 Containable 使用模型名称,但当我在同一模型之间有多个联接时,我经常在 Containable 中使用关联名称。对于简单的项目,模型名称通常与关联名称相同,因此这可能就是书上这么说的原因。

  • I think that containable would not support threaded finds on the contained models. EG you might have a post_id column in your comments table, and do something like:

    $this->Comment->find('threaded', array(
    'conditions' => array(
    'post_id' => 5)));

  • Although the book may say that Containable uses the model name, I have regularly used the association name in Containable when I have multiple joins between the same models. For simple projects, the model name is usually the same as the association name, so that may be why the book says that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文