Example #1
0
 public function actionAutocomplete($search = null, $id = null, $object_id = null)
 {
     /**
      * @todo Добавить отображение вложенности
      */
     $out = ['more' => false];
     if (!is_null($search)) {
         $query = new Query();
         $query->select(Property::tableName() . '.id, ' . Property::tableName() . '.name AS text')->from(Property::tableName())->andWhere(['like', Property::tableName() . '.name', $search])->limit(100);
         if (!is_null($object_id)) {
             $query->leftJoin(PropertyGroup::tableName(), PropertyGroup::tableName() . '.id = ' . Property::tableName() . '.property_group_id');
             $query->andWhere([PropertyGroup::tableName() . '.id' => $object_id]);
         }
         $command = $query->createCommand();
         $data = $command->queryAll();
         $out['results'] = array_values($data);
     } elseif ($id > 0) {
         $out['results'] = ['id' => $id, 'text' => Property::findOne($id)->name];
     } else {
         $out['results'] = ['id' => 0, 'text' => Yii::t('app', 'No matching records found')];
     }
     echo Json::encode($out);
 }
Example #2
0
 /**
  * @group subquery
  * @covers Query::leftJoin
  */
 function testLeftJoinPropelStyle()
 {
     $q = new Query('table');
     $q->leftJoin('table.bar_id', 'foo.bar_id');
     $this->assertEquals("SELECT `table`.*\nFROM `table`\n\tLEFT JOIN `foo` ON (`table`.`bar_id` = `foo`.`bar_id`)", (string) $q->getQuery());
 }
Example #3
0
 public function testDeleteStatement_LeftJoin_Prepend()
 {
     $query = new Query("DELETE FROM `test` LEFT JOIN x ON test.x_id = x.id");
     $query->leftJoin("abc", "test.id = abc.idTest", Query::PREPEND);
     $this->assertEquals("DELETE FROM `abc` LEFT JOIN (`test` LEFT JOIN x ON test.x_id = x.id) ON `test`.`id` = `abc`.`idTest`", (string) $query);
 }