У меня ниже требование присоединения к дополнительной модели city
перед выполнением запроса.
Здесь в приведенном ниже коде столбец timezone
находится в таблице city
.
$this->user->dishwasher->jobs()
->whereBetween("start_date_time", ["convert_tz( now() + interval 1440 minute, '$this->configTimeZone', timezone)", "convert_tz(NOW()+ INTERVAL 10080 MINUTE, '$this->configTimeZone', timezone)"])
->get();
Я попытался добавить with
свойство на Dishwasher
модальный
class Dishwasher extends Model {
protected $with = ['city'];
public function user() {
return $this->belongsTo('App\User');
}
public function jobs() {
return $this->belongsToMany('App\Job');
}
public function city() {
return $this->belongsTo("App\City");
}
}
Также я попытался добавить with
свойство.
$this->user->dishwasher->jobs()
->whereBetween("start_date_time", ["convert_tz( now() + interval 1440 minute, '$this->configTimeZone', timezone)", "convert_tz(NOW()+ INTERVAL 10080 MINUTE, '$this->configTimeZone', timezone)"])
->with(['city'])
->get();
Но в конце я оказался в одном запросе только,
select
`jobs`.*,
`dishwasher_jobs`.`dishwasher_id` as `pivot_dishwasher_id`,
`dishwasher_jobs`.`job_id` as `pivot_job_id`,
`dishwasher_jobs`.`id` as `pivot_id`
from `jobs`
inner join `dishwasher_jobs` on `jobs`.`id` = `dishwasher_jobs`.`job_id`
where `dishwasher_jobs`.`dishwasher_id` = ?
and `start_date_time` between ? and ?
Могу ли я узнать, как я могу добавить дополнительные соединения модальных, чтобы я мог использовать в состоянии where
?