开发者

magic finder not working when i add a OneToMany association to an entity (Doctrine 2)

After i added a OneToMany Association to my Entity , the magic finder and any means to get results from database has stopped and i get A FATAL ERROR.

here's the first entity (Slaplans):

namespace ZC\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use ZC\Entity\Slaholidaylinks;
/**
 * Slaplans
 *
 * @Table(name="slaplans")
 * @Entity(repositoryClass="Repositories\Slaplans")
 */
class Slaplans
{
    /**
     * @var integer $slaplanid
     *
     * @Column(name="slaplanid", type="integer", nullable=false)
     * @Id
     * @GeneratedValue(strategy="IDENTITY")
     */
    private $slaplanid;

    /**
     * @var integer $slas开发者_JAVA技巧cheduleid
     *
     * @Column(name="slascheduleid", type="integer", nullable=false)
     */
    private $slascheduleid;

    /**
     * @var string $title
     *
     * @Column(name="title", type="string", length=255, nullable=false)
     */
    private $title;

    /**
     * @var float $overduehrs
     *
     * @Column(name="overduehrs", type="float", nullable=false)
     */
    private $overduehrs;

    /**
     * @var float $resolutionduehrs
     *
     * @Column(name="resolutionduehrs", type="float", nullable=false)
     */
    private $resolutionduehrs;

    /**
     * @var smallint $isenabled
     *
     * @Column(name="isenabled", type="smallint", nullable=false)
     */
    private $isenabled;

    /**
     * @var integer $sortorder
     *
     * @Column(name="sortorder", type="integer", nullable=false)
     */
    private $sortorder;

    /**
     * @var smallint $ruletype
     *
     * @Column(name="ruletype", type="smallint", nullable=false)
     */
    private $ruletype;

    /**
     * @var integer $dateline
     *
     * @Column(name="dateline", type="integer", nullable=false)
     */
    private $dateline;

    /**
     * @OneToMany(targetEntity="Slaholidaylinks" , mappedBy="planid", cascade={"persist"} )
     */
    private $holidaylinks;

    public function __construct(){

        $this->holidaylinks= new ArrayCollection();
            }

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

    /**
     * Set slascheduleid
     *
     * @param integer $slascheduleid
     */
    public function setSlascheduleid($slascheduleid)
    {
        $this->slascheduleid = $slascheduleid;
    }

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

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

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

    /**
     * Set overduehrs
     *
     * @param float $overduehrs
     */
    public function setOverduehrs($overduehrs)
    {
        $this->overduehrs = $overduehrs;
    }

    /**
     * Get overduehrs
     *
     * @return float $overduehrs
     */
    public function getOverduehrs()
    {
        return $this->overduehrs;
    }

    /**
     * Set resolutionduehrs
     *
     * @param float $resolutionduehrs
     */
    public function setResolutionduehrs($resolutionduehrs)
    {
        $this->resolutionduehrs = $resolutionduehrs;
    }

    /**
     * Get resolutionduehrs
     *
     * @return float $resolutionduehrs
     */
    public function getResolutionduehrs()
    {
        return $this->resolutionduehrs;
    }

    /**
     * Set isenabled
     *
     * @param smallint $isenabled
     */
    public function setIsenabled($isenabled)
    {
        $this->isenabled = $isenabled;
    }

    /**
     * Get isenabled
     *
     * @return smallint $isenabled
     */
    public function getIsenabled()
    {
        return $this->isenabled;
    }

    /**
     * Set sortorder
     *
     * @param integer $sortorder
     */
    public function setSortorder($sortorder)
    {
        $this->sortorder = $sortorder;
    }

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

    /**
     * Set ruletype
     *
     * @param smallint $ruletype
     */
    public function setRuletype($ruletype)
    {
        $this->ruletype = $ruletype;
    }

    /**
     * Get ruletype
     *
     * @return smallint $ruletype
     */
    public function getRuletype()
    {
        return $this->ruletype;
    }

    /**
     * Set dateline
     *
     * @param integer $dateline
     */
    public function setDateline($dateline)
    {
        $this->dateline = $dateline;
    }

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

