I am having two models namely Patient Admission having two columns such as admission_date and discharge_date and another model daily_ward_entry having a date field say just date both models are related by ipd_patient_id
Now What I want is to create one or two validators, so that I can restrict the date entry in daily_ward_entry between admission_date and discharge_date
I had a look at the compare validator, but I can’t make out, how to replace the value to be compared with attribute from another model with relation.
I have tried following variations, but it always throwing error:
Variation one
[$this->discharge_date, 'compare', 'compareValue' => $this->admission_date, 'operator' => '>='],
error - Unknown Property – yii\base\UnknownPropertyException
Variation two
['discharge_date', 'compare', 'compareValue' => 'admission_date', 'operator' => '>='],
error - Discharge Date must be greater than or equal to "admission_date". This error is generated irrespective of date is lower or greater
variation three
[strtotime($this->discharge_date), 'compare', 'compareValue' =>strtotime($this->admission_date), 'operator' => '>='],
error - Unknown Property – yii\base\UnknownPropertyException
I need some direction and help. Thanks.