예제 #1
0
 /**
  * Returns the Dao function as SQL
  *
  * @param $builder       Builder\Where the sql query builder
  * @param $property_path string the property path
  * @param $prefix        string
  * @return string
  */
 public function toSql(Builder\Where $builder, $property_path, $prefix = '')
 {
     $joins = $builder->getJoins();
     // sub-query
     $class_name = $joins->getStartingClassName();
     $properties = $this->properties + [$property_path => Func::max()];
     $sub_builder = new Builder\Select($class_name, $properties, null, $builder->getSqlLink(), [Dao::groupBy($this->properties)]);
     // join
     $join = new Subquery($sub_builder);
     $joins->addJoin($join);
     // where
     $where = '';
     foreach (array_merge($this->properties, [$property_path]) as $property) {
         $where .= ' AND ' . $join->foreign_alias . DOT . BQ . rLastParse($property, DOT, 1, true) . BQ . ' = ' . $builder->buildColumn($property, $prefix);
     }
     $join->where = substr($where, 5);
     return null;
 }
예제 #2
0
 /**
  * @param $properties_path string[]
  * @return Group_By|null
  */
 private function groupBy($properties_path)
 {
     foreach ($properties_path as $property_path) {
         if (strpos($property_path, DOT)) {
             return Dao::groupBy(array_merge(['id'], $properties_path));
         }
     }
     return null;
 }