简体   繁体   English

Phalcon加入模型错误

[英]Phalcon Join Model Error

If we want to join multiple tables into single query using query builder in Phalcon. 如果我们想使用Phalcon中的查询构建器将多个表连接到单个查询中。 It demands to have models created for all tables that need to be joined. 它要求为所有需要连接的表创建模型。

Is this drawback or advantage? 这是缺点还是优势?

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

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

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

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

With one join query it works perfectly. 通过一个连接查询,它可以完美运行 But having 2 join queries like above gives be below error: 但是如上所述有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)

Is there a alternate way to join tables without creating models? 是否有另一种方法可以在不创建模型的情况下连接表?

You have to show from which model col1 col5 etc are coming. 您必须显示col1 col5等来自哪个型号。 Try rewriting your query by this example: 尝试通过此示例重写您的查询:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM