sql - How to bound primary key to custom ON condition in Yii Relations? -
the problem: how bound primary key custom relation query? context, for: one source can relate several different modifications (many_many), each modification relate product (belongs_to). if several products has 1 source, means products same - that's criteria. (i can't merge same products, because may turn out not same, if merge them - can't split them back). so, when need find orders related product, want find orders same products, not current product. relation looks this: 'orderedproducts'=>array(self::has_many,'orderproduct','','on'=>('modification_id in ( select distinct ms2.modification_id products p1 left join products_modifications pm on pm.product_id = p1.product_id left join modifications_sources ms on ms.modification_id = pm.modification_id left join modifications_sources ms2 on ms2.source_id = ms.source_id p1.product_id='.$this->primarykey.' )')), 'orders'=>array(self::has_many,...