Skip to content

Getter and setter generator not working properly (doctrine2-annotation) [with possible solution] #37

@s-yankov

Description

@s-yankov

So I have been using your exporter for a while and have experienced some problems with generating getters and setters.

Version: 3.1.3

The problem:

Without touching anything the some of the setters are the following:

    /**
     * Set Brand entity (many to one).
     */
    public function setBrand($brands)
    {
        $this->brands = $Brand;
        return $this;
    }

And the problem here is obvious.

The possible solution to this:

Open file "project_folder_name/public/vendor/mysql-workbench-schema-exporter/doctrine2-exporter/lib/Annotation/Model/Table.php", and edit the writer.

From (last method):

->write('public function set'.$nameSingular.'('.$typehints['set_arg'].'$'.$this->getNaming($foreign->getReferencedTable()->getName()).')'.$typehints['set_return'])
                    ->write('{')
                    ->indent()
                        ->write('$this->'.$this->getNaming($this->getRelatedVarName($foreign->getReferencedTable()->getName(), $related)).' = $'.$this->getNaming($foreign->getReferencedTable()->getModelName()).';')

To:

->write('public function set'.$nameSingular.'('.$typehints['set_arg'].'$'.$this->getNaming($foreign->getReferencedTable()->getName()).')'.$typehints['set_return'])
                    ->write('{')
                    ->indent()
                        ->write('$this->'.$this->getNaming($this->getRelatedVarName($foreign->getReferencedTable()->getName(), $related)).' = $'.$this->getNaming($foreign->getReferencedTable()->getName()).';')

Which fixes the setter methods like:

   /**
    * Set Brand entity (many to one).
    */
   public function setBrand($brands)
   {
       $this->brands = $brands;

       return $this;
   }

The export.json I am using to generate entities:

"export": "doctrine2-annotation",
 "zip": false,
 "dir": "...",
 "params": {
     "logToConsole": false,
     "logFile": "doc/wbexporter.log",
     "filename": "%entity%.%extension%",
     "indentation": 4,
     "useTabs": false,
     "eolDelimeter": "unix",
     "backupExistingFile": true,
     "addGeneratorInfoAsComment": false,
     "skipPluralNameChecking": false,
     "useLoggedStorage": false,
     "sortTablesAndViews": true,
     "exportOnlyTableCategorized": "",
     "enhanceManyToManyDetection": true,
     "skipManyToManyTables": true,
     "bundleNamespace": "App",
     "entityNamespace": "Entity",
     "repositoryNamespace": "",
     "useAutomaticRepository": true,
     "skipColumnWithRelation": false,
     "relatedVarNameFormat": "%name%%related%",
     "nullableAttribute": "auto",
     "generatedValueStrategy": "auto",
     "defaultCascade": false,
     "useAnnotationPrefix": "ORM\\",
     "skipGetterAndSetter": false,
     "generateEntitySerialization": true,
     "generateExtendableEntity": false,
     "quoteIdentifierStrategy": "auto",
     "extendsClass": "",
     "propertyTypehint": false,
     "extendableEntityHasDiscriminator": false
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions