教义2.0案例错误 [英] doctrine 2.0 cascase error

查看:38
本文介绍了教义2.0案例错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学说中出现以下错误...

I am getting following error in doctrine...

通过未配置为级联持久性操作的关系找到了一个新实体:Default_Model_EventImages @ 000000004b59e58d000000003ff05ded。明确持久化新实体,或在关系上配置级联持久化操作。

A new entity was found through a relationship that was not configured to cascade persist operations: Default_Model_EventImages@000000004b59e58d000000003ff05ded. Explicitly persist the new entity or configure cascading persist operations on the relationship.

事件模型

<?php
/**
 * @Entity
 * @Table(name="events")
 */
class Default_Model_Event
{
     /**
     * @Id @Column(name="id", type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;


    /** 
    * @Column(name="title", type="string") 
    */
    private $title;

    /** 
    * @Column(name="date_from", type="string") 
    */
    private $date_from;

    /** 
    * @Column(name="date_to", type="string") 
    */
    private $date_to;

    /** 
    * @Column(name="venue", type="string") 
    */
    private $venue;

    /** 
    * @Column(name="address", type="string") 
    */
    private $address;

    /** 
    * @Column(name="city", type="string") 
    */
    private $city;

    /** 
    * @Column(name="state", type="string") 
    */
    private $state;

    /** 
    * @Column(name="zip", type="string") 
    */
    private $zip;

    /** 
    * @Column(name="country", type="string") 
    */
    private $country;

    /** 
    * @Column(name="company_logo", type="string") 
    */
    private $company_logo;

    /** 
    * @Column(name="website", type="string") 
    */
    private $website;

    /** 
    * @Column(name="email", type="string") 
    */
    private $email;

    /** 
    * @Column(name="phone_number", type="string") 
    */
    private $phone_number;  

    /**
    * @Column(name="short_description", type="text") 
    */
    private $short_description;

     /**
    * @Column(name="long_description", type="text") 
    */
    private $long_description;

    /** 
    * @Column(name="status", type="string") 
    */
    private $status;

    /** 
    * @Column(name="date_created", type="string") 
    */
    private $date_created;

    /** 
    * @Column(name="date_modified", type="string") 
    */
    private $date_modified;

    /**
     * @ManyToOne(targetEntity="Default_Model_User", inversedBy="user_mapper")
     * @JoinColumn(name="user_id", referencedColumnName="id")
     */
    private $event_mapper;

    /**
     * @OneToMany(targetEntity="Default_Model_EventImages", mappedBy="eventimage_mapper",cascade={"All"}) 
     */
    private $images_mapper;


    public function setUser($event_mapper)
    {
      if (!is_null($event_mapper )) {
         $event_mapper->assignedToEvent($this);
         $this->event_mapper = $event_mapper;
      }
    }

    public function setEventimage_mapper($name, $order) {
        $this->images_mapper[$name] = new Default_Model_EventImages($name, $order, $this);
    }

    /**
     * @return the $id
     */
    public function getId() {
        return $this->id;
    }


    /**
     * @return the $title
     */
    public function getTitle() {
        return $this->title;
    }

    /**
     * @return the $date_from
     */
    public function getDate_from() {
        return $this->date_from;
    }

    /**
     * @return the $date_to
     */
    public function getDate_to() {
        return $this->date_to;
    }

    /**
     * @return the $venue
     */
    public function getVenue() {
        return $this->venue;
    }

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

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

    /**
     * @return the $state
     */
    public function getState() {
        return $this->state;
    }

    /**
     * @return the $zip
     */
    public function getZip() {
        return $this->zip;
    }

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

    /**
     * @return the $company_logo
     */
    public function getCompany_logo() {
        return $this->company_logo;
    }

    /**
     * @return the $website
     */
    public function getWebsite() {
        return $this->website;
    }

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

    /**
     * @return the $phone_number
     */
    public function getPhone_number() {
        return $this->phone_number;
    }

    /**
     * @return the $short_description
     */
    public function getShort_description() {
        return $this->short_description;
    }

    /**
     * @return the $long_description
     */
    public function getLong_description() {
        return $this->long_description;
    }

    /**
     * @return the $status
     */
    public function getStatus() {
        return $this->status;
    }

    /**
     * @return the $date_created
     */
    public function getDate_created() {
        return $this->date_created;
    }

    /**
     * @return the $date_modified
     */
    public function getDate_modified() {
        return $this->date_modified;
    }

    /**
     * @param field_type $id
     */
    public function setId($id) {
        $this->id = $id;
    }

    /**
     * @param field_type $title
     */
    public function setTitle($title) {
        $this->title = $title;
    }


    /**
     * @param field_type $date_from
     */
    public function setDate_from($date_from) {
        $this->date_from = $date_from;
    }

    /**
     * @param field_type $date_to
     */
    public function setDate_to($date_to) {
        $this->date_to = $date_to;
    }

    /**
     * @param field_type $venue
     */
    public function setVenue($venue) {
        $this->venue = $venue;
    }

    /**
     * @param field_type $address
     */
    public function setAddress($address) {
        $this->address = $address;
    }

