Doctrine ORM

Doctrine ORM: Fatal error: Call to a member function getOid() on a non-object 3

Came across this today and was unable to find a solution on Google, so hopefully this will help somebody out.  I had the following code using Doctrine ORM:

//load profile object
$clientProfile = new Profile();
$profileObject = $clientProfile->getProfileByPid($pid);
$profileObject->lead_type_reason = $lead_type_reason;

The getProfileByPid() method is as follows:

public function getProfileByPid($pid) {
$q = Doctrine_Query::create()
->where('id = ?', $pid);
try {
return $q->execute();
} catch (Doctrine_Connection_Exception $e) {

The problem is that the query returns multiple records and places them into a collection, rather than returning a single object as you might have expected.  Change the “return $q->execute()” to “return $q->fetchOne()” to solve the problem.  Better yet though, figure out why the query returns more than one record if you’re passing in a unique ID like I was.  Hope this helps!