D
D
darknet372019-09-11 12:27:39
Yii
darknet37, 2019-09-11 12:27:39

Sampling data with enumeration. Yii2?

Good afternoon. I have a problem. There is this sample:

$ser_spec = ServiceSpec::find()->where(['specialist_id' => $specialist['id']])->asArray()->all();

The result of this request:
Array
(
    [0] => Array
        (
            [id] => 1
            [service_id] => 1
            [specialist_id] => 1
        )
    [1] => Array
        (
            [id] => 8
            [service_id] => 2
            [specialist_id] => 1
        )
    [2] => Array
        (
            [id] => 9
            [service_id] => 3
            [specialist_id] => 1
        )
)

I need to somehow get only the field values ​​from this: service_id. And make a query to the Services table, where id => service_id
Please tell me how can I do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2019-09-11
@darknet37

Set up links in the models and follow the example as here
You will get a link call: $model->serSpec Extract
from the documentation

class Customer extends ActiveRecord
{
    public function getOrders()
    {
        return $this->hasMany(Order::className(), ['customer_id' => 'id']);
    }
}

class Order extends ActiveRecord
{
    public function getCustomer()
    {
        return $this->hasOne(Customer::className(), ['id' => 'customer_id']);
    }
}

// SELECT * FROM `customer` WHERE `id` = 123
$customer = Customer::findOne(123);

// SELECT * FROM `order` WHERE `customer_id` = 123
// $orders - это массив объектов Order
$orders = $customer->orders;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question