【问题标题】:Phalcon - ::find() with relational conditionsPhalcon - ::find() 与关系条件
【发布时间】:2019-01-06 20:52:30
【问题描述】:

我正在尝试在 Phalcon 中获取模型以获取带有条件参数的数据,以便通过静态调用 ::find() 获取数据并将与其外部相关的参数传递给它:

ProductReports::find(array(
            "order.order_status_id = 6"
        ));

报错: Error fetchingProductReportsreport: exception 'Phalcon\Mvc\Model\Exception' with message 'Syntax error, unexpected token ORDER, near to '.order_status_id = 6', when parsing: SELECT [ProductReports].* FROM [ProductReports] WHERE order.order_status_id = 6 (113)

/**
 * Class ProductReports
 *
 * @Source('product_reports');
 *
 * @BelongsTo('order_id', 'Orders', 'order_id', {'alias':'order'});
 */
class ProductReports extends Model

有什么方法可以获取静态::find() 过滤它的关系而不是执行 foreach 循环(过滤单行与它的关系 order 别名)?

【问题讨论】:

    标签: php phalcon phalcon-orm


    【解决方案1】:

    在这种情况下,您会想要使用 QueryBuilder。确保使用别名定义模型之间的关系。如果您使用命名空间,请使用命名空间的完整路径(即 [Project\Models\Orders].order_status_id)。

    https://forum.phalconphp.com/discussion/8197/conditions-on-relation

    【讨论】:

    • 真可惜!我认为 phalcon 的人会想到另一种方法来做到这一点,而无需使用查询生成器。谢谢
    • 但这几乎是最好的方法。您提出的例如语法非常糟糕恕我直言。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 2018-05-27
    • 1970-01-01
    • 2020-06-23
    • 2012-08-18
    • 1970-01-01
    • 2016-01-27
    相关资源
    最近更新 更多