2013-11-03 3 views
0

Сначала я создал базу данных, а затем сгенерировал ее сущности. После этого я создал методы получение и установки в лицах с помощью:Создание геттеров и сеттеров Symfony2

php app/console doctrine:generate:entities DigitalManager 

Позже я решил создать ассоциацию (один ко многим) между субъектами, так что я добавил соответствующие команды в моем Entities и то, что я получил это:

партии Entity:

<?php 

namespace DigitalManager\Bundle\ERPBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* Party 
* 
* @ORM\Table(name="party") 
* @ORM\Entity 
*/ 
class Party 
{ 
/** 
* @var string 
* 
* @ORM\Column(name="name", type="string", length=45, nullable=true) 
*/ 
private $name; 

/** 
* @ORM\ManyToOne(targetEntity="Account", inversedBy="parties") 
* @ORM\JoinColumn(name="account_id", referencedColumnName="aid") 
*/ 
public $account; 

/** 
* @var string 
* 
* @ORM\Column(name="address", type="string", length=45, nullable=true) 
*/ 
private $address; 

/** 
* @var string 
* 
* @ORM\Column(name="phone_fax", type="string", length=45, nullable=true) 
*/ 
private $phoneFax; 

/** 
* @var string 
* 
* @ORM\Column(name="fax", type="string", length=45, nullable=true) 
*/ 
private $fax; 

/** 
* @var string 
* 
* @ORM\Column(name="email", type="string", length=45, nullable=true) 
*/ 
private $email; 

/** 
* @var string 
* 
* @ORM\Column(name="mobile", type="string", length=45, nullable=true) 
*/ 
private $mobile; 

/** 
* @var string 
* 
* @ORM\Column(name="country", type="string", length=45, nullable=true) 
*/ 
private $country; 

/** 
* @var string 
* 
* @ORM\Column(name="city", type="string", length=45, nullable=true) 
*/ 
private $city; 

/** 
* @var string 
* 
* @ORM\Column(name="phone_res", type="string", length=45, nullable=true) 
*/ 
private $phoneRes; 

/** 
* @var string 
* 
* @ORM\Column(name="remarks", type="string", length=45, nullable=true) 
*/ 
private $remarks; 

/** 
* @var boolean 
* 
* @ORM\Column(name="active", type="boolean", nullable=true) 
*/ 
private $active; 

/** 
* @var integer 
* 
* @ORM\Column(name="limit", type="integer", nullable=true) 
*/ 
private $limit; 

/** 
* @var integer 
* 
* @ORM\Column(name="term", type="integer", nullable=true) 
*/ 
private $term; 

/** 
* @var string 
* 
* @ORM\Column(name="officer_id", type="string", length=45, nullable=true) 
*/ 
private $officerId; 

/** 
* @var \DateTime 
* 
* @ORM\Column(name="date", type="datetime", nullable=true) 
*/ 
private $date; 

/** 
* @var string 
* 
* @ORM\Column(name="cnic", type="string", length=45, nullable=true) 
*/ 
private $cnic; 

/** 
* @var string 
* 
* @ORM\Column(name="ntn", type="string", length=45, nullable=true) 
*/ 
private $ntn; 

/** 
* @var boolean 
* 
* @ORM\Column(name="L_O", type="boolean", nullable=true) 
*/ 
private $lO; 

/** 
* @var string 
* 
* @ORM\Column(name="type", type="string", length=45, nullable=true) 
*/ 
private $type; 

/** 
* @var integer 
* 
* @ORM\Column(name="acc_id", type="integer", nullable=true) 
*/ 
private $accId; 

/** 
* @var integer 
* 
* @ORM\Column(name="party_id", type="integer") 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="IDENTITY") 
*/ 
private $partyId; 



/** 
* Set name 
* 
* @param string $name 
* @return Party 
*/ 
public function setName($name) 
{ 
    $this->name = $name; 

    return $this; 
} 

/** 
* Get name 
* 
* @return string 
*/ 
public function getName() 
{ 
    return $this->name; 
} 

/** 
* Set address 
* 
* @param string $address 
* @return Party 
*/ 
public function setAddress($address) 
{ 
    $this->address = $address; 

    return $this; 
} 

/** 
* Get address 
* 
* @return string 
*/ 
public function getAddress() 
{ 
    return $this->address; 
} 

/** 
* Set phoneFax 
* 
* @param string $phoneFax 
* @return Party 
*/ 
public function setPhoneFax($phoneFax) 
{ 
    $this->phoneFax = $phoneFax; 

    return $this; 
} 

/** 
* Get phoneFax 
* 
* @return string 
*/ 
public function getPhoneFax() 
{ 
    return $this->phoneFax; 
} 

/** 
* Set fax 
* 
* @param string $fax 
* @return Party 
*/ 
public function setFax($fax) 
{ 
    $this->fax = $fax; 

    return $this; 
} 

/** 
* Get fax 
* 
* @return string 
*/ 
public function getFax() 
{ 
    return $this->fax; 
} 

/** 
* Set email 
* 
* @param string $email 
* @return Party 
*/ 
public function setEmail($email) 
{ 
    $this->email = $email; 

    return $this; 
} 

/** 
* Get email 
* 
* @return string 
*/ 
public function getEmail() 
{ 
    return $this->email; 
} 

/** 
* Set mobile 
* 
* @param string $mobile 
* @return Party 
*/ 
public function setMobile($mobile) 
{ 
    $this->mobile = $mobile; 

    return $this; 
} 

/** 
* Get mobile 
* 
* @return string 
*/ 
public function getMobile() 
{ 
    return $this->mobile; 
} 

/** 
* Set country 
* 
* @param string $country 
* @return Party 
*/ 
public function setCountry($country) 
{ 
    $this->country = $country; 

    return $this; 
} 

/** 
* Get country 
* 
* @return string 
*/ 
public function getCountry() 
{ 
    return $this->country; 
} 

/** 
* Set city 
* 
* @param string $city 
* @return Party 
*/ 
public function setCity($city) 
{ 
    $this->city = $city; 

    return $this; 
} 

/** 
* Get city 
* 
* @return string 
*/ 
public function getCity() 
{ 
    return $this->city; 
} 

/** 
* Set phoneRes 
* 
* @param string $phoneRes 
* @return Party 
*/ 
public function setPhoneRes($phoneRes) 
{ 
    $this->phoneRes = $phoneRes; 

    return $this; 
} 

/** 
* Get phoneRes 
* 
* @return string 
*/ 
public function getPhoneRes() 
{ 
    return $this->phoneRes; 
} 

/** 
* Set remarks 
* 
* @param string $remarks 
* @return Party 
*/ 
public function setRemarks($remarks) 
{ 
    $this->remarks = $remarks; 

    return $this; 
} 

/** 
* Get remarks 
* 
* @return string 
*/ 
public function getRemarks() 
{ 
    return $this->remarks; 
} 

/** 
* Set active 
* 
* @param boolean $active 
* @return Party 
*/ 
public function setActive($active) 
{ 
    $this->active = $active; 

    return $this; 
} 

/** 
* Get active 
* 
* @return boolean 
*/ 
public function getActive() 
{ 
    return $this->active; 
} 

/** 
* Set limit 
* 
* @param integer $limit 
* @return Party 
*/ 
public function setLimit($limit) 
{ 
    $this->limit = $limit; 

    return $this; 
} 

/** 
* Get limit 
* 
* @return integer 
*/ 
public function getLimit() 
{ 
    return $this->limit; 
} 

/** 
* Set term 
* 
* @param integer $term 
* @return Party 
*/ 
public function setTerm($term) 
{ 
    $this->term = $term; 

    return $this; 
} 

/** 
* Get term 
* 
* @return integer 
*/ 
public function getTerm() 
{ 
    return $this->term; 
} 

/** 
* Set officerId 
* 
* @param string $officerId 
* @return Party 
*/ 
public function setOfficerId($officerId) 
{ 
    $this->officerId = $officerId; 

    return $this; 
} 

/** 
* Get officerId 
* 
* @return string 
*/ 
public function getOfficerId() 
{ 
    return $this->officerId; 
} 

/** 
* Set date 
* 
* @param \DateTime $date 
* @return Party 
*/ 
public function setDate($date) 
{ 
    $this->date = $date; 

    return $this; 
} 

/** 
* Get date 
* 
* @return \DateTime 
*/ 
public function getDate() 
{ 
    return $this->date; 
} 

/** 
* Set cnic 
* 
* @param string $cnic 
* @return Party 
*/ 
public function setCnic($cnic) 
{ 
    $this->cnic = $cnic; 

    return $this; 
} 

/** 
* Get cnic 
* 
* @return string 
*/ 
public function getCnic() 
{ 
    return $this->cnic; 
} 

/** 
* Set ntn 
* 
* @param string $ntn 
* @return Party 
*/ 
public function setNtn($ntn) 
{ 
    $this->ntn = $ntn; 

    return $this; 
} 

/** 
* Get ntn 
* 
* @return string 
*/ 
public function getNtn() 
{ 
    return $this->ntn; 
} 

/** 
* Set lO 
* 
* @param boolean $lO 
* @return Party 
*/ 
public function setLO($lO) 
{ 
    $this->lO = $lO; 

    return $this; 
} 

/** 
* Get lO 
* 
* @return boolean 
*/ 
public function getLO() 
{ 
    return $this->lO; 
} 

/** 
* Set type 
* 
* @param string $type 
* @return Party 
*/ 
public function setType($type) 
{ 
    $this->type = $type; 

    return $this; 
} 

/** 
* Get type 
* 
* @return string 
*/ 
public function getType() 
{ 
    return $this->type; 
} 

/** 
* Set accId 
* 
* @param integer $accId 
* @return Party 
*/ 
public function setAccId($accId) 
{ 
    $this->accId = $accId; 

    return $this; 
} 

/** 
* Get accId 
* 
* @return integer 
*/ 
public function getAccId() 
{ 
    return $this->accId; 
} 

/** 
* Get partyId 
* 
* @return integer 
*/ 
public function getPartyId() 
{ 
    return $this->partyId; 
} 
} 

