createRecord() public static method

If the initial data is empty, the AR object will not be created and null will be returned. (You should use the "new" operator to create the AR instance in that case.)
Since: 3.1.2
public static createRecord ( $type, $data ) : TActiveRecord
return TActiveRecord the initialized AR object. Null if the initial data is empty.
Beispiel #1
0
 /**
  * Apply result mapping.
  * @param array a result set row retrieved from the database
  * @param object the result object, will create if necessary.
  * @return object the result filled with data, null if not filled.
  */
 protected function applyResultMap($row, &$resultObject = null)
 {
     if ($row === false) {
         return null;
     }
     $resultMapName = $this->_statement->getResultMap();
     $resultClass = $this->_statement->getResultClass();
     $obj = null;
     if ($this->getManager()->getResultMaps()->contains($resultMapName)) {
         $obj = $this->fillResultMap($resultMapName, $row, null, $resultObject);
     } else {
         if (strlen($resultClass) > 0) {
             $obj = $this->fillResultClass($resultClass, $row, $resultObject);
         } else {
             $obj = $this->fillDefaultResultMap(null, $row, $resultObject);
         }
     }
     if (class_exists('TActiveRecord', false) && $obj instanceof TActiveRecord) {
         //Create a new clean active record.
         $obj = TActiveRecord::createRecord(get_class($obj), $obj);
     }
     return $obj;
 }
 /**
  * @param string active record class name.
  * @param array row data
  * @param array foreign key column names
  * @return TActiveRecord
  */
 protected function createFkObject($type, $row, $foreignKeys)
 {
     $obj = TActiveRecord::createRecord($type, $row);
     if (count($this->_association_columns) > 0) {
         $i = 0;
         foreach ($foreignKeys as $ref => $fk) {
             $obj->setColumnValue($ref, $row[$this->_association_columns[$i++]]);
         }
     }
     return $obj;
 }