原则 2:使用表架构更新实体



我在 zend 框架 2 中使用原则 2。要使用数据库表从现有实体生成方法,使用的控制台命令是:

php doctrine-module orm:generate-entities --generate-annotations="true" --generate-methods="true" module

我有两个命名空间博客和位置

我的问题是:

 1. When I run above code, only blog entities get updated. I want to know why it is behaving like this?
 2. If I want to update only a specific entity, how can i do it?

博客有两个实体:帖子和分类

类别.php

<?php
namespace BlogEntity;
use DoctrineORMMapping as ORM;
use ZendInputFilterFactory as InputFactory;
use ZendInputFilterInputFilter;
use ZendInputFilterInputFilterAwareInterface;
use ZendInputFilterInputFilterInterface;
/**
 * Category
 *
 * @ORMTable(name="Categories")
 * @ORMEntity
 */
class Category implements InputFilterAwareInterface
{
    /**
     * @var integer
     *
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="IDENTITY")
     */
    private $id;
    /**
     * @var string
     *
     * @ORMColumn(name="name", type="string", nullable=false)
     */
    private $name;
    protected $inputFilter;
    /**
    * Get Id
    *
    * @param integer
    */
    public function getId()
    {
        return $this->id;
    }
    /**
    * Set name
    *
    * @param string $name
    * @return Category
    */
    public function setName($name)
    {
        $this->name = $name;
        return $this;
    }
    /**
    * Get name
    *
    * @return string
    */
    public function getName()
    {
        return $this->name;
    }
}

后.php

namespace BlogEntity;
use DoctrineORMMapping as ORM;
/**
 * Post
 *
 * @ORMTable(name="posts")
 * @ORMEntity
 * @ORMHasLifecycleCallbacks
 */
class Post
{
    /**
     * @var integer
     *
     * @ORMColumn(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
     * @ORMId
     * @ORMGeneratedValue(strategy="IDENTITY")
     */
    private $id;
    /**
     * @var string
     *
     * @ORMColumn(name="title", type="string", precision=0, scale=0, nullable=false, unique=false)
     */
    private $title;
    /**
     * @var string
     *
     * @ORMColumn(name="content", type="text", precision=0, scale=0, nullable=false, unique=false)
     */
    private $content;
    /**
     * @var DateTime
     *
     * @ORMColumn(name="created_date", type="datetime", precision=0, scale=0, nullable=false, unique=false)
     */
    private $createdDate;
    /**
     * @var BlogEntityCategory
     *
     * @ORMManyToOne(targetEntity="BlogEntityCategory")
     * @ORMJoinColumns({
     *   @ORMJoinColumn(name="category_id", referencedColumnName="id", nullable=true)
     * })
     */
    private $category;

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Set title
     *
     * @param string $title
     * @return Post
     */
    public function setTitle($title)
    {
        $this->title = $title;
        return $this;
    }
    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }
    /**
     * Set content
     *
     * @param string $content
     * @return Post
     */
    public function setContent($content)
    {
        $this->content = $content;
        return $this;
    }
    /**
     * Get content
     *
     * @return string 
     */
    public function getContent()
    {
        return $this->content;
    }
    /**
     * Set createdDate
     *
     * @param DateTime $createdDate
     * @return Post
     */
    public function setCreatedDate($createdDate)
    {
        $this->createdDate = $createdDate;
        return $this;
    }
    /**
     * Get createdDate
     *
     * @return DateTime 
     */
    public function getCreatedDate()
    {
        return $this->createdDate;
    }
    /**
     * Set category
     *
     * @param BlogEntityCategory $category
     * @return Post
     */
    public function setCategory(BlogEntityCategory $category = null)
    {
        $this->category = $category;
        return $this;
    }
    /**
     * Get category
     *
     * @return BlogEntityCategory 
     */
    public function getCategory()
    {
        return $this->category;
    }
}

位置有国家.php

<?php
namespace CountryEntity;
use DoctrineORMMapping as ORM;
/**
 * Country
 *
 * @ORMTable(name="countries")
 * @ORMEntity
 */
class Country
{
    /**
     * @var integer
     *
     * @ORMColumn(name="id", type="integer", nullable=false)
     * @ORMId
     * @ORMGeneratedValue(strategy="IDENTITY")
     */
    private $id;
    /**
     * @var string
     *
     * @ORMColumn(name="name", type="string", length=55, nullable=false)
     */
    private $name;

}
当然,

每个人都需要在 ZF2 上有一个函数,该函数可以生成单个实体。 但是那些时候你不能仅仅通过教义或模块来做到这一点。当你试图在《交响乐》中运行教义时,这是可以接受的。我正在使用 doctrine2 和 zf2 有同样的问题。

创建了一个我调用的 PHP 脚本

Script to Create a Single Entity:
Choose Entity Name.
Generate All Entities on a Temp Folder.
Exclude All non-needed entities from folder.
Copy Single Entity to "src/$module/Entity" Folder.

是一个黑客,我必须让它根据需要工作。

使用 -

-filter 选项执行此操作。php doctrine-module orm:generate-entity --filter="Post" ...

相关内容

  • 没有找到相关文章

最新更新