cake-php
[Arriba] [Todas las Listas]

Consigue registro viejo en beforeSave cuando actualizando (haciendo un $

To: cake-php@xxxxxxxxxxxxxxxx
Subject: Consigue registro viejo en beforeSave cuando actualizando (haciendo un $esto->encontrar() dentro de beforeSave callback)
From: Vanja Dizdarević <lex.non.scripta@xxxxxxxxx>
Date: Sat, 29 Jun 2013 10:53:49 -0700 (PDT)
Delivery-date: Sat, 29 Jun 2013 13:54:03 -0400
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=x-beenthere:date:from:to:message-id:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=IJoonnetyWag3v9gqkaazCzT+e4Ny91FA84MNCAkYKY=; b=qaCCHei7a6lzZlXMFB+WGDbyepbRc0aXsTTUIj2L4tf7+UKq8y23CFcWVk00s95dEn ZF6JSNJrJGU+xUqMTi8Hk546Jln+WG3RferT8BS783PtaUd7yf81LrpN2fVL17pVMxkp 6TbEafFk24Xx7t/cdNTHAPKcq7LQ37UIr8p2TUGQYHO8hpbM1kV5bS4BUdFsJp3F476M 2F8YjjkW/bKFSz3oMDsygOOoo87BLhxWJugtAUKYBunwOjPbfwAmC5iB4LmMgZM62O9D fbPc/QMcrDUEsotLNd9MowT6bTeFNrU43N/3PA9lrZPzk23lXRfT9P6z23AsCod8Wu8d 3O5w==
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-beenthere:date:from:to:message-id:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=IJoonnetyWag3v9gqkaazCzT+e4Ny91FA84MNCAkYKY=; b=FG+2xyb8Efeb7Uxz4VJUJzTTSiZ2Jn6Qu6sC2LXB7aMVok9oeT5vym0skbNUdpp1zX 4O6WSK9Khf0ZpzCI6VMjbijHC5Rfou6UsbFv9AKSNTHBSwLsI5rTzPLqvbB+xQy7ISzL pWNf7GuH63/LMamXEPQbYqh//V8WjkRcDQpucJrmC12ll8yEh+CBJ/J5SELqbJs7JYRE jJ+yLQGrueL+La9bURXKTiTrH2PqMKZY3b9aFCVc0Gjuztjz6CzDOmG7IUgeuGvF48RR 5RRmJh8Qu3b0PFqNmwVU1VHTt1avToa2FSKtCHvcTP/1ASwkT3Opp4ikQ/kUS66j/r65 EZ1w==
Envelope-to: traductor@xxxxxxxxxxx
List-archive: <http://groups.google.com/group/cake-php>
List-help: <http://groups.google.com/support/>, <mailto:cake-php+help@googlegroups.com>
List-id: <cake-php.googlegroups.com>
List-post: <http://groups.google.com/group/cake-php/post>, <mailto:cake-php@googlegroups.com>
List-subscribe: <http://groups.google.com/group/cake-php/subscribe>, <mailto:cake-php+subscribe@googlegroups.com>
List-unsubscribe: <http://groups.google.com/group/cake-php/subscribe>, <mailto:googlegroups-manage+1003367825667+unsubscribe@googlegroups.com>
Mailing-list: list cake-php@xxxxxxxxxxxxxxxx; contact cake-php+owners@xxxxxxxxxxxxxxxx
Reply-to: cake-php@xxxxxxxxxxxxxxxx
Sender: cake-php@xxxxxxxxxxxxxxxx
Cuando actualizando una fila, deseo leer el "dato" viejo antes de salvar el 
registro actual.

Aquí un ejemplo simplificado:

código de Controlador:
$esto->Usuario->salvar(['*id' => 3, '*username' => 'un-nuevo-*username']);

código de Modelo:
Usuario de clase extiende *AppModel
   #adj_nom #público *beforeSave($opciones)
       //#pro_verbcj #ser un actualizar?
       Si (*isset($esto->dato[$esto->*alias][$esto->*primaryKey]))
            //#adj_nom #leer
            $*oldData = 
$esto->*findById($esto->dato[$esto->*alias][$esto->*primaryKey]); 
              //^^^ aquí el problema! ^^^
            Si ($*oldData[$esto->*alias]['*username_actualiza_cuenta'] >= 3)
               #verbcj falso;
            }
            más
              $#prn->dato[$esto->*alias]['*username_actualiza_cuenta'] = 
$*oldData[$esto->*alias]['*username_actualiza_cuenta'] + 1;
            }
       }
   }
}

El problema es, que $esto->*findById (o ninguno otra operación LEÍDA) llena 
el actual $esto->dato con el dato leído, el cual ruinas la corriente actualiza. 
Así que mi *gut me dice a *instantiate un modelo de Usuario nuevo dentro del *beforeSave 
(no *optimal) o a *somehow utiliza el *DataSource directamente sin todo 
el *callbacks y Modelo *instantiation.

El real *scenario realmente tiene que ser dentro del *beforeSave *callback, porque 
la lógica es requerida para cada modificación.

*Thanks!

-- 
Gustarnos en *FaceBook *https://www.facebook.com/*CakePHP
nos Encuentra en *Twitter *http://*twitter.*com/*CakePHP

--- 
Recibiste este mensaje porque eres *subscribed al *Google Grupos "*CakePHP" grupo.
A *unsubscribe de este grupo y la parón que recibe *emails de él, enviar un *email a pastel-*php+unsubscribe@xxxxxxxxxxxxxxxx.
A correo a este grupo, envía *email a pastel-php@xxxxxxxxxxxxxxxx.
Visita este grupo en *http://grupos.*google.*com/Pastel/de grupo-*php.
Para más opciones, visita *https://grupos.*google.*com/Los Grupos/optan_fuera.


When updating a row, I wish to read the "old" data before saving the 
current record.

Here's a simplified example:

Controller code:
$this->User->save(['id' => 3, 'username' => 'a-new-username']);

Model code:
class User extends AppModel {
   public function beforeSave($options){
       //is it an update?
       if (isset($this->data[$this->alias][$this->primaryKey])) {
            //read record
            $oldData = 
$this->findById($this->data[$this->alias][$this->primaryKey]); 
              //^^^ here's the problem! ^^^
            if ($oldData[$this->alias]['username_update_count'] >= 3){
               return false;
            }
            else {
              $this->data[$this->alias]['username_update_count'] = 
$oldData[$this->alias]['username_update_count'] + 1;
            }
       }
   }
}

The problem is, that $this->findById (or any other READ operation) fills 
the current $this->data with the read data, which ruins the current update. 
So my gut tells me to instantiate a new User model inside the beforeSave 
(not optimal) or to somehow use the DataSource directly without all the 
callbacks and Model instantiation.

The real scenario really has to be inside the beforeSave callback, because 
the logic is required for every modification.

Thanks!

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@xxxxxxxxxxxxxxxx.
To post to this group, send email to cake-php@xxxxxxxxxxxxxxxx.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


<Anterior por Tema] Tema Actual [Siguiente por Tema>