space_balls
space_balls

Reputation: 1423

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;

}
?>

Upvotes: 1

Views: 1996

Answers (2)

Michal K.
Michal K.

Reputation: 189

You can implement method findByUniId in custom repository.

Upvotes: 1

space_balls
space_balls

Reputation: 1423

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));

Upvotes: 2

Related Questions