Пример #1
0
 protected function prepareRelationships(Entity $entity)
 {
     $attributes = [];
     $relationships = $entity->getRelationshipConfig();
     foreach ($relationships as $relationship) {
         $table = $relationship['table'];
         $foreignKey = $this->underscore($relationship['entity']) . '_id';
         $localKey = $this->underscore($entity->getEntityName()) . '_id';
         $attribute = $this->applyAttributeDefaults(['parent' => $relationship['entity']]);
         if ($relationship['type'] == Relationship::HAS_PIVOT && !isset($this->pivots[$relationship['table']])) {
             $this->pivots[$table][$foreignKey] = $attribute;
             $this->pivots[$table][$localKey] = $this->applyAttributeDefaults(['parent' => $entity->getEntityName()]);
         } elseif ($relationship['type'] == Relationship::HAS_ONE) {
             $attributes[$foreignKey] = $attribute;
         } elseif ($relationship['type'] == Relationship::BELONGS_TO) {
             $attributes[$foreignKey] = $attribute;
         }
     }
     return $attributes;
 }