【问题标题】:Phalcon Join Model ErrorPhalcon 连接模型错误
【发布时间】:2014-03-27 10:09:45
【问题描述】:

如果我们想使用 Phalcon 中的查询构建器将多个表连接到单个查询中。它要求为所有需要连接的表创建模型。

这是缺点还是优点?

$m = Firstmodel::query()
    ->columns("col1, col2")

    ->where("col3 = '2'")

    ->join("model2", "col1 = col5", 'a')
    ->join("model3", "col6 = col7", 'b')

    ->orderBy("col1")
    ->execute();

只需一个连接查询,它就可以完美运行。但是有 2 个像上面这样的连接查询会出现以下错误:

Scanning error before '] JOIN [] JOIN [...' 
when parsing: SELECT col1, col2 FROM [Firstmodel] 
JOIN [model2] AS [a] ON col1 = col5 
JOIN [] JOIN [] JOIN [] JOIN [] WHERE col3 = '2' ORDER BY col1 (180)

是否有其他方法可以在不创建模型的情况下连接表?

【问题讨论】:

    标签: php model phalcon


    【解决方案1】:

    您必须显示 col1 col5 等来自哪个模型。尝试通过此示例重写您的查询:

    $builder->from('Robots')
        ->join('RobotsParts', 'Robots.id = RobotsParts.robots_id', 'p')
        ->join('Parts', 'Parts.id = RobotsParts.parts_id', 't');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 2022-12-04
      • 2015-06-05
      • 2018-02-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多