Doctrine Orm - 多个OneToMany连接到同一个表

时间:2015-05-21 13:50:30

标签: doctrine-orm zend-framework2 one-to-many many-to-one

我正在努力解决以下问题。我正在编写一个基本的用户/订单关系,其中许多用户扮演不同的角色。因此,每个订单都链接到作为订单发起者的用户,快递员(将要接收订单的用户),收件人,即将接收订单的用户。

它表明Order表与User表有许多关系。每个订单每个组都有一个用户,而每个用户可能与各个订单有多个关系。

不幸的是,我一直收到这个错误,我不知道如何解决它:

  

执行'SELECT t0.id AS id1,t0.size AS时发生异常   size2,t0.total AS total3,t0.initial_offer AS initial_offer4,   t0.user_order_owner AS user_order_owner5,t0.user_order_to AS   user_order_to6,t0.user_order_from AS user_order_from7,   t0.user_order_courier AS user_order_courier8,t0.event_collection_id   AS event_collection_id9,t0.event_delivery_id AS event_delivery_id10,   t0.currency_id AS currency_id11,t0.capacity_limitation_id AS   capacity_limitation_id12,t0.negotiation_id AS negotiation_id13,   t0.address_from_id AS address_from_id14,t0.address_to_id AS   address_to_id15 FROM order t0 WHERE t0.user_order_courier =?'同   params [1]:

OR:

  

SQLSTATE [42000]:语法错误或访问冲突:1064您有   SQL语法错误;查看与您的手册相对应的手册   MySQL服务器版本用于在'order t0 WHERE附近使用正确的语法   第1行的t0.user_order_courier ='1'

