开发者

DQL association error when run query

Im new in DQL and doctrine 2 so, please be patient. I have this query:

select c, m from A10\CrmBundle\Entity\Crm c inner join c.irszam m on m.irszam = c.cim1irszam where c.kod = ?1

I get this error back:

[Semantical Error] line 0, col 64 near 'm on m.irszam': Error: Class A10\CrmBundle\Entity\Crm has no association named irszam

Entities:

  class Crm
    {
        /**
         * @Id 
         * @OneToOne(targetEntity="megye", mappedBy="kod")
         *
         */
        protected $kod;
        ...
    }

   class Megye
    {

       ...

        /**
         * @OneToOne(targetEntity=开发者_如何学Go"crm", inversedBy="irszam")
         * @JoinColumn(name="irszam_id", referencedColumnName="id")
         * @Column(type="integer")
         */
        protected $irszam;
       ...
    }

Thanks for help!


Try replacing "on" by "with" in your query. Also, you are using identity (@Id) through foreign entities (@OneToOne), so make sure you're using Doctrine 2.1 (which is already at Release Candidate state), because that functionality is not available in 2.0.x series.

Also, I think you have an error in your association mapping. I think what you really want to do is:

class Crm
{
    /**
     * @Id 
     * @OneToOne(targetEntity="megye", mappedBy="irszam")
     *
     */
    protected $kod;
    ...
}

class Megye
{

   ...

    /**
     * @OneToOne(targetEntity="crm", inversedBy="kod")
     * @JoinColumn(name="irszam_id", referencedColumnName="id")
     * @Column(type="integer")
     */
    protected $irszam;
   ...
}

In other words, you have to switch the mappedBy and inversedBy mapping properties, as defined here. You probably will have to recreate the DB schema after these changes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