开发者

Doctrine 2.0 findBy* - not working when column contains underscores

I have the following class where one of the columns in the table contains an underscore - uni_id

When I try to the query:

$campus_at_uni  = $this->em->getRepository('models\campus')->findByUni_id($campus->uni_id);

and error occurs. I suspect it is because of the underscore between uni and if.

Is there a workaround for this?

<?php
/**
 * CampusModel
 */

 namespace models;

/**
 * @Entity
 * @Table(name="campus")
 */ 
class Campus
{
    /** 
    * @Id
    * @Column(type="integer")
    * @GeneratedValue(strategy="AUTO")
    */
    public $id;

    /**
    * @Column(type="integer")
    */
    public $uni_id;

 开发者_高级运维   /**
    * @Column(type="string")
    */
    public $name;

    /**
    * @Column(type="datetime")
    */
    public $date_created;

    /**
    * @Column(type="datetime")
    */
    public $date_modified;

}
?>


I couldn't find a workaround for this so the simplest answer to this is to do the following:

$campus_at_uni  = $this->em->getRepository('models\Campus')->findBy(array('uni_id'=>$campus->uni_id));


You can implement method findByUniId in custom repository.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