/** * @param SectionInterface $section * @param FieldInterface $field * * @return bool */ public function addFieldToSectionTable(SectionInterface $section, FieldInterface $field) { if (!$field->hasDatabaseColumn()) { return true; } Schema::table($section->getSectionTableName(), function ($table) use($field) { $field->onDatabaseCreate($table); $field->setDatabaseFieldType($table); }); return true; }
/** * @param array $attributes * @param SectionInterface|null $section */ public function __construct($attributes = [], SectionInterface $section = null) { $this->section = $section; if (!is_null($section)) { $this->table = $this->section->getSectionTableName(); $this->primaryKey = $section->getDocumentPrimaryKey(); if (!is_null($this->primaryKey) && $this->hasField($this->primaryKey)) { $field = $this->getFields()->get($this->primaryKey); if ($field instanceof Primary) { $this->incrementing = true; } } foreach ($this->getFields() as $field) { if (!$field instanceof FieldTypeOnlySystemInterface and $field->hasDatabaseColumn()) { $this->fillable[] = $field->getDBKey(); $this->setAttribute($field->getDBKey(), $field->getDefaultValue()); } if ($field instanceof FieldTypeRelationInterface) { $this->relationsFields[] = $field->getRelationName(); } } } parent::__construct($attributes); }
/** * @param DocumentInterface $document * @param SectionInterface|null $relatedSection * @param FieldInterface|null $relatedField * * @return HasOneRelation */ public function getDocumentRelation(DocumentInterface $document, SectionInterface $relatedSection = null, FieldInterface $relatedField = null) { return new HasOneRelation($relatedSection->getEmptyDocument()->newQuery(), $document, $relatedSection->getSectionTableName() . '.' . $this->getRelatedField()->getDBKey(), $this->getSection()->getDocumentPrimaryKey()); }
/** * @param SectionInterface $section */ public function dropSectionTable(SectionInterface $section) { Schema::dropIfExists($section->getSectionTableName()); }