public function writeGetArrayCopy(WriterInterface $writer)
    {
        $columns   = $this->getColumns();
        $relations = $this->getTableRelations();

        $writer
            ->write('/**')
            ->write(' * Return a array with all fields and data.')
            ->write(' * Default the relations will be ignored.')
            ->write(' * ')
            ->write(' * @param array $fields')
            ->write(' * @return array')
            ->write(' */')
            ->write('public function getArrayCopy(array $fields = array())')
            ->write('{')
            ->indent()
                ->write('$dataFields = array(%s);', implode(', ', array_map(function($column) {
                    return sprintf('\'%s\'', $column);
                }, $columns->getColumnNames())))
                ->write('$relationFields = array(%s);', implode(', ', array_map(function($relation) {
                    return sprintf('\'%s\'', lcfirst($relation->getReferencedTable()->getModelName()));
                }, $relations)))
                ->write('$copiedFields = array();')
                ->write('foreach ($relationFields as $relationField) {')
                ->indent()
                    ->write('$map = null;')
                    ->write('if (array_key_exists($relationField, $fields)) {')
                    ->indent()
                        ->write('$map = $fields[$relationField];')
                        ->write('$fields[] = $relationField;')
                        ->write('unset($fields[$relationField]);')
                    ->outdent()
                    ->write('}')
                    ->write('if (!in_array($relationField, $fields)) {')
                    ->indent()
                        ->write('continue;')
                    ->outdent()
                    ->write('}')
                    ->write('$getter = sprintf(\'get%s\', ucfirst(str_replace(\' \', \'\', ucwords(str_replace(\'_\', \' \', $relationField)))));')
                    ->write('$relationEntity = $this->{$getter}();')
                    ->write('$copiedFields[$relationField] = (!is_null($map))')
                    ->indent()
                        ->write('? $relationEntity->getArrayCopy($map)')
                        ->write(': $relationEntity->getArrayCopy();')
                    ->outdent()
                    ->write('$fields = array_diff($fields, array($relationField));')
                ->outdent()
                ->write('}')
                ->write('foreach ($dataFields as $dataField) {')
                ->indent()
                    ->write('if (!in_array($dataField, $fields) && !empty($fields)) {')
                    ->indent()
                        ->write('continue;')
                    ->outdent()
                    ->write('}')
                    ->write('$getter = sprintf(\'get%s\', ucfirst(str_replace(\' \', \'\', ucwords(str_replace(\'_\', \' \', $dataField)))));')
                    ->write('$copiedFields[$dataField] = $this->{$getter}();')
                ->outdent()
                ->write('}')
                ->write('')
                ->write('return $copiedFields;')
            ->outdent()
            ->write('}')
            ->write('')
        ;

        return $this;
    }