How do I select a value FROM a staging table?

  • 0
    There are three tables, in one table is a list of specialists, in the second a list of services, in the third table the relationship between specialists and services and the cost of services provided by a specialist.

    Now I can get a full description of the service associated with a specialist, but I cannot receive the cost of this service provided by this specialist.
    $model->services[0] // Описание услуги
    $model->services[0]->price //  тут должна быть цена услуги


    Well, on the other hand, I can get a list of specialists who provide this service, but I cannot get the price of this service:
    $model->specialists[0] // Информация о специалисте
    $model->specialists[0]->price //  error


    How can I choose the price of a service from the intermediate tables?

    Tables:
    Специалисты:  id | name
    Услуги:  id | name
    Услуги специалистов: id | service_id | specialist_id | price


    Specialist model:
    public function getServices() {
            return $this->hasMany(Services::className(), ['id' => 'service_id'])
                ->viaTable('services_specialist', ['specialist_id' => 'id']);
        }


    Service model:
    public function getSpecialists() {
            return $this->hasMany(Specialist::className(), ['id' => 'specialist_id'])
                ->viaTable('services_specialist', ['service_id' => 'id']);
        }
    MySQL Anonymous, Mar 13, 2019

  • 1 Answers
  • 0
    public function getPrice() {
    return $this->hasOne(ServicesSpecialist::className(), ['service_id' => 'id']);
    }
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!