【问题标题】:Is it possible to do joins in Doctrine with the Criteria functionality?是否可以使用 Criteria 功能在 Doctrine 中加入?
【发布时间】:2018-11-17 00:41:19
【问题描述】:
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);
}

假设我的事件实体有一个类别并且类别有很多事件,我将如何过滤这些?

【问题讨论】:

    标签: symfony join doctrine criteria dql


    【解决方案1】:

    如果你想收集类别对象上的非活动事件,你可以使用条件类

    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);
        }
    }
    

    How filter data inside entity object in Symfony 2 and Doctrine

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-04
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多