symfony - 是否可以使用 Criteria 功能在 Doctrine 中加入?
问题描述
public function findActiveEvents($start, $end)
{
$expr = Criteria::expr();
$criteria = Criteria::create();
$criteria->where(
$expr->andX($expr->gte('start', $start), $expr->lte('end', $end)
));
return $this->matching($criteria);
}
假设我的事件实体有一个类别,而类别有很多事件,我将如何过滤这些?
解决方案
如果您想收集类别对象上的非活动事件,您可以使用标准类
class Category{
protected $events; // (oneToMany)
// ...
protected getEvents() { // default method
return $this->events;
}
protected getActiveEvents() {
$expr = Criteria::expr();
$criteria = Criteria::create();
$criteria->where(
$expr->andX($expr->gte('start', $start), $expr->lte('end', $end)
));
return $this->events->matching($criteria);
}
}
推荐阅读
- sql - 根据 ID 条件连接两个表,并且第一个表中的日期介于另一个表中的其他两个日期之间
- react-native - 如何将应用程序的当前状态传递到选项卡导航屏幕
- javascript - 如何在 ngx-awesome-uploader 中更改裁剪后的图像背景颜色
- python - Plotly Express 乡村地区的合唱团
- python - 无法通过 python 请求调用 Azure 认知服务计算机视觉 OCR API
- mysql - MySQL 从其他表中选择两条记录?
- python - random.randint 的加权版本
- r - 计算对数总和的指数
- python - sqlalchemy.exc.ResourceClosedError:此连接已关闭错误
- vue.js - 具有多个 tbody 的 Vue.js 渲染表