public function display()
    {
        $return = array();
        $relation_name = (strpos($this->config['name'],'d:') === 0)?substr($this->config['name'],2):$this->referencedTable->getModelName();
        $return[] = '    ' . $relation_name . ':';
        $return[] = '      class: ' . $this->referencedTable->getModelName();

        $ownerColumn = $this->data->xpath("value[@key='columns']");
        $return[] = '      local: ' . \MwbExporter\Core\Registry::get((string) $ownerColumn[0]->link)->getColumnName();

        $referencedColumn = $this->data->xpath("value[@key='referencedColumns']");
        $return[] = '      foreign: ' . \MwbExporter\Core\Registry::get((string) $referencedColumn[0]->link)->getColumnName();

        $foreignAlias = trim($this->getForeignAlias());

        if (!empty($foreignAlias)) {
            $return[] = '      foreignAlias: ' . $foreignAlias;
        } else {
            if((int)$this->config['many'] === 1){
                $return[] = '      foreignAlias: ' . \MwbExporter\Helper\Pluralizer::pluralize($this->owningTable->getModelName());
            } else {
                $return[] = '      foreignAlias: ' . $this->owningTable->getModelName();
            }
        }

        $return[] = '      onDelete: ' . strtolower($this->config['deleteRule']);
        $return[] = '      onUpdate: ' . strtolower($this->config['updateRule']);

        return implode("\n", $return);
    }
    /**
     * Return the foreign key definition
     * Yaml format
     *
     * @return string
     */
    public function display()
    {
        $return = array();

        /**
         * sometimes the link between to tables is broken
         */
        if($this->referencedTable == null){
            return $this->indentation(2) . '# There is another foreign key declaration but it seems broken.';
        }

        $return[] = $this->indentation(2) . $this->referencedTable->getModelName() . ':';
        $return[] = $this->indentation(3) . 'class: ' . $this->referencedTable->getModelName();

        $ownerColumn = $this->data->xpath("value[@key='columns']");
        $return[] = $this->indentation(3) . 'local: ' . \MwbExporter\Core\Registry::get((string) $ownerColumn[0]->link)->getColumnName();

        $referencedColumn = $this->data->xpath("value[@key='referencedColumns']");
        $return[] = $this->indentation(3) . 'foreign: ' . \MwbExporter\Core\Registry::get((string) $referencedColumn[0]->link)->getColumnName();

        if((int)$this->config['many'] === 1){
            $return[] = $this->indentation(3) . 'foreignAlias: ' . \MwbExporter\Helper\Pluralizer::pluralize($this->owningTable->getModelName());
        } else {
            $return[] = $this->indentation(3) . 'foreignAlias: ' . $this->owningTable->getModelName();
        }

        $return[] = $this->indentation(3) . 'onDelete: ' . strtolower($this->config['deleteRule']);
        $return[] = $this->indentation(3) . 'onUpdate: ' . strtolower($this->config['updateRule']);

        return implode("\n", $return);
    }
    /**
     *
     * @return string
     */
    public function getModelName()
    {
        $tablename = $this->getRawTableName();

        // check if table name is plural --> convert to singular
        if(\MwbExporter\Helper\Pluralizer::wordIsPlural($tablename)){
            $tablename = \MwbExporter\Helper\Singularizer::singularize($tablename);
        }

        // camleCase under scores for model names
        return ucfirst(preg_replace('@\_(\w)@e', 'ucfirst("$1")', $tablename));
    }
 public static function wordIsSingular($word)
 {
     return !( \MwbExporter\Helper\Pluralizer::wordIsPlural($word) );
 }
    /**
     * Getters and setters for the entity attributes
     *
     * @return string
     */
    public function displayGetterAndSetter()
    {
        $return = array();

        // do not include getter and setter for columns that reflect references
        if(is_null($this->local)){
            $return[] = $this->indentation() . 'public function set' . $this->columnNameBeautifier($this->config['name']) . '($' . $this->config['name'] . ')';
            $return[] = $this->indentation() . '{';
            $return[] = $this->indentation(2) . '$this->' . $this->config['name'] . ' = $' . $this->config['name'] . ';';
            $return[] = $this->indentation(2) . 'return $this; // fluent interface';
            $return[] = $this->indentation() . '}';
            $return[] = '';

            $return[] = $this->indentation() . 'public function get' . $this->columnNameBeautifier($this->config['name']) . '()';
            $return[] = $this->indentation() . '{';
            $return[] = $this->indentation(2) . 'return $this->' . $this->config['name'] . ';';
            $return[] = $this->indentation() . '}';
            $return[] = '';
        }

        // one to many references
        if(is_array($this->foreigns)){
            foreach($this->foreigns as $foreign){
                $return[] = $this->indentation() . 'public function add' . $this->columnNameBeautifier($foreign->getOwningTable()->getModelName()) . '(' . $foreign->getOwningTable()->getModelName() . ' $' . lcfirst($foreign->getOwningTable()->getModelName()) . ')';
                $return[] = $this->indentation() . '{';
                $return[] = $this->indentation(2) . '$this->' . lcfirst(\MwbExporter\Helper\Pluralizer::pluralize($foreign->getOwningTable()->getModelName())) . '[] = $' . lcfirst($foreign->getOwningTable()->getModelName()) . ';';
                $return[] = $this->indentation(2) . 'return $this; // fluent interface';
                $return[] = $this->indentation() . '}';
                $return[] = '';

                $return[] = $this->indentation() . 'public function get' . $this->columnNameBeautifier(\MwbExporter\Helper\Pluralizer::pluralize($foreign->getOwningTable()->getModelName())) . '()';
                $return[] = $this->indentation() . '{';
                $return[] = $this->indentation(2) . 'return $this->' . lcfirst(\MwbExporter\Helper\Pluralizer::pluralize($foreign->getOwningTable()->getModelName())) . ';';
                $return[] = $this->indentation() . '}';
                $return[] = '';
            }
        }

        // many to one references
        if(!is_null($this->local)){
            $return[] = $this->indentation() . 'public function set' . $this->columnNameBeautifier($this->local->getReferencedTable()->getModelName()) . '(' . $this->local->getReferencedTable()->getModelName() . ' $' . lcfirst($this->local->getReferencedTable()->getModelName()) . ')';
            $return[] = $this->indentation() . '{';
            $return[] = $this->indentation(2) . '$' . lcfirst($this->local->getReferencedTable()->getModelName()) . '->add' . $this->columnNameBeautifier($this->local->getOwningTable()->getModelName()) . '($this);';
            $return[] = $this->indentation(2) . '$this->' . lcfirst($this->local->getReferencedTable()->getModelName()) . ' = $' . lcfirst($this->local->getReferencedTable()->getModelName()) . ';';
            $return[] = $this->indentation(2) . 'return $this; // fluent interface';
            $return[] = $this->indentation() . '}';
            $return[] = '';

            $return[] = $this->indentation() . 'public function get' . $this->columnNameBeautifier($this->local->getReferencedTable()->getModelName()) . '()';
            $return[] = $this->indentation() . '{';
            $return[] = $this->indentation(2) . 'return $this->' . lcfirst($this->local->getReferencedTable()->getModelName()) . ';';
            $return[] = $this->indentation() . '}';
            $return[] = '';
        }

        return implode("\n", $return);
    }
    protected function displayManyToManyGetterAndSetter()
    {
        $return = array();

        foreach($this->manyToManyRelations as $relation){
            $return[] = $this->indentation() . 'public function add' . $relation['refTable']->getModelName() . '(' . $relation['refTable']->getModelName() . ' $' . lcfirst($relation['refTable']->getModelName()) . ')';
            $return[] = $this->indentation() . '{';
            $return[] = $this->indentation(2) . '$' . lcfirst($relation['refTable']->getModelName()) . '->add' . $this->getModelName() . '($this);';
            $return[] = $this->indentation(2) . '$this->' . lcfirst(\MwbExporter\Helper\Pluralizer::pluralize($relation['refTable']->getModelName())) . '[] = $' . lcfirst($relation['refTable']->getModelName()) . ';';
            $return[] = $this->indentation(2) . 'return $this;';
            $return[] = $this->indentation() . '}';
            $return[] = '';
            $return[] = $this->indentation() . 'public function get' . \MwbExporter\Helper\Pluralizer::pluralize($relation['refTable']->getModelName()) . '()';
            $return[] = $this->indentation() . '{';
            $return[] = $this->indentation(2) . 'return $this->' . lcfirst(\MwbExporter\Helper\Pluralizer::pluralize($relation['refTable']->getModelName())) . ';';
            $return[] = $this->indentation() . '}';
        }

        return implode("\n", $return);
    }