I have Yii2 relations
Model Variants (simplified)
Variants hasOne Reference Sequence
public function getReferenceSequence()
{
return $this->hasOne(ReferenceSequences::className(), ['id' => 'reference_sequence_id'])->alias('referenceSequence');
}
Variants hasMany Annotations via ReferenceSequence
I want to join Annotations based on the model property 'start' and 'end'(integer values) using comparison operators.
THIS DOESN'T WORK
public function getAnnotations()
{
return $this->hasMany(Annotations::className(), ['chrom' => 'name'])
->via('referenceSequence')
->andOnCondition(['AND',['>=','tx_start',$this->start],['<=','tx_start',$this->end]])
->alias('annotations');
}
I'm looking for the Annotations that have the same chromosome, but also fall within the start/end range for the Variants model.
Instead of trying to inject the model properties $this->start and $this->end which for some reason only results in one pair of values being used, rather than each search result model joining on the properties of the $this object, I want to use an alias to the parent table.
The 'on' condition should be something like:
->andOnCondition(['AND',['>=','tx_start','VARIANTS_MODEL_ALIAS.start],['<=','tx_start',VARIANTS_MODEL_ALIAS.end]])
In Yii1 there was the magic "t" alias but this doesn't work any more.