Answer the question
In order to leave comments, you need to log in
How to get response in Query Builder?
Have a request
$query = Country::find();
$SubQuery = $query->select(['id'])->from('partner')->where(['phone' => 9301111111])->createCommand()->rawSql;
echo '<pre>'; var_dump($SubQuery); echo '</pre>';
string(51) "SELECT `id` FROM `partner` WHERE `phone`=9301111111"
$SubQuery = $query->select(['id'])->from('partner')->where(['phone' => 9301111111])->one();
object(app\models\Country)#96 (8) {
["_attributes":"yii\db\BaseActiveRecord":private]=>
array(0) {
}
["_oldAttributes":"yii\db\BaseActiveRecord": private]=>
array(0) {
}
["_related":"yii\db\BaseActiveRecord":private]=>
array(0) {
}
["_errors":"yii\base\Model":private]=>
NULL
["_validators":"yii\base\Model":private]=>
NULL
["_scenario":"yii\base\Model":private]=>
string(7) "default"
["_events":"yii \base\Component":private]=>
array(0) {
}
["_behaviors":"yii\base\Component":private]=>
array(0) {
}
}
Answer the question
In order to leave comments, you need to log in
It seems that the ID refers to the primary key and it is not in the attributes, and you specified only its selection in the select; If you just need id, then $SubQuery->id, if there are other fields, then you need to list them in the select or remove them altogether, then it will return all the fields. It's not clear what you want
If you select by "phone", then why is it not in the select?
Try:
$model = Country::find()
->select(['id','phone'])
->from('partner')
->where(['phone' => 9301111111])
->one();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question