如何在 propel 查询中添加别名

发布于 2024-12-09 09:04:08 字数 342 浏览 1 评论 0原文

在我的 symfony 1.4 项目中,我有两个连接到同一个表(不同的外键)的查询:

return ArticleQuery::create(null,$criteria)
        ->joinWithArticleCategoryRelatedByNewsCategoryId()
        ->joinWithArticleCategoryRelatedByHelpCategoryId();

我收到错误: SQLSTATE[42000]:语法错误或访问冲突:1066 不唯一的表/别名:'article_category'

如何向此联接添加别名?

In my symfony 1.4 project I have query with two joins to the same table (different foreign keys):

return ArticleQuery::create(null,$criteria)
        ->joinWithArticleCategoryRelatedByNewsCategoryId()
        ->joinWithArticleCategoryRelatedByHelpCategoryId();

I'm getting error:
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'article_category'

How can I add alias to this join?

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

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

发布评论

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

评论(2

吖咩 2024-12-16 09:04:08

这对我有用:

return ArticleQuery::create()
    ->joinWith('ArticleCategoryRelatedByNewsCategoryId a', Criteria::LEFT_JOIN)
    ->joinWith('ArticleCategoryRelatedByHelpCategoryId b', Criteria::LEFT_JOIN);

在其他情况下 - 你应该尝试升级你的 Propel ;)

This worked for me:

return ArticleQuery::create()
    ->joinWith('ArticleCategoryRelatedByNewsCategoryId a', Criteria::LEFT_JOIN)
    ->joinWith('ArticleCategoryRelatedByHelpCategoryId b', Criteria::LEFT_JOIN);

In other case - you should try to upgrade your Propel ;)

贪了杯 2024-12-16 09:04:08

注意:我使用 Propel 1.6

将参数传递给 join 方法应该足够了。

return ArticleQuery::create(null,$criteria)
        ->joinWithArticleCategoryRelatedByNewsCategoryId('news')
        ->joinWithArticleCategoryRelatedByHelpCategoryId('help');

查看生成的 BaseArticleQuery.php 以查看已为您生成了哪些方法。我的一种连接方法如下所示:

/**
 * Adds a JOIN clause to the query using the ArticleKeyword relation
 *
 * @param     string $relationAlias optional alias for the relation
 * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
 *
 * @return    KeywordQuery The current query, for fluid interface
 */
public function joinArticleKeyword($relationAlias = null, $joinType = Criteria::LEFT_JOIN)

Propel 的优势之一是几乎所有东西都有一个具体的方法。因此,如果您有一个支持代码完成的 IDE,您可以收到有关方法支持哪些参数的提示。

Note: I use Propel 1.6

It should be enough to pass an argument to the join method.

return ArticleQuery::create(null,$criteria)
        ->joinWithArticleCategoryRelatedByNewsCategoryId('news')
        ->joinWithArticleCategoryRelatedByHelpCategoryId('help');

Look in your generated BaseArticleQuery.php to see what methods have been generated for you. One of my join methods look like this:

/**
 * Adds a JOIN clause to the query using the ArticleKeyword relation
 *
 * @param     string $relationAlias optional alias for the relation
 * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
 *
 * @return    KeywordQuery The current query, for fluid interface
 */
public function joinArticleKeyword($relationAlias = null, $joinType = Criteria::LEFT_JOIN)

One of the strengths of Propel, is that nearly everything has a concrete method. So if you have an IDE with support for code completion, you can receive hints of what arguments the methods support.

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