AFAIK it doesn't work on Cake => 1.2.x
>From comment on that post :

The approach using beforeSave() no longer works for cake 1.2. Looking at
CAKE/libs/model/model.php:save() the call to beforeSave() happens long after
variable $db has been set using the old value of $this->useDbConfig .


On Fri, Feb 11, 2011 at 6:39 PM, majna <[email protected]> wrote:

> Cleaner solution for master/slave using callbacks (or Behavior)
>
> function beforeSave() {
>    $this->useDbConfig = 'master';
>    return true;
> }
>
> function afterSave() {
>    $this->useDbConfig = 'default';
>    return true;
> }
>
> function beforeDelete() {
>    $this->useDbConfig = 'master';
>     return true;
> }
>
> function afterDelete() {
>    $this->useDbConfig = 'default';
>     return true;
> }
>
>
> http://bakery.cakephp.org/articles/eagerterrier/2007/05/26/load-balancing-and-mysql-master-and-slaves-2
>
> On Feb 10, 6:14 pm, ibejohn818 <[email protected]> wrote:
> > This what I am using.
> > ===
> > class AppModel extends Model {
> >
> >         public function save($data = null, $validate = true, $fieldList =
> > array()) {
> >
> >                 $this->useDbConfig = 'master';
> >
> >                 $success = parent::save($data,$validate,$fieldList);
> >
> >                 $this->useDbConfig = 'default';
> >
> >                 return $success;
> >
> >         }
> >
> >         public function saveAll($data = null, $options = array()) {
> >
> >                 $this->useDbConfig = 'master';
> >
> >                 $status = parent::saveAll($data,$options);
> >
> >                 $this->useDbConfig = 'default';
> >
> >                 return $status;
> >
> >         }
> >
> >         public function updateAll($fields, $conditions = true) {
> >
> >                 $this->useDbConfig = 'master';
> >
> >                 $status = parent::updateAll($fields,$conditions);
> >
> >                 $this->useDbConfig = 'default';
> >
> >                 return $status;
> >
> >         }
> >
> >         public function delete($id = null, $cascade = true) {
> >
> >                 $this->useDbConfig = "master";
> >
> >                 $status = parent::delete($id,$cascade);
> >
> >                 $this->useDbConfig = 'default';
> >
> >                 return $status;
> >
> >         }
> >
> > }
> >
> > ====
> >
> > For multiple Slaves you should use a load balancer to RoundRobin
> > Balance the requests to your slaves.
> >
> > On Feb 10, 9:05 am, Okto Silaban <[email protected]> wrote:
> >
> > > That's what I'm trying to do.
> > > I've setup 1 master and 2 slaves. But CakePHP doesn't support read &
> write
> > > query separation.
> > > So, do you have any information how can I split the read & write query?
> > > *other than rewrite all my models
> >
> > > thanks.
> >
> > > On Wed, Feb 9, 2011 at 10:03 AM, Dr. Tarique Sani <
> [email protected]>wrote:
> >
> > > > Have you split the reads and the writes?
> >
> > > > All the writes go to the master which is on a server of its own and
> > > > the reads are from the slaves which are typically on the same machine
> > > > as the webserver and of course use very aggressive caching
> >
> > > > Cheers
> > > > Tarique
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group
> at http://groups.google.com/group/cake-php
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to