nciri / zend-db-model-generator

Automatically exported from code.google.com/p/zend-db-model-generator
0 stars 0 forks source link

Foreign Keys: duplicated properties #14

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
* What steps will reproduce the problem?
1. generate models
2. get php errors

* What is the expected output? What do you see instead?
No duplicated class properties, getters, setters when dealing with foreign keys

* What version of the product are you using? On what operating system?
v0.6

* Please provide any additional information below.
-- Example: I have two tables
1. users
2. language
The user table has a column "language" that has a foreign key constraint 
referencing the column "id" of the "language" table

-- create table statements
CREATE TABLE IF NOT EXISTS `user` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `salutation` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
  `firstname` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
  `lastname` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
  `confirmed` tinyint(1) NOT NULL DEFAULT '0',
  `blocked` tinyint(1) NOT NULL DEFAULT '0',
  `language` bigint(20) unsigned NOT NULL DEFAULT '1',
  `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `last_login` timestamp NULL DEFAULT NULL,
  `last_login_ip` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
  `password` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'sha256 hash',
  PRIMARY KEY (`id`),
  KEY `fk_user_language` (`language`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Main 
User Table';

CREATE TABLE IF NOT EXISTS `language` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `iso639_1` varchar(2) COLLATE utf8_bin NOT NULL,
  `Name` varchar(128) COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `iso639-1_UNIQUE` (`iso639_1`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

-- problematic code snippeds in the generated model class for table "User" 
(full class file attached)
[snip]
/**
     * Database var type bigint(20) unsigned
     *
     * @var int
     */
    protected $_Language;

    /**
     * Parent relation fk_user_language
     *
     * @var Core_Model_Language
     */
    protected $_Language;
[snip]
/**
     * Sets column language
     *
     * @param int $data
     * @return Core_Model_User
     */
    public function setLanguage($data)
    {
        $this->_Language = $data;
        return $this;
    }

    /**
     * Gets column language
     *
     * @return int
     */
    public function getLanguage()
    {
        return $this->_Language;
    }

    /**
     * Sets parent relation Language
     *
     * @param Core_Model_Language $data
     * @return Core_Model_User
     */
    public function setLanguage(Core_Model_Language $data)
    {
        $this->_Language = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['id'];
        }

        $this->setLanguage($primary_key);

        return $this;
    }

    /**
     * Gets parent Language
     *
     * @param boolean $load Load the object if it is not already
     * @return Core_Model_Language
     */
    public function getLanguage($load = true)
    {
        if ($this->_Language === null && $load) {
            $this->getMapper()->loadRelated('FkUserLanguage', $this);
        }

        return $this->_Language;
    }
[snip]

Original issue reported on code.google.com by andr...@stangl.rocks on 25 Sep 2011 at 2:31

Attachments:

GoogleCodeExporter commented 8 years ago
I tested using latest SVN version and the problem does not occur. created the 
tables as listed and used the zdmg to create the User class, it creates it 
properly with no duplicate properties. please check with latest SVN if the 
problem occurs and if it still does please provide mysql server version and php 
version. I tested it on PHP 5.3.10 and on MYSQL Server 5.1.61 on Mac OS Lion 
10.7.3.

Original comment by kfirufk@gmail.com on 7 Feb 2012 at 9:09

GoogleCodeExporter commented 8 years ago
Hi,
same issue for me whith zdmg-0.7rc1. (PHP Version 5.3.2 et mysql 
5.1.37-community)
the model /Expertaffiliation.php have duplicate properties and method get and 
set..

Original comment by led...@gmail.com on 30 Jul 2012 at 4:55

Attachments:

GoogleCodeExporter commented 8 years ago
I try to update on my windows (Vista): 
php (php-5.4.5-Win32-VC9-x86) and mysql (mysql-5.5.25a-win32)

and on other computer : (Linux solid 2.6.31-23-generic #75-Ubuntu)
php ( 5.2.10.dfsg.1-2ubuntu6.10) and mysql (5.1.37-1ubuntu5.5)

---------------------------
 /**
     * Sets column grade
     *
     * @param int $data
     * @return datatest_Model_Expertaffiliation
     */
    public function setGrade($data)
    {
        $this->_Grade = $data;
        return $this;
    }
-----------[..]-------------
/**
     * Sets parent relation Grade
     *
     * @param datatest_Model_Grade $data
     * @return datatest_Model_Expertaffiliation
     */
    public function setGrade(datatest_Model_Grade $data)
    {
        $this->_Grade = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idGrade'];
        }

        $this->setGrade($primary_key);

        return $this;
    }
--------------------------

Original comment by led...@gmail.com on 31 Jul 2012 at 9:20

GoogleCodeExporter commented 8 years ago
found issue :
The foreign key and table must not have same name...

:)

Original comment by led...@gmail.com on 31 Jul 2012 at 12:59