    /**
     * @param field_type $city
     */
    public function setCity($city) {
        $this->city = $city;
    }

    /**
     * @param field_type $state
     */
    public function setState($state) {
        $this->state = $state;
    }

    /**
     * @param field_type $zip
     */
    public function setZip($zip) {
        $this->zip = $zip;
    }

    /**
     * @param field_type $country
     */
    public function setCountry($country) {
        $this->country = $country;
    }

    /**
     * @param field_type $company_logo
     */
    public function setCompany_logo($company_logo) {
        $this->company_logo = $company_logo;
    }

    /**
     * @param field_type $website
     */
    public function setWebsite($website) {
        $this->website = $website;
    }

    /**
     * @param field_type $email
     */
    public function setEmail($email) {
        $this->email = $email;
    }

    /**
     * @param field_type $phone_number
     */
    public function setPhone_number($phone_number) {
        $this->phone_number = $phone_number;
    }

    /**
     * @param field_type $short_description
     */
    public function setShort_description($short_description) {
        $this->short_description = $short_description;
    }

    /**
     * @param field_type $long_description
     */
    public function setLong_description($long_description) {
        $this->long_description = $long_description;
    }

    /**
     * @param field_type $status
     */
    public function setStatus($status) {
        $this->status = $status;
    }

    /**
     * @param field_type $date_created
     */
    public function setDate_created($date_created) {
        $this->date_created = $date_created;
    }

    /**
     * @param field_type $date_modified
     */
    public function setDate_modified($date_modified) {
        $this->date_modified = $date_modified;
    }


}//end class

事件图像模型

<?php
/**
 * @Entity
 * @Table(name="event_images")
 */
class Default_Model_EventImages
{
     /**
     * @Id @Column(name="id", type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /** 
    * @Column(name="name", type="string") 
    */
    private $name;

    /** 
    * @Column(name="order", type="integer") 
    */
    private $order;

    /** 
    * @Column(name="status", type="string") 
    */
    private $status;

    /** 
    * @Column(name="date_created", type="string") 
    */
    private $date_created;

    /** 
    * @Column(name="date_modified", type="string") 
    */
    private $date_modified;

    /**
     * @ManyToOne(targetEntity="Default_Model_Event", inversedBy="images_mapper", cascade={"All"})
     * @JoinColumn(name="event_id", referencedColumnName="id")
     */
    private $eventimage_mapper;


    public function __construct($name, $order, $event) {
        $this->name = $name;
        $this->order = $order;
        $this->eventimage_mapper = $event;
        $this->date_created = new DateTime();
        $this->status = 'active';
    }

    /**
     * @return the $id
     */
    public function getId() {
        return $this->id;
    }

    /**
     * @return the $status
     */
    public function getStatus() {
        return $this->status;
    }

    /**
     * @return the $date_created
     */
    public function getDate_created() {
        return $this->date_created;
    }

    /**
     * @return the $date_modified
     */
    public function getDate_modified() {
        return $this->date_modified;
    }

    /**
     * @param field_type $id
     */
    public function setId($id) {
        $this->id = $id;
    }

    /**
     * @param field_type $status
     */
    public function setStatus($status) {
        $this->status = $status;
    }

    /**
     * @param field_type $date_created
     */
    public function setDate_created($date_created) {
        $this->date_created = $date_created;
    }

    /**
     * @param field_type $date_modified
     */
    public function setDate_modified($date_modified) {
        $this->date_modified = $date_modified;
    }


}//end class

控制器

$user_id = '2'; //(int)$formData['category_id'];
                $user_mapper = $this->_em->find("Default_Model_User", (int)$user_id);
                $event = new Default_Model_Event(); 
                $event->setUser($user_mapper);

                $event->setTitle($title);
                $event->setDate_from($date_from);
                $event->setDate_to($date_to);
                $event->setVenue($venue);
                $event->setAddress($address);
                $event->setCity($city);
                $event->setState($state);
                $event->setZip($zip);
                $event->setCountry($country);
                $event->setCompany_logo($company_logo);
                $event->setWebsite($website);
                $event->setEmail($email);
                $event->setPhone_number($phone);
                $event->setStatus('pending');
                $event->setShort_description($short_description);
                $event->setLong_description($long_description);
                $date = new Zend_Date;
                $event->setDate_created($date->toString('YYYY-MM-dd HH:mm:ss'));

                foreach($images as $key => $value) {
                    $event->setEventimage_mapper($value, $key);
                    //$this->_em->persist($eventImages);
                }

                $this->_em->persist($event);
                $this->_em->flush();


推荐答案

实际上问题是我必须坚持所有活动图像对象单独。.

Actually the problem was i had to persist all the event images object individually..

foreach($images as $key => $value) {
    $eventImages = $event->setEventimage_mapper($value, $key);
    $this->_em->persist($eventImages);

}

,并且在事件模型中

public function setEventimage_mapper($name, $order) {
        return $this->images_mapper[$name] = new Default_Model_EventImages($name, $order, $this);
    }

这篇关于教义2.0案例错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