系统中的每个订单都有一个用户:

  1. 信使
  2. 收件人
  3. 汇款人
  4. 我使用orderCourier连接进行错误测试,连接如下:

    订单实体::

     /**
         * @ORM\ManyToOne(targetEntity="RoleBasedUser\Entity\User", inversedBy="orderCourier")
         * @ORM\JoinColumn(name="user_order_courier", referencedColumnName="id")
         */
        private $userCourier;
    

    用户实体

    /**
     * @ORM\OneToMany(targetEntity="Negotiation\Entity\Order", mappedBy="userCourier")
     */
    private $orderCourier;
    

    完整实体如下:

    我的用户实体:

    <?php
    namespace RoleBasedUser\Entity;
    use Doctrine\ORM\Mapping AS ORM;
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\Common\Collections\Collection;
    use Gedmo\Mapping\Annotation as Gedmo;
    use Rbac\Role\RoleInterface;
    use ZfcRbac\Identity\IdentityInterface;
    
    /**
     * Class User
     * @package RoleBasedUser\Entity
     *
     * @ORM\Entity(repositoryClass="UserRepository")
     * @ORM\Table(name="rbu_users")
     */
    class User implements IdentityInterface
    {
        /**
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         * @ORM\Column(name="id", type="integer", nullable=false)
         *
         * @var int
         * @access protected
         */
        private $id;
    
        /**
    
    
    * @ORM\Column(type="string", length=32, nullable=false, name="uuid")
         *
         * @var string
         * @access private
         */
        private $uuid;
    
        /**
         * @ORM\Column(type="string", unique=true, length=255, nullable=true, name="email")
         *
         * @var string
         * @access private
         */
        private $email;
    
        /**
         * @ORM\Column(type="smallint", nullable=true, name="state")
         *
         * @var integer
         * @access private
         */
        private $state;
    
        /**
         * @ORM\OneToMany(targetEntity="RoleBasedUser\Entity\LocationHistory", mappedBy="user")
         */
        private $location;
    /**
     * @ORM\Column(nullable=true)
     */
    private $parent;
    
    /**
     * @ORM\Column(nullable=true)
     */
    private $firstName;
    
    /**
     * @ORM\Column(nullable=true)
     */
    private $lastName;
    
    /**
     * @ORM\Column(nullable=true)
     */
    private $password;
    
    //    /**
    //     * @ORM\OneToMany(targetEntity="Negotiation\Entity\Order", mappedBy="userOwner")
    //     */
    //    private $orderOwner;
    //
    //    /**                      `
    //     * @ORM\OneToMany(targetEntity="Negotiation\Entity\Order", mappedBy="userTo")
    //     */
    //    private $orderTo;
    //
    //    /**
    //     * @ORM\OneToMany(targetEntity="Negotiation\Entity\Order", mappedBy="userFrom")
    //     */
    //    private $orderFrom;
    //
        /**
         * @ORM\OneToMany(targetEntity="Negotiation\Entity\Order", mappedBy="userCourier")
         */
        private $orderCourier;
    
        /**
         * @ORM\OneToMany(targetEntity="RoleBasedUser\Entity\Feedback", mappedBy="client")
         */
        private $clientFeedback;
    
        /**
         * @ORM\OneToMany(targetEntity="RoleBasedUser\Entity\Feedback", mappedBy="courier")
         */
        private $feedbackCourier;
    
        /**
         * @ORM\OneToMany(targetEntity="RoleBasedUser\Entity\UserAvailability", mappedBy="user")
         */
        private $pleaseUseMe;
    
        /**
         * @ORM\OneToMany(targetEntity="RoleBasedUser\Entity\UserStoredLocations", mappedBy="user")
         */
        private $userAddresses;
    
        /**
         * @ORM\ManyToOne(targetEntity="RoleBasedUser\Entity\Corporate", inversedBy="user")
         * @ORM\JoinColumn(name="corporate_id", referencedColumnName="id")
         */
        private $corporate;
    
        /**
     * @ORM\OneToMany(targetEntity="Negotiation\Entity\Offer", mappedBy="user")
     */
    private $offer;
    
    /**
     * @ORM\ManyToMany(targetEntity="HierarchicalRole")
     * @ORM\JoinTable(name="rbu_users_roles",
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
     * )
     *
     * @var Collection
     * @access private
     */
    private $roles;
    
    /**
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(type="datetime")
     *
     * @var \DateTime
     * @access protected
     */
    protected $created;
    
    /**
     * @Gedmo\Timestampable(on="update")
     * @ORM\Column(type="datetime")
     *
     * @var \DateTime
     * @access protected
     */
    protected $modified;
    
    /**
     * Initiates all ArrayCollections
     *
     * @access public
     */
    public function __construct()
    {
        $this->roles = new ArrayCollection();
        $this->orderOwner = new ArrayCollection();
        $this->orderTo = new ArrayCollection();
        $this->orderFrom = new ArrayCollection();
        $this->orderCourier = new ArrayCollection();
        $this->clientFeedback = new ArrayCollection();
        $this->feedbackCourier = new ArrayCollection();
        $this->pleaseUseMe = new ArrayCollection();
        $this->userAddresses = new ArrayCollection();
        $this->offer = new ArrayCollection();
    }
    
    /**
     * {@inheritDoc}
     */
    public function getRoles()
    {
        return $this->roles->toArray();
    }
    
    public function getRole()
    {
        if(!empty($this->getRoles()[0])) {
            $roleObject = $this->getRoles()[0];
            return $roleObject->getName();
        }  else return "Not set";
    
    }
    
    /**
     * Set the list of roles
     * @param Collection $roles
     */
    public function setRoles(Collection $roles)
    {
        $this->roles->clear();
        foreach ($roles as $role) {
            $this->roles[] = $role;
        }
    }
    
    /**
     * Add one role to roles list
     * @param \Rbac\Role\RoleInterface $role
     */
    public function addRole(RoleInterface $role)
    {
        $this->roles[] = $role;
    }
    
    /**
     * Add Roles to the collection
     * @param Collection $roles
     */
    public function addRoles(Collection $roles)
    {
        foreach($roles as $role) {
            $this->roles->add($role);
        }
    }
    
    /**
     * Remove Roles from the collection
     * @param Collection $roles
     */
    public function removeRoles(Collection $roles)
    {
        foreach($roles as $role) {
            $this->roles->removeElement($role);
        }
    }
    
    /**
     * @return mixed
     */
    public function getCorporate()
    {
        return $this->corporate;
    }
    
    /**
     * @param mixed $corporate
     */
    public function setCorporate($corporate)
    {
        $this->corporate = $corporate;
    }
    
    /**
     * @return \DateTime
     */
    public function getCreated()
    {
        return $this->created;
    }
    
    /**
     * @param \DateTime $created
     */
    public function setCreated($created)
    {
        $this->created = $created;
    }
    
    /**
     * @return mixed
     */
    public function getFirstName()
    {
        return $this->firstName;
    }
    
    /**
     * @param mixed $firstName
     */
    public function setFirstName($firstName)
    {
        $this->firstName = $firstName;
    }
    
    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    
    /**
     * @param int $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * @return mixed
     */
    public function getLastName()
    {
        return $this->lastName;
    }
    
    /**
     * @param mixed $lastName
     */
    public function setLastName($lastName)
    {
        $this->lastName = $lastName;
    }
    
    /**
     * @return mixed
     */
    public function getLocation()
    {
        return $this->location;
    }
    
    /**
     * @param mixed $location
     */
    public function setLocation($location)
    {
        $this->location = $location;
    }
    
    /**
     * @return \DateTime
     */
    public function getModified()
    {
        return $this->modified;
    }
    
    /**
     * @param \DateTime $modified
     */
    public function setModified($modified)
    {
        $this->modified = $modified;
    }
    
    /**
     * @return mixed
     */
    public function getParent()
    {
        return $this->parent;
    }
    
    /**
     * @param mixed $parent
     */
    public function setParent($parent)
    {
        $this->parent = $parent;
    }
    
    /**
     * @return mixed
     */
    public function getPassword()
    {
        return $this->password;
    }
    
    /**
     * @param mixed $password
     */
    public function setPassword($password)
    {
        $this->password = $password;
    }
    
    /**
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }
    
    /**
     * @param string $email
     */
    public function setEmail($email)
    {
        $this->email = $email;
    }
    
    /**
     * @return string
     */
    public function getUuid()
    {
        return $this->uuid;
    }
    
    /**
     * @param string $uuid
     */
    public function setUuid($uuid)
    {
        $this->uuid = $uuid;
    }
    
    /**
     * {@inheritDoc}
     */
    public function getOrderOwner()
    {
        return $this->orderOwner->toArray();
    }
    
    /**
     * @param Collection $orderOwner
     */
    public function setOrderOwner(Collection $orderOwner)
    {
        $this->orderOwner->clear();
        foreach ($orderOwner as $order) {
            $this->orderOwner[] = $order;
        }
    }
    
    /**
     * @param Collection $orderOwner
     */
    public function addOrderOwner(Collection $orderOwner)
    {
        foreach($orderOwner as $order) {
            $this->orderOwner->add($order);
        }
    }
    
    /**
     * @param Collection $orderOwner
     */
    public function removeOrderOwner(Collection $orderOwner)
    {
        foreach($orderOwner as $order) {
            $this->orderOwner->removeElement($order);
        }
    }
    
    /**
     * {@inheritDoc}
     */
    public function getOrderTo()
    {
        return $this->orderTo->toArray();
    }
    
    /**
     * @param Collection $orderTo
     */
    public function setOrderTo(Collection $orderTo)
    {
        $this->orderTo->clear();
        foreach ($orderTo as $order) {
            $this->orderTo[] = $order;
        }
    }
    
    /**
     * @param Collection $orderTo
     */
    public function addOrderTo(Collection $orderTo)
    {
        foreach($orderTo as $order) {
            $this->orderTo->add($order);
        }
    }
    
    /**
     * @param Collection $orderTo
     */
    public function removeOrderTo(Collection $orderTo)
    {
        foreach($orderTo as $order) {
            $this->orderTo->removeElement($order);
        }
    }
    
    
    /**
     * {@inheritDoc}
     */
    public function getOrderFrom()
    {
        return $this->orderFrom->toArray();
    }
    
    /**
     * @param Collection $orderFrom
     */
    public function setOrderFrom(Collection $orderFrom)
    {
        $this->orderFrom->clear();
        foreach ($orderFrom as $order) {
            $this->orderFrom[] = $order;
        }
    }
    
    /**
     * @param Collection $orderFrom
     */
    public function addOrderFrom(Collection $orderFrom)
    {
        foreach($orderFrom as $order) {
            $this->orderFrom->add($order);
        }
    }
    
    /**
     * @param Collection $orderFrom
     */
    public function removeOrderFrom(Collection $orderFrom)
    {
        foreach($orderFrom as $order) {
            $this->orderFrom->removeElement($order);
        }
    }
    
    /**
     * {@inheritDoc}
     */
    public function getOrderCourier()
    {
        return $this->orderCourier->toArray();
    }
    
    /**
     * @param Collection $orderCourier
     */
    public function setOrderCourier(Collection $orderCourier)
    {
        $this->orderCourier->clear();
        foreach ($orderCourier as $order) {
            $this->orderCourier[] = $order;
        }
    }
    
    /**
     * @param Collection $orderCourier
     */
    public function addOrderCourier(Collection $orderCourier)
    {
        foreach($orderCourier as $order) {
            $this->orderCourier->add($order);
        }
    }
    
    /**
     * @param Collection $orderCourier
     */
    public function removeOrderCourier(Collection $orderCourier)
    {
        foreach($orderCourier as $order) {
            $this->orderCourier->removeElement($order);
        }
    }
    
    /**
     * {@inheritDoc}
     */
    public function getClientFeedback()
    {
        return $this->clientFeedback->toArray();
    }
    
    /**
     * @param Collection $clientFeedback
     */
    public function setClientFeedback(Collection $clientFeedback)
    {
        $this->clientFeedback->clear();
        foreach ($clientFeedback as $feedback) {
            $this->clientFeedback[] = $feedback;
        }
    }
    
    /**
     * @param Collection $clientFeedback
     */
    public function addClientFeedback(Collection $clientFeedback)
    {
        foreach($clientFeedback as $feedback) {
            $this->clientFeedback->add($feedback);
        }
    }
    
    /**
     * @param Collection $clientFeedback
     */
    public function removeClientFeedback(Collection $clientFeedback)
    {
        foreach($clientFeedback as $feedback) {
            $this->clientFeedback->removeElement($feedback);
        }
    }
    
    /**
     * {@inheritDoc}
     */
    public function getFeedbackCourier()
    {
        return $this->feedbackCourier->toArray();
    }
    
    /**
     * @param Collection $feedbackCourier
     */
    public function setFeedbackCourier(Collection $feedbackCourier)
    {
        $this->feedbackCourier->clear();
        foreach ($feedbackCourier as $feedback) {
            $this->feedbackCourier[] = $feedback;
        }
    }
    
    /**
     * @param Collection $feedbackCourier
     */
    public function addFeedbackCourier(Collection $feedbackCourier)
    {
        foreach($feedbackCourier as $feedback) {
            $this->feedbackCourier->add($feedback);
        }
    }
    
    /**
     * @param Collection $feedbackCourier
     */
    public function removeFeedbackCourier(Collection $feedbackCourier)
    {
        foreach($feedbackCourier as $feedback) {
            $this->feedbackCourier->removeElement($feedback);
        }
    }
    
    /**
     * {@inheritDoc}
     */
    public function getPleaseUseMe()
    {
        return $this->pleaseUseMe->toArray();
    }
    
    /**
     * @param Collection $pleaseUseMe
     */
    public function setPleaseUseMe(Collection $pleaseUseMe)
    {
        $this->pleaseUseMe->clear();
        foreach ($pleaseUseMe as $useme) {
            $this->pleaseUseMe[] = $useme;
        }
    }
    
    /**
     * @param Collection $pleaseUseMe
     */
    public function addPleaseUseMe(Collection $pleaseUseMe)
    {
        foreach($pleaseUseMe as $useme) {
            $this->pleaseUseMe->add($useme);
        }
    }
    
    /**
     * @param Collection $pleaseUseMe
     */
    public function removePleaseUseMe(Collection $pleaseUseMe)
    {
        foreach($pleaseUseMe as $useme) {
            $this->pleaseUseMe->removeElement($useme);
        }
    }
    
    /**
     * {@inheritDoc}
     */
    public function getUserAddresses()
    {
        return $this->userAddresses->toArray();
    }
    
    /**
     * @param Collection $userAddresses
     */
    public function setUserAddresses(Collection $userAddresses)
    {
        $this->userAddresses->clear();
        foreach ($userAddresses as $address) {
            $this->userAddresses[] = $address;
        }
    }
    
    /**
     * @param Collection $userAddresses
     */
    public function addUserAddresses(Collection $userAddresses)
    {
        foreach($userAddresses as $address) {
            $this->userAddresses->add($address);
        }
    }
    
    /**
     * @param Collection $userAddresses
     */
    public function removeUserAddresses(Collection $userAddresses)
    {
        foreach($userAddresses as $address) {
            $this->userAddresses->removeElement($address);
        }
    }
    
    /**
     * {@inheritDoc}
     */
    public function getOffer()
    {
        return $this->offer->toArray();
    }
    
    /**
     * @param Collection $offer
     */
    public function setOffer(Collection $offer)
    {
        $this->offer->clear();
        foreach ($offer as $n) {
            $this->offer[] = $n;
        }
    }
    
    /**
     * @param Collection $offer
     */
    public function addOffer(Collection $offer)
    {
        foreach($offer as $n) {
            $this->offer->add($n);
        }
    }
    
    /**
     * @param Collection $offer
     */
    public function removeOffer(Collection $offer)
    {
        foreach($offer as $n) {
            $this->offer->removeElement($n);
        }
    }
    
    /**
     * @param int $state
     */
    public function setState($state)
    {
        $this->state = $state;
    }
    
    /**
     * @return int
     */
    public function getState()
    {
        return $this->state;
    }
    
    }
    

    我的订单实体:

     <?php
    namespace Negotiation\Entity;
    use Doctrine\ORM\Mapping AS ORM;
    
    /**
     * @ORM\Entity
     */
    class Order
    {
        /**
         * @ORM\Id
         * @ORM\Column(type="integer")
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
    
        /**
         * @ORM\Column(type="integer", nullable=true)
         */
        private $size;
    
        /**
         * @ORM\Column(type="float", length=15, nullable=true)
         */
        private $total;
    
        /**
         * @ORM\Column(nullable=true)
         */
        private $initialOffer;
    
        /**
         * @ORM\ManyToOne(targetEntity="RoleBasedUser\Entity\User", inversedBy="orderOwner")
         * @ORM\JoinColumn(name="user_order_owner", referencedColumnName="id")
         */
        private $userOwner;
    
        /**
         * @ORM\ManyToOne(targetEntity="RoleBasedUser\Entity\User", inversedBy="orderTo")
         * @ORM\JoinColumn(name="user_order_to", referencedColumnName="id")
         */
        private $userTo;
    
        /**
         * @ORM\OneToMany(targetEntity="RoleBasedUser\Entity\Feedback", mappedBy="order")
         */
        private $feedback;
    
        /**
         * @ORM\ManyToOne(targetEntity="RoleBasedUser\Entity\User", inversedBy="orderFrom")
         * @ORM\JoinColumn(name="user_order_from", referencedColumnName="id")
         */
        private $userFrom;
    
        /**
         * @ORM\ManyToOne(targetEntity="RoleBasedUser\Entity\User", inversedBy="orderCourier")
         * @ORM\JoinColumn(name="user_order_courier", referencedColumnName="id")
         */
        private $userCourier;
    
        /**
         * @ORM\ManyToOne(targetEntity="Negotiation\Entity\Event", inversedBy="wayBillCollection")
         */
        private $eventCollection;
    
        /**
         * @ORM\ManyToOne(targetEntity="Negotiation\Entity\Event", inversedBy="wayBillDelivery")
         */
        private $eventDelivery;
    
        /**
         * @ORM\ManyToOne(targetEntity="Negotiation\Entity\Currency", inversedBy="order")
         */
        private $currency;
    
        /**
         * @ORM\ManyToOne(targetEntity="Negotiation\Entity\CapacityLimitation", inversedBy="order")
         */
        private $capacityLimitation;
    
        /**
         * @ORM\ManyToOne(targetEntity="Negotiation\Entity\Negotiation", inversedBy="order")
         */
        private $negotiation;
    
        /**
         * @ORM\ManyToOne(targetEntity="Negotiation\Entity\Address", inversedBy="orderFrom")
         */
        private $addressFrom;
    
        /**
         * @ORM\ManyToOne(targetEntity="Negotiation\Entity\Address", inversedBy="orderTo")
         */
        private $addressTo;
    
        /**
         * @return mixed
         */
        public function getAddressFrom()
        {
            return $this->addressFrom;
        }
    
        /**
         * @param mixed $addressFrom
         */
        public function setAddressFrom($addressFrom)
        {
            $this->addressFrom = $addressFrom;
        }
    
        /**
         * @return mixed
         */
        public function getAddressTo()
        {
            return $this->addressTo;
        }
    
        /**
         * @param mixed $addressTo
         */
        public function setAddressTo($addressTo)
        {
            $this->addressTo = $addressTo;
        }
    
        /**
         * @return mixed
         */
        public function getCapacityLimitation()
        {
            return $this->capacityLimitation;
        }
    
        /**
         * @param mixed $capacityLimitation
         */
        public function setCapacityLimitation($capacityLimitation)
        {
            $this->capacityLimitation = $capacityLimitation;
        }
    
        /**
         * @return mixed
         */
        public function getCurrency()
        {
            return $this->currency;
        }
    
        /**
         * @param mixed $currency
         */
        public function setCurrency($currency)
        {
            $this->currency = $currency;
        }
    
        /**
         * @return mixed
         */
        public function getEventCollection()
        {
            return $this->eventCollection;
        }
    
        /**
         * @param mixed $eventCollection
         */
        public function setEventCollection($eventCollection)
        {
            $this->eventCollection = $eventCollection;
        }
    
        /**
         * @return mixed
         */
        public function getEventDelivery()
        {
            return $this->eventDelivery;
        }
    
        /**
         * @param mixed $eventDelivery
         */
        public function setEventDelivery($eventDelivery)
        {
            $this->eventDelivery = $eventDelivery;
        }
    
        /**
         * @return mixed
         */
        public function getFeedback()
        {
            return $this->feedback;
        }
    
        /**
         * @param mixed $feedback
         */
        public function setFeedback($feedback)
        {
            $this->feedback = $feedback;
        }
    
        /**
         * @return mixed
         */
        public function getId()
        {
            return $this->id;
        }
    
        /**
         * @param mixed $id
         */
        public function setId($id)
        {
            $this->id = $id;
        }
    
        /**
         * @return mixed
         */
        public function getInitialOffer()
        {
            return $this->initialOffer;
        }
    
        /**
         * @param mixed $initialOffer
         */
        public function setInitialOffer($initialOffer)
        {
            $this->initialOffer = $initialOffer;
        }
    
        /**
         * @return mixed
         */
        public function getNegotiation()
        {
            return $this->negotiation;
        }
    
        /**
         * @param mixed $negotiation
         */
        public function setNegotiation($negotiation)
        {
            $this->negotiation = $negotiation;
        }
    
        /**
         * @return mixed
         */
        public function getSize()
        {
            return $this->size;
        }
    
        /**
         * @param mixed $size
         */
        public function setSize($size)
        {
            $this->size = $size;
        }
    
        /**
         * @return mixed
         */
        public function getTotal()
        {
            return $this->total;
        }
    
        /**
         * @param mixed $total
         */
        public function setTotal($total)
        {
            $this->total = $total;
        }
    
        /**
         * @return mixed
         */
        public function getUserCourier()
        {
            return $this->userCourier;
        }
    
        /**
         * @param mixed $userCourier
         */
        public function setUserCourier($userCourier)
        {
            $this->userCourier = $userCourier;
        }
    
        /**
         * @return mixed
         */
        public function getUserFrom()
        {
            return $this->userFrom;
        }
    
        /**
         * @param mixed $userFrom
         */
        public function setUserFrom($userFrom)
        {
            $this->userFrom = $userFrom;
        }
    
        /**
         * @return mixed
         */
        public function getUserOwner()
        {
            return $this->userOwner;
        }
    
        /**
         * @param mixed $userOwner
         */
        public function setUserOwner($userOwner)
        {
            $this->userOwner = $userOwner;
        }
    
        /**
         * @return mixed
         */
        public function getUserTo()
        {
            return $this->userTo;
        }
    
        /**
         * @param mixed $userTo
         */
        public function setUserTo($userTo)
        {
            $this->userTo = $userTo;
        }
    }
    

    编辑:

    当我尝试编辑用户并且发生例外时出现错误:$ this-&gt; updateForm-&gt; bind($ object);

    $user_id = (int) $this->params()->fromRoute('user_id', 0);
            $object = $this->userService->find($user_id);
    
            $prg = $this->prg();
    
            if ($prg instanceof Response) {
                return $prg;
            } elseif ($prg === false) {
    
                $this->updateForm->bind($object);
    
                return $this->getVM()->setVariables([
                        'user' => $object,
                        'form' => $this->updateForm
                    ]);
            }
    

    编辑:

    基本上这三个表会导致问题,一旦我删除它们,一切都按预期工作:

    //    /**
    //     * @ORM\OneToMany(targetEntity="Negotiation\Entity\Order", mappedBy="userOwner")
    //     */
    //    private $orderOwner;
    
    //    /**                      `
    //     * @ORM\OneToMany(targetEntity="Negotiation\Entity\Order", mappedBy="userTo")
    //     */
    //    private $orderTo;
    
    //    /**
    //     * @ORM\OneToMany(targetEntity="Negotiation\Entity\Order", mappedBy="userFrom")
    //     */
    //    private $orderFrom;
    
    //    /**
    //     * @ORM\OneToMany(targetEntity="Negotiation\Entity\Order", mappedBy="userCourier")
    //     */
    //    private $orderCourier;
    

