[英]Phalcon - ::find() with relational conditions
我正在尝试在Phalcon中获取一个模型以获取带有条件参数的数据,以便通过静态调用::find()
获取数据并将参数传递给与之相关的外部变量:
ProductReports::find(array(
"order.order_status_id = 6"
));
被赋予错误: Error fetching
ProductReports report: 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)
出错: report: 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
别名过滤单行)?
在这种情况下,您想使用QueryBuilder。 确保使用别名定义模型之间的关系。 如果使用名称空间,请使用名称空间的完整路径(即[Project \\ Models \\ Orders] .order_status_id)。
https://forum.phalconphp.com/discussion/8197/conditions-on-relation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.