public function write(WriterInterface $writer)
 {
     $writer->write('%s:', $this->getName())->indent()->writeCallback(function (WriterInterface $writer, Index $_this = null) {
         $writer->write('fields: [%s]', implode(', ', $_this->getColumnNames()));
     })->writeIf(($type = strtolower($this->parameters->get('indexType'))) !== 'index', 'type: ' . $type)->outdent();
     return $this;
 }
 public function writeTable(WriterInterface $writer)
 {
     if (!$this->isExternal()) {
         $writer->open($this->getTableFileName())->write('%s:', $this->getModelName())->indent()->writeIf($actAs = trim($this->getActAsBehaviour()), $actAs)->write('tableName: ' . ($this->getDocument()->getConfig()->get(Formatter::CFG_EXTEND_TABLENAME_WITH_SCHEMA) ? $this->getSchema()->getName() . '.' : '') . $this->getRawTableName())->writeCallback(function (WriterInterface $writer, Table $_this = null) {
             $_this->getColumns()->write($writer);
         })->writeCallback(function (WriterInterface $writer, Table $_this = null) {
             $externalRelation = $_this->getExternalRelations();
             if (count($_this->getRelations()) || $externalRelation) {
                 $writer->write('relations:');
                 $writer->indent();
                 foreach ($_this->getRelations() as $relation) {
                     $relation->write($writer);
                 }
                 if ($externalRelation) {
                     $writer->write($externalRelation);
                 }
                 $writer->outdent();
             }
         })->writeCallback(function (WriterInterface $writer, Table $_this = null) {
             if (count($_this->getIndexes())) {
                 $writer->write('indexes:');
                 $writer->indent();
                 foreach ($_this->getIndexes() as $index) {
                     $index->write($writer);
                 }
                 $writer->outdent();
             }
         })->write('options:')->indent()->write('charset: ' . (($charset = $this->parameters->get('defaultCharacterSetName')) ? $charset : 'utf8'))->writeIf($engine = $this->parameters->get('tableEngine'), 'type: ' . $engine)->outdent()->outdent()->close();
         return self::WRITE_OK;
     }
     return self::WRITE_EXTERNAL;
 }
 /**
  * (non-PHPdoc)
  * @see \MwbExporter\Model\Schema::write()
  */
 public function write(WriterInterface $writer)
 {
     $writer->open($this->getDocument()->translateFilename($this))->write('<?xml version="1.0" encoding="UTF-8"?>')->write('<database name="%s" defaultIdMethod="native">', $this->getName())->writeCallback(function (WriterInterface $writer, Schema $_this = null) {
         $_this->writeSchema($writer);
     })->write('</database>')->close();
     return $this;
 }
 public function writeTable(WriterInterface $writer)
 {
     if (!$this->isExternal()) {
         $writer->open($this->getTableFileName())->write('<?php')->write('')->write('class ' . $this->getTablePrefix() . $this->getModelName() . 'Controller extends ' . $this->getParentTable())->write('{')->indent()->write('')->outdent()->write('}')->write('')->close();
         return self::WRITE_OK;
     }
     return self::WRITE_EXTERNAL;
 }
 public function writeTable(WriterInterface $writer)
 {
     if (!$this->isExternal()) {
         $writer->open($this->getTableFileName())->write('%s.%s = Ext.extend(%s, %s);', $this->getClassPrefix(), $this->getModelName(), $this->getParentClass(), $this->asModel())->write('')->write('%1$s.%2$s = Ext.extend(%1$s.%2$s, %3$s);', $this->getClassPrefix(), $this->getModelName(), $this->asUI())->write('')->close();
         return self::WRITE_OK;
     }
     return self::WRITE_EXTERNAL;
 }
 /**
  * Write model body code.
  * 
  * @param \MwbExporter\Writer\WriterInterface $writer
  * @return \MwbExporter\Formatter\Node\Sequelize\Model\Table
  */
 protected function writeBody(WriterInterface $writer)
 {
     $writer->writeCallback(function (WriterInterface $writer, Table $_this = null) {
         if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) {
             $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_JS))->write('');
         }
     })->write("module.exports = function(sequelize, DataTypes) {")->indent()->write("return sequelize.define('%s', %s, %s);", $this->getModelName(), $this->asModel(), $this->asOptions())->outdent()->write("}");
     return $this;
 }
 public function write(WriterInterface $writer)
 {
     $writer->write('columns:')->indent()->writeCallback(function (WriterInterface $writer, Columns $_this = null) {
         foreach ($_this as $column) {
             $column->write($writer);
         }
     })->outdent();
     return $this;
 }
 /**
  * Write model body code.
  * 
  * @param \MwbExporter\Writer\WriterInterface $writer
  * @return \MwbExporter\Formatter\Sencha\ExtJS4\Model\Table
  */
 public function writeBody(WriterInterface $writer)
 {
     $writer->writeCallback(function (WriterInterface $writer, Table $_this = null) {
         if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) {
             $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_JS))->write('');
         }
     })->write("Ext.define('%s', %s);", $this->getClassPrefix() . '.' . $this->getModelName(), $this->asModel());
     return $this;
 }
 public function write(WriterInterface $writer)
 {
     if ($this->referencedTable == null) {
         $writer->write('# There is another foreign key declaration.');
     } else {
         $writer->write('%s:', 0 === strpos($this->parameters->get('name'), 'd:') ? substr($this->parameters->get('name'), 2) : $this->referencedTable->getModelName())->indent()->write('class: ' . $this->referencedTable->getModelName())->write('local: ' . $this->foreign->getColumnName())->write('foreign: ' . $this->local->getColumnName())->write('foreignAlias: ' . (($alias = $this->getForeignAlias()) ? $alias : ($this->isManyToOne() ? Inflector::pluralize($this->referencedTable->getModelName()) : $this->referencedTable->getModelName())))->write('onDelete: ' . strtolower($this->parameters->get('deleteRule')))->write('onUpdate: ' . strtolower($this->parameters->get('updateRule')))->outdent();
     }
     return $this;
 }
 public function writeView(WriterInterface $writer)
 {
     if (!$this->isExternal()) {
         $namespace = $this->getConfig()->get(Formatter::CFG_NAMESPACE);
         $writer->indent()->write('<table name="%s" phpName="%s" namespace="%s" skipSql="true" readOnly="true">', $this->getRawViewName(), $this->getModelName(), $namespace)->write('</table>')->outdent();
         return self::WRITE_OK;
     }
     return self::WRITE_EXTERNAL;
 }
 /**
  * (non-PHPdoc)
  * @see \MwbExporter\Model\Schema::write()
  */
 public function write(WriterInterface $writer)
 {
     $writer->open($this->getDocument()->translateFilename(null, $this))->write('<?xml version="1.0" encoding="UTF-8"?>')->writeCallback(function (WriterInterface $writer, Schema $_this = null) {
         if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) {
             $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_XML));
         }
     })->write('<database name="%s" defaultIdMethod="native">', $this->getName())->writeCallback(function (WriterInterface $writer, Schema $_this = null) {
         $_this->writeSchema($writer);
     })->write('</database>')->close();
     return $this;
 }
 public function writeGetterAndSetter(WriterInterface $writer)
 {
     if (!$this->isIgnored()) {
         $this->getDocument()->addLog(sprintf('  Writing setter/getter for column "%s"', $this->getColumnName()));
         $table = $this->getTable();
         $converter = $this->getFormatter()->getDatatypeConverter();
         $nativeType = $converter->getNativeType($converter->getMappedType($this));
         $writer->write('/**')->write(' * Set the value of ' . $this->getColumnName() . '.')->write(' *')->write(' * @param ' . $nativeType . ' $' . $this->getColumnName())->write(' * @return ' . $table->getNamespace())->write(' */')->write('public function set' . $this->getBeautifiedColumnName() . '($' . $this->getColumnName() . ')')->write('{')->indent()->write('$this->' . $this->getColumnName() . ' = $' . $this->getColumnName() . ';')->write('')->write('return $this;')->outdent()->write('}')->write('')->write('/**')->write(' * Get the value of ' . $this->getColumnName() . '.')->write(' *')->write(' * @return ' . $nativeType)->write(' */')->write('public function get' . $this->getBeautifiedColumnName() . '()')->write('{')->indent()->write('return $this->' . $this->getColumnName() . ';')->outdent()->write('}')->write('');
     }
     return $this;
 }
 public function writeTable(WriterInterface $writer)
 {
     if (!$this->isExternal()) {
         $writer->open($this->getTableFileName())->write('<?php')->write('')->writeCallback(function (WriterInterface $writer, Table $_this = null) {
             if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) {
                 $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_PHP))->write('');
             }
         })->write('class ' . $this->getTablePrefix() . $this->getModelName() . 'Controller extends ' . $this->getParentTable())->write('{')->indent()->write('')->outdent()->write('}')->write('')->close();
         return self::WRITE_OK;
     }
     return self::WRITE_EXTERNAL;
 }
 public function write(WriterInterface $writer)
 {
     $type = strtoupper($this->getFormatter()->getDatatypeConverter()->getType($this));
     if ($type == 'DECIMAL') {
         $type = $type . '" size="' . $this->parameters->get('precision') . '" scale="' . $this->parameters->get('scale');
     }
     if ($type == 'ENUM' or $type == 'SET') {
         $type = $type . '" sqlType="' . $type . $this->parameters->get('datatypeExplicitParams') . '" valueSet="' . substr($this->parameters->get('datatypeExplicitParams'), 1, -1);
     }
     $writer->write('<column name="%s" type="%s"%s%s%s%s%s%s />', $this->getColumnName(), $type, $this->isPrimary == 1 ? ' primaryKey="true"' : '', $this->parameters->get('length') > 0 ? ' size="' . $this->parameters->get('length') . '"' : '', $this->isNotNull() ? ' required="true"' : '', $this->isAutoIncrement() ? ' autoIncrement="true"' : '', ($defaultValue = $this->getDefaultValue()) && !in_array($defaultValue, array('CURRENT_TIMESTAMP')) ? ' defaultValue="' . $defaultValue . '"' : '', $defaultValue ? ' defaultExpr="' . $defaultValue . '"' : '');
     return $this;
 }
 public function writeTable(WriterInterface $writer)
 {
     switch (true) {
         case $this->isExternal():
             return self::WRITE_EXTERNAL;
         case $this->isManyToMany():
             return self::WRITE_M2M;
         default:
             $writer->open($this->getTableFileName())->write($this->asYAML())->close();
             return self::WRITE_OK;
     }
 }
 /**
  * (non-PHPdoc)
  * @see \MwbExporter\Model\Schema::write()
  */
 public function write(WriterInterface $writer)
 {
     $data = $this->asYAML();
     $indent = $this->getConfig()->get(Formatter::CFG_INDENTATION);
     $yaml = new YAML($data, array('indent' => $indent, 'inline' => true, 'inline_size' => $this->getInlineSize($data) + ($this->getArrayLevel($data) - 1) * $indent));
     $writer->open($this->getDocument()->translateFilename(null, $this))->writeCallback(function (WriterInterface $writer, Schema $_this = null) {
         if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) {
             $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_YAML))->write('');
         }
     })->write($yaml)->close();
     return $this;
 }
 public function writeTable(WriterInterface $writer)
 {
     if (!$this->isExternal()) {
         $writer->open($this->getTableFileName())->writeCallback(function (WriterInterface $writer, Table $_this = null) {
             if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) {
                 $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_JS))->write('');
             }
         })->write('%s.%s = Ext.extend(%s, %s);', $this->getClassPrefix(), $this->getModelName(), $this->getParentClass(), $this->asModel())->write('')->write('%1$s.%2$s = Ext.extend(%1$s.%2$s, %3$s);', $this->getClassPrefix(), $this->getModelName(), $this->asUI())->write('')->close();
         return self::WRITE_OK;
     }
     return self::WRITE_EXTERNAL;
 }
 public function writeGetterAndSetter(WriterInterface $writer)
 {
     if (!$this->isIgnored()) {
         $this->getDocument()->addLog(sprintf('  Writing setter/getter for column "%s"', $this->getColumnName()));
         $table = $this->getTable();
         $converter = $this->getFormatter()->getDatatypeConverter();
         $nativeType = $converter->getNativeType($converter->getMappedType($this));
         $shouldTypehintProperties = $this->getConfig()->get(Formatter::CFG_PROPERTY_TYPEHINT);
         $typehint = $shouldTypehintProperties && class_exists($nativeType) ? "{$nativeType} " : '';
         $writer->write('/**')->write(' * Set the value of ' . $this->getColumnName() . '.')->write(' *')->write(' * @param ' . $nativeType . ' $' . $this->getColumnName())->write(' * @return ' . $table->getNamespace())->write(' */')->write('public function set' . $this->getBeautifiedColumnName() . '(' . $typehint . '$' . $this->getColumnName() . ')')->write('{')->indent()->write('$this->' . $this->getColumnName() . ' = $' . $this->getColumnName() . ';')->write('')->write('return $this;')->outdent()->write('}')->write('')->write('/**')->write(' * Get the value of ' . $this->getColumnName() . '.')->write(' *')->write(' * @return ' . $nativeType)->write(' */')->write('public function get' . $this->getBeautifiedColumnName() . '()')->write('{')->indent()->write('return $this->' . $this->getColumnName() . ';')->outdent()->write('}')->write('');
     }
     return $this;
 }
 public function write(WriterInterface $writer)
 {
     $writer->write('%s:', $this->getColumnName())->indent()->write('type: %s', $this->getDocument()->getFormatter()->getDatatypeConverter()->getType($this))->writeIf($this->isPrimary(), 'primary: true')->writeIf($this->isNotNull(), 'notnull: true')->writeIf($this->isAutoIncrement(), 'autoincrement: true')->writeCallback(function (WriterInterface $writer, Column $_this = null) {
         if ($values = $_this->getParameters()->get('datatypeExplicitParams')) {
             $writer->write('values: %s', strtr($values, array('(' => '[', ')' => ']')));
         }
     })->writeIf($default = $this->getDefaultValue(), 'default: ' . $default)->writeCallback(function (WriterInterface $writer, Column $_this = null) {
         foreach ($_this->getNode()->xpath("value[@key='flags']/value") as $flag) {
             $writer->write(strtolower($flag) . ': true');
         }
     })->outdent();
     return $this;
 }
 public function writeReferences(WriterInterface $writer)
 {
     $writer->write('/**')->write(' * @var array')->write(' */')->writeCallback(function (WriterInterface $writer, Table $_this = null) {
         if (count($_this->getForeignKeys())) {
             $writer->write('protected $_referenceMap = array(');
             $writer->indent();
             foreach ($_this->getForeignKeys() as $foreignKey) {
                 $foreignKey->write($writer);
             }
             $writer->outdent();
             $writer->write(');');
         } else {
             $writer->write('protected $_referenceMap = array();');
         }
     });
     return $this;
 }
 public function writeTable(WriterInterface $writer)
 {
     switch (true) {
         case $this->isExternal():
             return self::WRITE_EXTERNAL;
         case $this->getConfig()->get(Formatter::CFG_SKIP_M2M_TABLES) && $this->isManyToMany():
             return self::WRITE_M2M;
         default:
             $this->getDocument()->addLog(sprintf('Writing table "%s"', $this->getModelName()));
             $writer->open($this->getTableFileName())->writeCallback(function (WriterInterface $writer, Table $_this = null) {
                 if ($_this->getConfig()->get(Formatter::CFG_ADD_COMMENT)) {
                     $writer->write($_this->getFormatter()->getComment(Comment::FORMAT_YAML))->write('');
                 }
             })->write($this->asYAML())->close();
             return self::WRITE_OK;
     }
 }
 public function write(WriterInterface $writer)
 {
     if ($this->isUnique()) {
         $type = "unique";
     } else {
         if ($this->isIndex()) {
             $type = "index";
         } else {
             return $this;
         }
     }
     $writer->write('<%s name="%s">', $type, $this->getName())->indent();
     foreach ($this->columns as $refColumn) {
         $writer->write('<%s-column name="%s" />', $type, $refColumn->getColumnName());
     }
     $writer->outdent()->write('</%s>', $type);
     return $this;
 }
 public function writeVendor(WriterInterface $writer)
 {
     $writer->write('<vendor type="mysql">');
     $writer->indent();
     $writer->write('<parameter name="Engine" value="%s" />', $this->parameters->get('tableEngine'));
     $writer->write('<parameter name="Charset" value="%s" />', $this->parameters->get('defaultCharacterSetName'));
     $writer->outdent();
     $writer->write('</vendor>');
     return $this;
 }
 public function writeRelations(WriterInterface $writer)
 {
     $parentTable = $this->getParent()->getParent();
     foreach ($this->foreigns as $foreign) {
         //if($foreign->getParent()->getParent()->getRawTableName() == $parentTable->getRawTableName()){
         $writer->write('<foreign-key name="%s" foreignTable="%s" phpName="%s" refPhpName="%s" onDelete="%s" onUpdate="%s">', $foreign->parameters->get('name'), $foreign->getOwningTable()->getRawTableName(), $foreign->getOwningTable()->getModelName(), $foreign->getReferencedTable()->getModelName(), strtolower($foreign->parameters->get('deleteRule')) == 'no action' ? 'none' : strtolower($foreign->parameters->get('deleteRule')), strtolower($foreign->parameters->get('updateRule')) == 'no action' ? 'none' : strtolower($foreign->parameters->get('updateRule')));
         $writer->indent();
         $writer->write('<reference local="%s" foreign="%s" />', $foreign->getLocal()->getColumnName(), $foreign->getForeign()->getColumnName());
         $writer->outdent();
         $writer->write('</foreign-key>');
         //}
     }
     return $this;
 }
 public function writeRelations(WriterInterface $writer)
 {
     foreach ($this->foreignKeys as $foreign) {
         $writer->write('<foreign-key name="%s" foreignTable="%s" phpName="%s" refPhpName="%s" onDelete="%s" onUpdate="%s">', $foreign->parameters->get('name'), $foreign->getReferencedTable()->getRawTableName(), $foreign->getReferencedTable()->getModelName(), $foreign->getOwningTable()->getModelName(), strtolower($foreign->parameters->get('deleteRule')) == 'no action' ? 'none' : strtolower($foreign->parameters->get('deleteRule')), strtolower($foreign->parameters->get('updateRule')) == 'no action' ? 'none' : strtolower($foreign->parameters->get('updateRule')));
         $writer->indent();
         $locals = $foreign->getLocals();
         $foreigns = $foreign->getForeigns();
         for ($i = 0; $i < count($locals); $i++) {
             $writer->write('<reference local="%s" foreign="%s" />', $locals[$i]->getColumnName(), $foreigns[$i]->getColumnName());
         }
         $writer->outdent();
         $writer->write('</foreign-key>');
     }
     return $this;
 }
