framework/db/ar/CActiveFinder.php
private function populateRecord($query,$row)
	{
		// determine the primary key value
		if(is_string($this->_pkAlias))  // single key
		{
			if(isset($row[$this->_pkAlias]))
				$pk=$row[$this->_pkAlias];
			else	// no matching related objects
				return null;
		}
		else // is_array, composite key
		{
			$pk=array();
			foreach($this->_pkAlias as $name=>$alias)
			{
				if(isset($row[$alias]))
					$pk[$name]=$row[$alias];
				else	// no matching related objects
					return null;
			}
			$pk=serialize($pk);
		}

		// retrieve or populate the record according to the primary key value
		if(isset($this->records[$pk]))
			$record=$this->records[$pk];
		else
		{
			$attributes=array();
			$aliases=array_flip($this->_columnAliases);
			foreach($row as $alias=>$value)
			{
				if(isset($aliases[$alias]))
					$attributes[$aliases[$alias]]=$value;
			}
			$record=$this->model->populateRecord($attributes,false);
			foreach($this->children as $child)
			{
				if(!empty($child->relation->select))
					$record->addRelatedRecord($child->relation->name,null,$child->relation instanceof CHasManyRelation);
			}
			$this->records[$pk]=$record;
		}

		// populate child records recursively
		foreach($this->children as $child)
		{
			if(!isset($query->elements[$child->id]) || empty($child->relation->select))
				continue;
			$childRecord=$child->populateRecord($query,$row);
			if($child->relation instanceof CHasOneRelation || $child->relation instanceof CBelongsToRelation)
				$record->addRelatedRecord($child->relation->name,$childRecord,false);
			else // has_many and many_many
			{
				// need to double check to avoid adding duplicated related objects
				if($childRecord instanceof CActiveRecord)
					$fpk=serialize($childRecord->getPrimaryKey());
				else
					$fpk=0;
				if(!isset($this->_related[$pk][$child->relation->name][$fpk]))
				{
					if($childRecord instanceof CActiveRecord && $child->relation->index!==null)
						$index=$childRecord->{$child->relation->index};
					else
						$index=true;
					$record->addRelatedRecord($child->relation->name,$childRecord,$index);
					$this->_related[$pk][$child->relation->name][$fpk]=true;
				}
			}
		}

		return $record;
	}
private function populateRecord($query,$row)
	{
		// determine the primary key value
		if(is_string($this->_pkAlias))  // single key
		{
			if(isset($row[$this->_pkAlias]))
				$pk=$row[$this->_pkAlias];
			else	// no matching related objects
				return null;
		}
		else // is_array, composite key
		{
			$pk=array();
			foreach($this->_pkAlias as $name=>$alias)
			{
				if(isset($row[$alias]))
					$pk[$name]=$row[$alias];
				else	// no matching related objects
					return null;
			}
			$pk=serialize($pk);
		}

		// retrieve or populate the record according to the primary key value
		if(isset($this->records[$pk]))
			$record=$this->records[$pk];
		else
		{
			$attributes=array();
			$aliases=array_flip($this->_columnAliases);
			foreach($row as $alias=>$value)
			{
				if(isset($aliases[$alias]))
					$attributes[$aliases[$alias]]=$value;
			}
			$record=$this->model->populateRecord($attributes,false);
			foreach($this->children as $child)
			{
				if(!empty($child->relation->select))
					$record->addRelatedRecord($child->relation->name,null,$child->relation instanceof CHasManyRelation);
			}
			$this->records[$pk]=$record;
		}

		// populate child records recursively
		foreach($this->children as $child)
		{
			if(!isset($query->elements[$child->id]) || empty($child->relation->select))
				continue;
			$childRecord=$child->populateRecord($query,$row);
			if($child->relation instanceof CHasOneRelation || $child->relation instanceof CBelongsToRelation)
				$record->addRelatedRecord($child->relation->name,$childRecord,false);
			else // has_many and many_many
			{
				// need to double check to avoid adding duplicated related objects
				if($childRecord instanceof CActiveRecord)
					$fpk=serialize($childRecord->getPrimaryKey());
				else
					$fpk=0;
				if(!isset($this->_related[$pk][$child->relation->name][$fpk]))
				{
					if($childRecord instanceof CActiveRecord && $child->relation->index!==null)
						$index=$childRecord->{$child->relation->index};
					else
						$index=true;
					$record->addRelatedRecord($child->relation->name,$childRecord,$index);
					$this->_related[$pk][$child->relation->name][$fpk]=true;
				}
			}
		}

		return $record;
	}
private function populateRecord ( $ query , $ row ) { // determine the primary key value if ( is_string ( $ this -> _pkAlias ) ) // single key { if ( isset ( $ row [ $ this -> _pkAlias ] ) ) $ pk = $ row [ $ this -> _pkAlias ] ; else // no matching related objects return null ; } else // is_array, composite key { $ pk = array ( ) ; foreach ( $ this -> _pkAlias as $ name => $ alias ) { if ( isset ( $ row [ $ alias ] ) ) $ pk [ $ name ] = $ row [ $ alias ] ; else // no matching related objects return null ; } $ pk = serialize ( $ pk ) ; } // retrieve or populate the record according to the primary key value if ( isset ( $ this -> records [ $ pk ] ) ) $ record = $ this -> records [ $ pk ] ; else { $ attributes = array ( ) ; $ aliases = array_flip ( $ this -> _columnAliases ) ; foreach ( $ row as $ alias => $ value ) { if ( isset ( $ aliases [ $ alias ] ) ) $ attributes [ $ aliases [ $ alias ] ] = $ value ; } $ record = $ this -> model -> populateRecord ( $ attributes , false ) ; foreach ( $ this -> children as $ child ) { if ( ! empty ( $ child -> relation -> select ) ) $ record -> addRelatedRecord ( $ child -> relation -> name , null , $ child -> relation instanceof CHasManyRelation ) ; } $ this -> records [ $ pk ] = $ record ; } // populate child records recursively foreach ( $ this -> children as $ child ) { if ( ! isset ( $ query -> elements [ $ child -> id ] ) || empty ( $ child -> relation -> select ) ) continue ; $ childRecord = $ child -> populateRecord ( $ query , $ row ) ; if ( $ child -> relation instanceof CHasOneRelation || $ child -> relation instanceof CBelongsToRelation ) $ record -> addRelatedRecord ( $ child -> relation -> name , $ childRecord , false ) ; else // has_many and many_many { // need to double check to avoid adding duplicated related objects if ( $ childRecord instanceof CActiveRecord ) $ fpk = serialize ( $ childRecord -> getPrimaryKey ( ) ) ; else $ fpk = 0 ; if ( ! isset ( $ this -> _related [ $ pk ] [ $ child -> relation -> name ] [ $ fpk ] ) ) { if ( $ childRecord instanceof CActiveRecord && $ child -> relation -> index !== null ) $ index = $ childRecord -> { $ child -> relation -> index } ; else $ index = true ; $ record -> addRelatedRecord ( $ child -> relation -> name , $ childRecord , $ index ) ; $ this -> _related [ $ pk ] [ $ child -> relation -> name ] [ $ fpk ] = true ; } } } return $ record ; }
Populates the active records with the query data.
@param CJoinQuery $query the query executed
@param array $row a row of data
@return CActiveRecord the populated record
Populates the active records with the query data .