framework/db/ar/CActiveFinder.php
private function joinOneMany($fke,$fks,$pke,$parent)
	{
		$schema=$this->_builder->getSchema();
		$joins=array();
		if(is_string($fks))
			$fks=preg_split('/\s*,\s*/',$fks,-1,PREG_SPLIT_NO_EMPTY);
		foreach($fks as $i=>$fk)
		{
			if(!is_int($i))
			{
				$pk=$fk;
				$fk=$i;
			}

			if(!isset($fke->_table->columns[$fk]))
				throw new CDbException(Yii::t('yii','The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key "{key}". There is no such column in the table "{table}".',
					array('{class}'=>get_class($parent->model), '{relation}'=>$this->relation->name, '{key}'=>$fk, '{table}'=>$fke->_table->name)));

			if(is_int($i))
			{
				if(isset($fke->_table->foreignKeys[$fk]) && $schema->compareTableNames($pke->_table->rawName, $fke->_table->foreignKeys[$fk][0]))
					$pk=$fke->_table->foreignKeys[$fk][1];
				else // FK constraints undefined
				{
					if(is_array($pke->_table->primaryKey)) // composite PK
						$pk=$pke->_table->primaryKey[$i];
					else
						$pk=$pke->_table->primaryKey;
				}
			}

			$joins[]=$fke->getColumnPrefix().$schema->quoteColumnName($fk) . '=' . $pke->getColumnPrefix().$schema->quoteColumnName($pk);
		}
		if(!empty($this->relation->on))
			$joins[]=$this->relation->on;

		if(!empty($this->relation->joinOptions) && is_string($this->relation->joinOptions))
			return $this->relation->joinType.' '.$this->getTableNameWithAlias().' '.$this->relation->joinOptions.
				' ON ('.implode(') AND (',$joins).')';
		else
			return $this->relation->joinType.' '.$this->getTableNameWithAlias().' ON ('.implode(') AND (',$joins).')';
	}
private function joinOneMany($fke,$fks,$pke,$parent)
	{
		$schema=$this->_builder->getSchema();
		$joins=array();
		if(is_string($fks))
			$fks=preg_split('/\s*,\s*/',$fks,-1,PREG_SPLIT_NO_EMPTY);
		foreach($fks as $i=>$fk)
		{
			if(!is_int($i))
			{
				$pk=$fk;
				$fk=$i;
			}

			if(!isset($fke->_table->columns[$fk]))
				throw new CDbException(Yii::t('yii','The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key "{key}". There is no such column in the table "{table}".',
					array('{class}'=>get_class($parent->model), '{relation}'=>$this->relation->name, '{key}'=>$fk, '{table}'=>$fke->_table->name)));

			if(is_int($i))
			{
				if(isset($fke->_table->foreignKeys[$fk]) && $schema->compareTableNames($pke->_table->rawName, $fke->_table->foreignKeys[$fk][0]))
					$pk=$fke->_table->foreignKeys[$fk][1];
				else // FK constraints undefined
				{
					if(is_array($pke->_table->primaryKey)) // composite PK
						$pk=$pke->_table->primaryKey[$i];
					else
						$pk=$pke->_table->primaryKey;
				}
			}

			$joins[]=$fke->getColumnPrefix().$schema->quoteColumnName($fk) . '=' . $pke->getColumnPrefix().$schema->quoteColumnName($pk);
		}
		if(!empty($this->relation->on))
			$joins[]=$this->relation->on;

		if(!empty($this->relation->joinOptions) && is_string($this->relation->joinOptions))
			return $this->relation->joinType.' '.$this->getTableNameWithAlias().' '.$this->relation->joinOptions.
				' ON ('.implode(') AND (',$joins).')';
		else
			return $this->relation->joinType.' '.$this->getTableNameWithAlias().' ON ('.implode(') AND (',$joins).')';
	}
private function joinOneMany ( $ fke , $ fks , $ pke , $ parent ) { $ schema = $ this -> _builder -> getSchema ( ) ; $ joins = array ( ) ; if ( is_string ( $ fks ) ) $ fks = preg_split ( '/\s*,\s*/' , $ fks , - 1 , PREG_SPLIT_NO_EMPTY ) ; foreach ( $ fks as $ i => $ fk ) { if ( ! is_int ( $ i ) ) { $ pk = $ fk ; $ fk = $ i ; } if ( ! isset ( $ fke -> _table -> columns [ $ fk ] ) ) throw new CDbException ( Yii :: t ( 'yii' , 'The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key "{key}". There is no such column in the table "{table}".' , array ( '{class}' => get_class ( $ parent -> model ) , '{relation}' => $ this -> relation -> name , '{key}' => $ fk , '{table}' => $ fke -> _table -> name ) ) ) ; if ( is_int ( $ i ) ) { if ( isset ( $ fke -> _table -> foreignKeys [ $ fk ] ) && $ schema -> compareTableNames ( $ pke -> _table -> rawName , $ fke -> _table -> foreignKeys [ $ fk ] [ 0 ] ) ) $ pk = $ fke -> _table -> foreignKeys [ $ fk ] [ 1 ] ; else // FK constraints undefined { if ( is_array ( $ pke -> _table -> primaryKey ) ) // composite PK $ pk = $ pke -> _table -> primaryKey [ $ i ] ; else $ pk = $ pke -> _table -> primaryKey ; } } $ joins [ ] = $ fke -> getColumnPrefix ( ) . $ schema -> quoteColumnName ( $ fk ) . '=' . $ pke -> getColumnPrefix ( ) . $ schema -> quoteColumnName ( $ pk ) ; } if ( ! empty ( $ this -> relation -> on ) ) $ joins [ ] = $ this -> relation -> on ; if ( ! empty ( $ this -> relation -> joinOptions ) && is_string ( $ this -> relation -> joinOptions ) ) return $ this -> relation -> joinType . ' ' . $ this -> getTableNameWithAlias ( ) . ' ' . $ this -> relation -> joinOptions . ' ON (' . implode ( ') AND (' , $ joins ) . ')' ; else return $ this -> relation -> joinType . ' ' . $ this -> getTableNameWithAlias ( ) . ' ON (' . implode ( ') AND (' , $ joins ) . ')' ; }
Generates the join statement for one-many relationship.
This works for HAS_ONE, HAS_MANY and BELONGS_TO.
@param CJoinElement $fke the join element containing foreign keys
@param array $fks the foreign keys
@param CJoinElement $pke the join element contains primary keys
@param CJoinElement $parent the parent join element
@return string the join statement
@throws CDbException if a foreign key is invalid
Generates the join statement for one - many relationship . This works for HAS_ONE HAS_MANY and BELONGS_TO .