Ejemplo n.º 26
0
 public function writeFillable(WriterInterface $writer)
 {
     /*
      * FIXME: identify which columns are FK and not add to the array fillable
      */
     $writer->write('/**')->write(' * The attributes that are mass assignable.')->write(' * ')->write(' * @var array')->write(' */')->writeCallback(function (WriterInterface $writer, Table $_this = null) {
         if (count($_this->getColumns())) {
             $content = '';
             $columns = $_this->getColumns();
             foreach ($columns as $column) {
                 $content .= '\'' . $column->getColumnName() . '\',';
             }
             $writer->write('protected $fillable = [' . substr($content, 0, -1) . '];');
         }
     });
     return $this;
 }
 public function writeSerialization(WriterInterface $writer)
 {
     $writer->write('public function __sleep()')->write('{')->indent()->write('return array(%s);', implode(', ', array_map(function ($column) {
         return sprintf('\'%s\'', $column);
     }, $this->getColumns()->getColumnNames())))->outdent()->write('}');
     return $this;
 }
 public function write(WriterInterface $writer)
 {
     $writer->write('\'' . $this->getReferencedTable()->getRawTableName() . '\' => array(')->indent()->write('\'columns\'       => \'' . $this->foreign->getColumnName() . '\',')->write('\'refTableClass\' => \'' . $this->getReferencedTable()->getRawTableName() . '\',')->write('\'refColumns\'    => \'' . $this->local->getColumnName() . '\',')->outdent()->write('),');
     return $this;
 }