    /*
     * Get Holiday links
     * @return ArrayCollection $holidaylinks
     */
    public function getHolidaylinks()
    {
        return $this->holidaylinks;
    }
/*
    public function addHolidaylinks(Slaholidaylinks $aholidaylink)
    {
        $this->holidaylinks[]=$aholidaylink;
    }*/

}


    /**
     * @var string $title
     *
     * @Column(name="title", type="string", length=255, nullable=false)
     */
    private $title;

    /**
     * @var float $overduehrs
     *
     * @Column(name="overduehrs", type="float", nullable=false)
     */
    private $overduehrs;

    /**
     * @var float $resolutionduehrs
     *
     * @Column(name="resolutionduehrs", type="float", nullable=false)
     */
    private $resolutionduehrs;

    /**
     * @var smallint $isenabled
     *
     * @Column(name="isenabled", type="smallint", nullable=false)
     */
    private $isenabled;

    /**
     * @var integer $sortorder
     *
     * @Column(name="sortorder", type="integer", nullable=false)
     */
    private $sortorder;

    /**
     * @var smallint $ruletype
     *
     * @Column(name="ruletype", type="smallint", nullable=false)
     */
    private $ruletype;

    /**
     * @var integer $dateline
     *
     * @Column(name="dateline", type="integer", nullable=false)
     */
    private $dateline;

    /**
     * @OneToMany(targetEntity="Slaholidaylinks" , mappedBy="planid", cascade={"persist"} )
     */
    private $holidaylinks;

    public function __construct(){

        $this->holidaylinks= new ArrayCollection();
            }

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

    /**
     * Set slascheduleid
     *
     * @param integer $slascheduleid
     */
    public function setSlascheduleid($slascheduleid)
    {
        $this->slascheduleid = $slascheduleid;
    }

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

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

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

    /**
     * Set overduehrs
     *
     * @param float $overduehrs
     */
    public function setOverduehrs($overduehrs)
    {
        $this->overduehrs = $overduehrs;
    }

    /**
     * Get overduehrs
     *
     * @return float $overduehrs
     */
    public function getOverduehrs()
    {
        return $this->overduehrs;
    }

    /**
     * Set resolutionduehrs
     *
     * @param float $resolutionduehrs
     */
    public function setResolutionduehrs($resolutionduehrs)
    {
        $this->resolutionduehrs = $resolutionduehrs;
    }

    /**
     * Get resolutionduehrs
     *
     * @return float $resolutionduehrs
     */
    public function getResolutionduehrs()
    {
        return $this->resolutionduehrs;
    }

    /**
     * Set isenabled
     *
     * @param smallint $isenabled
     */
    public function setIsenabled($isenabled)
    {
        $this->isenabled = $isenabled;
    }

    /**
     * Get isenabled
     *
     * @return smallint $isenabled
     */
    public function getIsenabled()
    {
        return $this->isenabled;
    }

    /**
     * Set sortorder
     *
     * @param integer $sortorder
     */
    public function setSortorder($sortorder)
    {
        $this->sortorder = $sortorder;
    }

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

    /**
     * Set ruletype
     *
     * @param smallint $ruletype
     */
    public function setRuletype($ruletype)
    {
        $this->ruletype = $ruletype;
    }

    /**
     * Get ruletype
     *
     * @return smallint $ruletype
     */
    public function getRuletype()
    {
        return $this->ruletype;
    }

    /**
     * Set dateline
     *
     * @param integer $dateline
     */
    public function setDateline($dateline)
    {
        $this->dateline = $dateline;
    }

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

    /*
     * Get Holiday links
     * @return ArrayCollection $holidaylinks
     */
    public function getHolidaylinks()
    {
        return $this->holidaylinks;
    }
/*
    public function addHolidaylinks(Slaholidaylinks $aholidaylink)
    {
        $this->holidaylinks[]=$aholidaylink;
    }*/

}

here's the second Entity (Slaholidaylinks):

<?php
namespace ZC\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use ZC\Entity\Slaplans;

/**
 * Slaholidaylinks
 *
 * @Table(name="slaholidaylinks")
 * @Entity(repositroyClass="Repositories\Slaholidaylinks")
 */
class Slaholidaylinks
{
    /**
     * @var integer $slaholidaylinkid
     *
     * @Column(name="slaholidaylinkid", type="integer", nullable=false)
     * @Id
     * @GeneratedValue(strategy="IDENTITY")
     */
    private $slaholidaylinkid;

    /**
     * @var Slaplans $slaholidayid
     * @ManyToOne(targetEntity="Slaplans" , inversedBy="holidaylinks" )
     * @JoinColumn(name='slaplanid',referencedColumnName='slaplanid')
     */
    private $slaplanid;

    /**
     * @var integer $slaholidayid
     *
     * @Column(name="slaholidayid", type="integer", nullable=false)
     */
    private $slaholidayid;


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

    /**
     * Set slaplanid
     *
     * @param integer $slaplanid
     */
    public function setSlaplanid(Slaplans $slaplanid)
    {
        $this->slaplanid = $slaplanid;
    }

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

    /**
     * Set slaholidayid
     *
     * @param integer $slaholidayid
     */
    public function setSlaholidayid($slaholidayid)
    {
        $this->slaholidayid = $slaholidayid;
    }

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

where i try to get a Slaplans Entity using the following code i get a fatal error:

$default=$this->_em->getRepository('ZC\Entity\Slaplans')->findOneBySlaplanid($planid);

I tried the queryBuilder but i get an error also when i run the getResult function.

Please help me .


For the holidaylinks variable(Slaplans Entity):

/**
     *
     * @param \Doctrine\Common\Collections\Collection 
     *
     * @OneToMany(targetEntity="Slaholidaylinks",mappedBy="planid", cascade={"persist"})
     */
    private $holidaylinks;

For the planid variable( Slaholidaylinks Entity ):

/**
     *
     * @var Slaplans
     * @ManyToOne(targetEntity="Slaplans",inversedBy="holidaylinks")
     * @JoinColumns({
     *  @JoinColumn(name="slaplanid", referencedColumnName="slaplanid")
     * })
     */
    private $planid;

This is how i fixed my problem :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