/** * @return Relation[] */ public function getValidRelations() { //get valid relations (keep downstream) if ($this->valid_relatios) { return $this->valid_relatios; } $ids_companies = $this->getCompaniesIDs(); //should exist at least two companies! $id_company_client = $this->getFirstClient()->getItem()->id; $id_company_provider = $this->getLastProvider()->getItem()->id; $ids_relations = $this->db->getQueryBuilderSelect('relations')->columns('id')->setGlueOr()->whereOr($this->db->createConditionAnds()->where('provider', $id_company_client)->whereRaw('client NOT IN ' . $this->db->quoteArray($ids_companies) . ''))->whereOr($this->db->createConditionAnds()->where('client', $id_company_provider)->whereRaw('provider NOT IN ' . $this->db->quoteArray($ids_companies) . ''))->loadValueArray(); $this->valid_relatios = $this->relationModel->getByIDs($ids_relations); return $this->valid_relatios; }