Exemplo n.º 1
0
 public static function getBody($class, $condition = [], $columns = [])
 {
     $bodyModel = new $class();
     $table = $bodyModel::tableName();
     if (empty($columns)) {
         $columns = $bodyModel->getTableSchema()->columns;
     }
     $selects = ['a.*'];
     foreach ((array) $columns as $column) {
         $columnName = '';
         if (is_string($column)) {
             $columnName = $column;
         } else {
             $columnName = $column->name;
         }
         $selects[] = "body.{$columnName} as body_{$columnName}";
     }
     $query = new Query();
     $query->select($selects)->from(['a' => Content::tableName()])->innerJoin(['body' => $table], '{{a}}.[[id]]={{body}}.[[content_id]]');
     if (!empty($condition)) {
         $query->andWhere($condition);
     }
     return $query;
 }