Doctrine中使用DQL访问多对多中间表中的字段

发布于 2024-08-18 22:20:00 字数 180 浏览 3 评论 0原文

我有一个名为 ContentGroup 的模型和另一个名为 Content 的模型,它们之间具有多对多关系。

中间表有一个名为“位置”的字段,当我尝试编写 DQL 查询来获取与 ContentGroup 关联的所有内容时,我无法使用所涉及的模型或关系的别名来引用位置字段。

有人试试这个吗?

谢谢!

i have a model called ContentGroup and another called Content with a many-to-many relation between them.

The intermediate table has a field called Position, When i try to write a DQL query to obtain all the contents associated with a ContentGroup i cannot reference the position field usign the aliases of the models or relations involved.

someone try this?

thanks!

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

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

发布评论

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

评论(1

呢古 2024-08-25 22:20:00

考虑中间模型IntModel

没有测试过,但这应该有效:

$q = Doctrine::getTable('IntModel')->createQuery('p')
     ->leftJoin('p.Content as c')
     ->leftJoin('p.ContentGroup as cg')
     ->where('cg.id = ?', $my_content_group_id)->fetchOne();
echo $q->getPosition();

Consider intermediate model IntModel.

Didn't tested, but this should work:

$q = Doctrine::getTable('IntModel')->createQuery('p')
     ->leftJoin('p.Content as c')
     ->leftJoin('p.ContentGroup as cg')
     ->where('cg.id = ?', $my_content_group_id)->fetchOne();
echo $q->getPosition();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文