Ejemplo n.º 29
0
 public function writeDown(WriterInterface $writer)
 {
     $writer->write('/**')->write(' * Reverse the migrations.')->write(' *')->write(' * @return void')->write(' */')->write('public function down()')->write('{')->indent()->write('Schema::drop(\'' . $this->getRawTableName() . '\');')->outdent()->write('}')->write('');
     return $this;
 }
 public function writeRelationsGetterAndSetter(WriterInterface $writer)
 {
     $table = $this->getTable();
     // one to many references
     foreach ($this->foreigns as $foreign) {
         if ($foreign->getForeign()->getTable()->isManyToMany()) {
             // do not create entities for many2many tables
             continue;
         }
         if ($foreign->parseComment('unidirectional') === 'true') {
             // do not output mapping in foreign table when the unidirectional option is set
             continue;
         }
         if ($foreign->isManyToOne()) {
             // is ManyToOne
             $related = $this->getRelatedName($foreign);
             $related_text = $this->getRelatedName($foreign, false);
             $writer->write('/**')->write(' * Add ' . trim($foreign->getOwningTable()->getModelName() . ' ' . $related_text) . ' entity to collection (one to many).')->write(' *')->write(' * @param ' . $foreign->getOwningTable()->getNamespace() . ' $' . lcfirst($foreign->getOwningTable()->getModelName()))->write(' * @return ' . $table->getNamespace())->write(' */')->write('public function add' . $this->columnNameBeautifier($foreign->getOwningTable()->getModelName()) . $related . '(' . $foreign->getOwningTable()->getModelName() . ' $' . lcfirst($foreign->getOwningTable()->getModelName()) . ')')->write('{')->indent()->write('$this->' . lcfirst(Inflector::pluralize($foreign->getOwningTable()->getModelName())) . $related . '[] = $' . lcfirst($foreign->getOwningTable()->getModelName()) . ';')->write('')->write('return $this;')->outdent()->write('}')->write('')->write('/**')->write(' * Get ' . trim($foreign->getOwningTable()->getModelName() . ' ' . $related_text) . ' entity collection (one to many).')->write(' *')->write(' * @return ' . $table->getCollectionInterface())->write(' */')->write('public function get' . $this->columnNameBeautifier(Inflector::pluralize($foreign->getOwningTable()->getModelName())) . $related . '()')->write('{')->indent()->write('return $this->' . lcfirst(Inflector::pluralize($foreign->getOwningTable()->getModelName())) . $related . ';')->outdent()->write('}');
         } else {
             // OneToOne
             $writer->write('/**')->write(' * Set ' . $foreign->getOwningTable()->getModelName() . ' entity (one to one).')->write(' *')->write(' * @param ' . $foreign->getOwningTable()->getNamespace() . ' $' . lcfirst($foreign->getOwningTable()->getModelName()))->write(' * @return ' . $table->getNamespace())->write(' */')->write('public function set' . $this->columnNameBeautifier($foreign->getOwningTable()->getModelName()) . '(' . $foreign->getOwningTable()->getModelName() . ' $' . lcfirst($foreign->getOwningTable()->getModelName()) . ')')->write('{')->indent()->write('$this->' . lcfirst($foreign->getOwningTable()->getModelName()) . ' = $' . lcfirst($foreign->getOwningTable()->getModelName()) . ';')->write('')->write('return $this;')->outdent()->write('}')->write('')->write('/**')->write(' * Get ' . $foreign->getOwningTable()->getModelName() . ' entity (one to one).')->write(' *')->write(' * @return ' . $foreign->getOwningTable()->getNamespace())->write(' */')->write('public function get' . $this->columnNameBeautifier($foreign->getOwningTable()->getModelName()) . '()')->write('{')->indent()->write('return $this->' . lcfirst($foreign->getOwningTable()->getModelName()) . ';')->outdent()->write('}');
         }
         $writer->write('');
     }
     // many to one references
     if (null !== $this->local) {
         $unidirectional = $this->local->parseComment('unidirectional') === 'true';
         if ($this->local->isManyToOne()) {
             // is ManyToOne
             $related = $this->getManyToManyRelatedName($this->local->getReferencedTable()->getRawTableName(), $this->local->getForeign()->getColumnName());
             $related_text = $this->getManyToManyRelatedName($this->local->getReferencedTable()->getRawTableName(), $this->local->getForeign()->getColumnName(), false);
             $writer->write('/**')->write(' * Set ' . trim($this->local->getReferencedTable()->getModelName() . ' ' . $related_text) . ' entity (many to one).')->write(' *')->write(' * @param ' . $this->local->getReferencedTable()->getNamespace() . ' $' . lcfirst($this->local->getReferencedTable()->getModelName()))->write(' * @return ' . $table->getNamespace())->write(' */')->write('public function set' . $this->columnNameBeautifier($this->local->getReferencedTable()->getModelName()) . $related . '(' . $this->local->getReferencedTable()->getModelName() . ' $' . lcfirst($this->local->getReferencedTable()->getModelName()) . ' = null)')->write('{')->indent()->write('$this->' . lcfirst($this->local->getReferencedTable()->getModelName()) . $related . ' = $' . lcfirst($this->local->getReferencedTable()->getModelName()) . ';')->write('')->write('return $this;')->outdent()->write('}')->write('')->write('/**')->write(' * Get ' . trim($this->local->getReferencedTable()->getModelName() . ' ' . $related_text) . ' entity (many to one).')->write(' *')->write(' * @return ' . $this->local->getReferencedTable()->getNamespace())->write(' */')->write('public function get' . $this->columnNameBeautifier($this->local->getReferencedTable()->getModelName()) . $related . '()')->write('{')->indent()->write('return $this->' . lcfirst($this->local->getReferencedTable()->getModelName()) . $related . ';')->outdent()->write('}')->write('');
         } else {
             // OneToOne
             $writer->write('/**')->write(' * Set ' . $this->local->getReferencedTable()->getModelName() . ' entity (one to one).')->write(' *')->write(' * @param ' . $this->local->getReferencedTable()->getNamespace() . ' $' . lcfirst($this->local->getReferencedTable()->getModelName()))->write(' * @return ' . $table->getNamespace())->write(' */')->write('public function set' . $this->columnNameBeautifier($this->local->getReferencedTable()->getModelName()) . '(' . $this->local->getReferencedTable()->getModelName() . ' $' . lcfirst($this->local->getReferencedTable()->getModelName()) . ' = null)')->write('{')->indent()->writeIf(!$unidirectional, '$' . lcfirst($this->local->getReferencedTable()->getModelName()) . '->set' . $this->columnNameBeautifier($this->local->getOwningTable()->getModelName()) . '($this);')->write('$this->' . lcfirst($this->local->getReferencedTable()->getModelName()) . ' = $' . lcfirst($this->local->getReferencedTable()->getModelName()) . ';')->write('')->write('return $this;')->outdent()->write('}')->write('')->write('/**')->write(' * Get ' . $this->local->getReferencedTable()->getModelName() . ' entity (one to one).')->write(' *')->write(' * @return ' . $this->local->getReferencedTable()->getNamespace())->write(' */')->write('public function get' . $this->columnNameBeautifier($this->local->getReferencedTable()->getModelName()) . '()')->write('{')->indent()->write('return $this->' . lcfirst($this->local->getReferencedTable()->getModelName()) . ';')->outdent()->write('}')->write('');
         }
     }
     return $this;
 }