Posted by nick on December 19, 2010 at 3:59 pm
There is a bug with doctrine and many tickets have been opened for it from what I saw. Doing the following in a query will return no result
$q = Doctrine_Query::create()
->select('distinct(datetime_scraped)')
->from('Rate')
->orderBy('datetime_scraped desc');
The solution is to alias the distinct column like below
$q = Doctrine_Query::create()
->select('distinct(datetime_scraped) as datetime_scraped')
->from('Rate')
->orderBy('datetime_scraped desc');
Continue Reading
Posted by nick on October 30, 2010 at 1:28 pm
Doctrine ORM does not provide a built in method to truncate a table, so we must run a sql query manually. Use the below code and alter the SQL as needed:
$doctrine = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
$doctrine->query('TRUNCATE TABLE tableName');
unset($doctrine);
Continue Reading
Posted by nick on October 18, 2010 at 4:47 pm
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;
$profileObject->save();
The getProfileByPid() method is as follows:
public function getProfileByPid($pid) {
$q = Doctrine_Query::create()
->from('Profile')
->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!
Continue Reading