Ejemplo n.º 1
0
 /**
  * Sets the foreign field of the column, if any.
  *
  * @param  \CI_Model               $model
  * @param  \Rougin\Describe\Column $column
  * @param  array                   $properties
  * @return void
  */
 protected function setForeignField(\CI_Model $model, Column $column, array $properties)
 {
     $columnName = $column->getField();
     $foreignColumn = $column->getReferencedField();
     $foreignTable = $column->getReferencedTable();
     if (in_array($foreignTable, $properties['belongs_to'])) {
         $delimiters = [$foreignColumn => $model->{$columnName}];
         $foreign = $this->find($foreignTable, $delimiters);
         if (is_object($foreign)) {
             $tableName = TableHelper::getNameFromModel($foreign);
             $model->{$tableName} = $foreign;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns the values from the model's properties.
  *
  * @param  array $properties
  * @return array
  */
 public function getRelationshipProperties(array $properties)
 {
     $belongsTo = [];
     foreach ($this->belongs_to as $item) {
         if (!in_array($item, $this->_with)) {
             continue;
         } elseif (!isset($this->{$item})) {
             $this->load->model($item);
         }
         array_push($belongsTo, TableHelper::getNameFromModel(new $item()));
     }
     $properties['belongs_to'] = $belongsTo;
     return $properties;
 }