/** * @param AbstractTable $table * @param RecordSchema $record */ public function __construct(AbstractTable $table, RecordSchema $record) { $altered = []; foreach ($table->alteredColumns() as $column) { $altered[] = $column->getName(); } parent::__construct(\Spiral\interpolate('Passive table "{database}"."{table}" ({record}), were altered, columns: {columns}', ['database' => $record->getDatabase(), 'table' => $table->getName(), 'record' => $record, 'columns' => join(', ', $altered)])); }
/** * @param RecordSchema $record * @return string */ protected function renderNestedMany(RecordSchema $record) { $relationElement = new ClassElement($elementName = $this->createName($record->getName(), 'nested', 'relation')); //Clone schema from appropriate relation $relationElement->cloneSchema($relationClass = ManyToMany::class); $this->cleanElement($relationElement); $relationElement->setParent('\\' . $relationClass)->setInterfaces([]); $name = $record->getName(); $relationElement->replaceComments('Record|Record[]|RecordIterator', $this->helper('iterator', $name) . "|\\{$name}[]"); $relationElement->replaceComments(Record::class, $name); $relationElement->replaceComments("Record", '\\' . $name); $relationElement->replaceComments("Selector", $this->helper('selector', $name)); $relationElement->replaceComments("@return \$this", "@return \$this|{$elementName}|\\{$name}[]"); return $this->addClass($relationElement); }
/** * Normalize and pack every declared record relation schema. * * @param RecordSchema $record * @return array */ private function packRelations(RecordSchema $record) { $result = []; foreach ($record->getRelations() as $name => $relation) { $result[$name] = $relation->normalizeSchema(); } return $result; }
/** * Create set of options to specify missing relation definition fields. * * @return array */ protected function proposedDefinitions() { $options = ['name' => $this->name, 'name:plural' => Inflector::pluralize($this->name), 'name:singular' => Inflector::singularize($this->name), 'record:role' => $this->record->getRole(), 'record:table' => $this->record->getTable(), 'record:primaryKey' => $this->record->getPrimaryKey()]; //Some options may use values declared in other definition fields $proposed = [RecordEntity::OUTER_KEY => 'outerKey', RecordEntity::INNER_KEY => 'innerKey', RecordEntity::PIVOT_TABLE => 'pivotTable']; foreach ($proposed as $property => $alias) { if (isset($this->definition[$property])) { //Let's create some default options based on user specified values $options['definition:' . $alias] = $this->definition[$property]; } } if ($this->builder->hasRecord($this->target)) { $options = $options + ['outer:role' => $this->outerRecord()->getRole(), 'outer:table' => $this->outerRecord()->getTable(), 'outer:primaryKey' => $this->outerRecord()->getPrimaryKey()]; } return $options; }