lib/db/cortex.php
protected function _hasJoinMM_sql($key, $hasCond, &$filter, &$options) {
		$fieldConf = $this->fieldConf[$key]['has-many'];
		$relTable = $fieldConf['relTable'];
		$hasJoin = array();
		$mmTable = $this->mmTable($fieldConf,$key);
		if ($fieldConf['isSelf']) {
			$relTable .= '_ref';
			$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,$fieldConf['relField'].'_ref',$mmTable);
			$hasJoin[] = $this->_sql_left_join($key,$mmTable,$fieldConf['relPK'],
				[$fieldConf['relTable'],$relTable]);
			// cross-linked
			$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,
				$fieldConf['relField'],[$mmTable,$mmTable.'_c']);
			$hasJoin[] = $this->_sql_left_join($key.'_ref',$mmTable.'_c',$fieldConf['relPK'],
				[$fieldConf['relTable'],$relTable.'_c']);
			$this->_sql_mergeRelCondition($hasCond,$relTable,$filter,$options);
			$this->_sql_mergeRelCondition($hasCond,$relTable.'_c',$filter,$options,'OR');
		} else {
			$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,$fieldConf['relField'],$mmTable);
			$hasJoin[] = $this->_sql_left_join($key,$mmTable,$fieldConf['relPK'],$relTable);
			$this->_sql_mergeRelCondition($hasCond,$relTable,$filter,$options);
		}
		return $hasJoin;
	}
protected function _hasJoinMM_sql($key, $hasCond, &$filter, &$options) {
		$fieldConf = $this->fieldConf[$key]['has-many'];
		$relTable = $fieldConf['relTable'];
		$hasJoin = array();
		$mmTable = $this->mmTable($fieldConf,$key);
		if ($fieldConf['isSelf']) {
			$relTable .= '_ref';
			$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,$fieldConf['relField'].'_ref',$mmTable);
			$hasJoin[] = $this->_sql_left_join($key,$mmTable,$fieldConf['relPK'],
				[$fieldConf['relTable'],$relTable]);
			// cross-linked
			$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,
				$fieldConf['relField'],[$mmTable,$mmTable.'_c']);
			$hasJoin[] = $this->_sql_left_join($key.'_ref',$mmTable.'_c',$fieldConf['relPK'],
				[$fieldConf['relTable'],$relTable.'_c']);
			$this->_sql_mergeRelCondition($hasCond,$relTable,$filter,$options);
			$this->_sql_mergeRelCondition($hasCond,$relTable.'_c',$filter,$options,'OR');
		} else {
			$hasJoin[] = $this->_sql_left_join($this->primary,$this->table,$fieldConf['relField'],$mmTable);
			$hasJoin[] = $this->_sql_left_join($key,$mmTable,$fieldConf['relPK'],$relTable);
			$this->_sql_mergeRelCondition($hasCond,$relTable,$filter,$options);
		}
		return $hasJoin;
	}
protected function _hasJoinMM_sql ( $ key , $ hasCond , & $ filter , & $ options ) { $ fieldConf = $ this -> fieldConf [ $ key ] [ 'has-many' ] ; $ relTable = $ fieldConf [ 'relTable' ] ; $ hasJoin = array ( ) ; $ mmTable = $ this -> mmTable ( $ fieldConf , $ key ) ; if ( $ fieldConf [ 'isSelf' ] ) { $ relTable .= '_ref' ; $ hasJoin [ ] = $ this -> _sql_left_join ( $ this -> primary , $ this -> table , $ fieldConf [ 'relField' ] . '_ref' , $ mmTable ) ; $ hasJoin [ ] = $ this -> _sql_left_join ( $ key , $ mmTable , $ fieldConf [ 'relPK' ] , [ $ fieldConf [ 'relTable' ] , $ relTable ] ) ; // cross-linked $ hasJoin [ ] = $ this -> _sql_left_join ( $ this -> primary , $ this -> table , $ fieldConf [ 'relField' ] , [ $ mmTable , $ mmTable . '_c' ] ) ; $ hasJoin [ ] = $ this -> _sql_left_join ( $ key . '_ref' , $ mmTable . '_c' , $ fieldConf [ 'relPK' ] , [ $ fieldConf [ 'relTable' ] , $ relTable . '_c' ] ) ; $ this -> _sql_mergeRelCondition ( $ hasCond , $ relTable , $ filter , $ options ) ; $ this -> _sql_mergeRelCondition ( $ hasCond , $ relTable . '_c' , $ filter , $ options , 'OR' ) ; } else { $ hasJoin [ ] = $ this -> _sql_left_join ( $ this -> primary , $ this -> table , $ fieldConf [ 'relField' ] , $ mmTable ) ; $ hasJoin [ ] = $ this -> _sql_left_join ( $ key , $ mmTable , $ fieldConf [ 'relPK' ] , $ relTable ) ; $ this -> _sql_mergeRelCondition ( $ hasCond , $ relTable , $ filter , $ options ) ; } return $ hasJoin ; }
build query for SQL pivot table join and merge conditions
build query for SQL pivot table join and merge conditions