Separate INSERT and UPDATE queries in doctrine

Go To StackoverFlow.com

1

Is there any simple solution how to perform INSERT queries on one database and SELECT queries on another using Doctrine?

I'm trying to use Doctrine with Mysql replication...

2012-04-05 15:16
by samrockon
How do you use Doctrine: with symfony 1, Symfony 2, Zend, from scratch? Which version of doctrine do you use - j0k 2012-04-05 15:37
for now i use codeigniter + doctrine 1.2, however it is not so hard to switch to 2.x. if there will some sense in i - samrockon 2012-04-05 16:28


1

Already found a solution, 2 classes need to be modified:

class Doctrine_Query, change preQuery method:

public function preQuery()
{
    $doctrine_manager = Doctrine_Manager::getInstance();

    if ($this->getType() == Doctrine_Query::SELECT) {
       $this->_conn = $doctrine_manager->getConnection('slave');
    } else { 
       $this->_conn = $doctrine_manager->getConnection('master');
    }
}

class Doctrine_Record, update method save:

public function save(Doctrine_Connection $conn = null)
{
    if ($conn === null) {
        $conn = Doctrine_Manager::getInstance()->getConnection('master');
    }
    parent::save($conn);
}
2012-04-11 15:57
by samrockon
Ads