1 个答案:

答案 0 :(得分:0)

解决这个问题的方法是整理我的getter和setter。我过于专注于问题的注释,我从未向他们展示可能的错误。

感谢Svengali让我重新审视我做错了什么。

My Getters / Setters最初是这样的:

/**
     * {@inheritDoc}
     */
    public function getOrderCourier()
    {
        return $this->orderCourier->toArray();
    }

    /**
     * @param Collection $orderCourier
     */
    public function setOrderCourier(Collection $orderCourier)
    {
        $this->orderCourier->clear();
        foreach ($orderCourier as $order) {
            $this->orderCourier[] = $order;
        }
    }

    /**
     * @param Collection $orderCourier
     */
    public function addOrderCourier(Collection $orderCourier)
    {
        foreach($orderCourier as $order) {
            $this->orderCourier->add($order);
        }
    }

    /**
     * @param Collection $orderCourier
     */
    public function removeOrderCourier(Collection $orderCourier)
    {
        foreach($orderCourier as $order) {
            $this->orderCourier->removeElement($order);
        }
    }

我将它们改为:

/**
 * @return mixed
 */
public function getOrderCourier()
{
    return $this->orderCourier;
}

/**
 * @param mixed $orderCourier
 */
public function setOrderCourier($orderCourier)
{
    $this->orderCourier = $orderCourier;
}

问题不再存在。

感谢您的投入,虽然它可能只是一个简单的问题,但通常这是开发人员需要的,以便将它们推向正确的方向。