Answer the question
In order to leave comments, you need to log in
Yii2: How to pull cities by condition?
Got something wrong, guys. there are 2 models. City and Club (there are many clubs in the city. Club 1 to the city)
in short, you need to display all cities from known clubs.
made by the city
public function getClubs(){
return $this->hasMany(Club::className(), ['city_id'=>'id']);
}
$_cities = City::find()->joinWith('clubs')->where(['LIKE', 'name_ru', $term])->all();
Answer the question
In order to leave comments, you need to log in
$_cities = City::find()->joinWith('clubs', true, 'INNER JOIN')->where(['LIKE', 'net_city.name_ru', $term])->all();
Two tables connected via hasMany:
a) cart --- Cart
b) goods --- Goods
$result = (new \yii\db\Query())
->select([])
->from([ 'cart'])
->innerJoin(['goods'])
->where(['cart_ip' => $_SERVER['REMOTE_ADDR']])
->andWhere('`cart_good_id` = `goods_id`')
-> groupBy(['cart_good_id'])
->all();
return $this->render('index',['result' => $result]);
<?php foreach ( $result as $row):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question