Entity Счет

<?php 

namespace DigitalManager\Bundle\ERPBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Doctrine\Common\Collections\ArrayCollection; 

/** 
* Account 
* 
* @ORM\Table(name="account") 
* @ORM\Entity 
*/ 
class Account 
{ 

    public function __construct() 
    { 
     parent::__construct(); 

     // The line below must be here as a single category is to be mapped to many products, so an ArrayCollection is required instead of Array. 
     $this->parties = new ArrayCollection(); 
    } 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="name", type="string", length=45, nullable=true) 
    */ 
    private $name; 

    // The metadata above the $products property of the Category object is less important, and simply tells 
    // Doctrine to look at the Product.category property to figure out how the relationship is mapped. 

    /** 
    * @ORM\OneToMany(targetEntity="Party", mappedBy="account") 
    */ 
    protected $parties; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="address", type="string", length=200, nullable=true) 
    */ 
    private $address; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="level1", type="string", length=45, nullable=true) 
    */ 
    private $level1; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="level2", type="string", length=45, nullable=true) 
    */ 
    private $level2; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="level3", type="string", length=45, nullable=true) 
    */ 
    private $level3; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="contact", type="string", length=45, nullable=true) 
    */ 
    private $contact; 

    /** 
    * @var integer 
    * 
    * @ORM\Column(name="aid", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="IDENTITY") 
    */ 
    private $aid; 



    /** 
    * Set name 
    * 
    * @param string $name 
    * @return Account 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

    /** 
    * Get name 
    * 
    * @return string 
    */ 
    public function getName() 
    { 
     return $this->name; 
    } 

    /** 
    * Set address 
    * 
    * @param string $address 
    * @return Account 
    */ 
    public function setAddress($address) 
    { 
     $this->address = $address; 

     return $this; 
    } 

    /** 
    * Get address 
    * 
    * @return string 
    */ 
    public function getAddress() 
    { 
     return $this->address; 
    } 

    /** 
    * Set level1 
    * 
    * @param string $level1 
    * @return Account 
    */ 
    public function setLevel1($level1) 
    { 
     $this->level1 = $level1; 

     return $this; 
    } 

    /** 
    * Get level1 
    * 
    * @return string 
    */ 
    public function getLevel1() 
    { 
     return $this->level1; 
    } 

    /** 
    * Set level2 
    * 
    * @param string $level2 
    * @return Account 
    */ 
    public function setLevel2($level2) 
    { 
     $this->level2 = $level2; 

     return $this; 
    } 

    /** 
    * Get level2 
    * 
    * @return string 
    */ 
    public function getLevel2() 
    { 
     return $this->level2; 
    } 

    /** 
    * Set level3 
    * 
    * @param string $level3 
    * @return Account 
    */ 
    public function setLevel3($level3) 
    { 
     $this->level3 = $level3; 

     return $this; 
    } 

    /** 
    * Get level3 
    * 
    * @return string 
    */ 
    public function getLevel3() 
    { 
     return $this->level3; 
    } 

    /** 
    * Set contact 
    * 
    * @param string $contact 
    * @return Account 
    */ 
    public function setContact($contact) 
    { 
     $this->contact = $contact; 

     return $this; 
    } 

    /** 
    * Get contact 
    * 
    * @return string 
    */ 
    public function getContact() 
    { 
     return $this->contact; 
    } 

    /** 
    * Get aid 
    * 
    * @return integer 
    */ 
    public function getAid() 
    { 
     return $this->aid; 
    } 
} 

