I am trying to fetch a model in Phalcon to get data with conditional parameters, in order to get data with static call ::find()
and passing parameters to it related to it's foreign:
ProductReports::find(array(
"order.order_status_id = 6"
));
Is given the error: 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)
/**
* Class ProductReports
*
* @Source('product_reports');
*
* @BelongsTo('order_id', 'Orders', 'order_id', {'alias':'order'});
*/
class ProductReports extends Model
Is there any way to fetch to static ::find()
filtering it's relation instead doing a foreach loop (filter single row with it's relation order
alias)?
You'd want to use the QueryBuilder in that case. Make sure you define your relationship between your model with an alias. If you're using namespace, use the full path of your namespace (ie [Project\\Models\\Orders].order_status_id).
https://forum.phalconphp.com/discussion/8197/conditions-on-relation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.