【问题标题】:How to join two tables in Propel that don't have a foreign key defined between them?如何连接 Propel 中没有定义外键的两个表?
【发布时间】:2018-10-01 08:38:39
【问题描述】:

我有一个使用 Propel 2 的项目,我想在某个字段上加入两个表,但那里没有外键关系。我只想根据该值匹配它们。不幸的是,我无法让它工作,而 Propel 的文档,尽管它试图做到彻底,但仍然缺乏很好的参考。我该怎么做?

我尝试过的:

echo Table1Query::create()
        ->addJoin(Table1TableMap::COL_A, Table2TableMap::COL_B)
        ->where('Table2.C=?', 'asd')
        ->toString();

这在where() 部分失败,System error Cannot determine the column to bind to the parameter in clause "Table2.C=?".

我知道我可以得到 PDO 连接并退回到纯 SQL,这肯定会更容易,但使用 ORM 时感觉有点不对劲 (then again...)。

【问题讨论】:

    标签: php propel2


    【解决方案1】:

    由于您尚未在架构中定义关系,因此您需要执行显式连接类型,例如:

    ->addJoin(Table1TableMap::COL_A, Table2TableMap::COL_B, Criteria::JOIN_TYPE)
    // INNER_JOIN, INNER_JOIN, etc
    

    【讨论】:

      猜你喜欢
      • 2021-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      • 2013-08-06
      • 1970-01-01
      • 2015-03-16
      • 2017-01-25
      相关资源
      最近更新 更多