После добавления этих команд ассоциации, я пытался генерировать методы получения и установки для их использования:

PHP приложение/консольных доктрин: генерировать: объекты DigitalManager

Но это не похоже, генерируют геттеры и сеттеры для этих связанных атрибутов. Я просмотрел синтаксис с помощью документации Symfony2, и это было то же самое для создания ассоциаций. Может кто-нибудь, пожалуйста, скажите мне, что здесь не так, почему он не генерирует геттеры и сеттеры, хотя атрибуты есть?

+0

Является ли команда ** php app/console doctrine: schema: update --force ** обновляет вашу базу данных с помощью отношений ManyToOne? Я не вижу ошибок в вашем коде –

+0

Я пробовал, но он говорит, что база данных уже синхронизирована. –

+0

Почему свойство $ account в вашем партийном классе общедоступно? Может ли это быть проблема? – sebbo

ответ

0

Существует два процесса создания сущности и создания базы данных и т. Д. Процесс.

Я думаю, что вы можете сделать это путь

1. create a entity using command 
php app/console doctrine:generate:entity 
you provide shortcut name Like AcmeHelloBundle. After that it will ask you all the filed name of a table. step by step you create the table. 

2. If you not create your database then set database configuration file and run this command 
    php app/console doctrine:database:create 

3. After create the database you need to create the table depending on your entity that create in list 2 and run the folloing command like 
php app/console doctrine:schema:update --force 



4.Now you can create association with other entity. I just show here create entity but you need to create all entity that need for your project. After perfect association you need to run this command 
     php app/console doctrine:generate:entities DigitalManager 

5. Finnaly you need to perform this command again 
php app/console doctrine:schema:update --force 

Это может работать нормально.

1

Возможно, он пытается прочитать информацию из другого места. Есть ли файл XML для конфигурации этого объекта в Bundle/Resources/config/doctrine /?

+0

Ничего себе. Это решило мою проблему. Я использую аннотацию, но она, по-видимому, читает из файлов XML и игнорирует ассоциацию, которую я добавил в аннотации. Спасибо за это! – mcriecken

Смежные вопросы