cake-php
[Arriba] [Todas las Listas]

Re: Consigue registro viejo en beforeSave cuando actualizando (haciendo

To: cake-php@xxxxxxxxxxxxxxxx
Subject: Re: Consigue registro viejo en beforeSave cuando actualizando (haciendo un $esto->encontrar() dentro de beforeSave callback)
From: AD7six <andydawson76@xxxxxxxxx>
Date: Sun, 30 Jun 2013 11:35:21 -0700 (PDT)
Delivery-date: Sun, 30 Jun 2013 14:35:37 -0400
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=x-beenthere:date:from:to:message-id:in-reply-to:references: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=GwXoJgSyhrniSgnWMdaao1aQLgdp6h8Lwr4GhV70Zrg=; b=mLMXoA2+mG7+8EroGxN1XHeVXSzUtEGB+aaKEyXDiXzJU1zO4Ka4N519q2g//E6yTh k71k0vrXZJo0jmFjEmI4z+9H8g0xpv5Rn8gXKeOLxnqHmV+zZ+p8n28HID1CG4xEVfn8 U2q9CZ+/2AotmAxvY3W3QpOROM+3PQKBWnC7ePueRBCCfbHqnSt+7bss+PKHTSRJksm9 DAenBb2DFfMXHoa3Wa3xg3de0Os/bxovK/fLgvpssk9lnIbxMwE+NfpnldIscb1yKuFU tVjmCWj0L+pPGFtQIlFB4Hs+8sTeorY3lZ07JztBDJsQkeV8Gs/0UOIWldQZzLNn52q/ RxXA==
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-beenthere:date:from:to:message-id:in-reply-to:references: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=GwXoJgSyhrniSgnWMdaao1aQLgdp6h8Lwr4GhV70Zrg=; b=DME+76vtW/oKkBdJu0yKWOYrieNn8YwY9eApdy+wszkowHR7w8e+hXEqmQBZ6ZEjQd vbTHySHTO1IHa9lHx6kbw7+gcJjbWPlgYkoyl+OXwLzEl0LC6KtWC5BLRs7hTxuNcz4G pA/5plLu+w6CR6t4HMk1JAJKM+WmHTOvGexRSaIo92J7QOW5xAcNb4tMtGCK1UbHBzgi a52K1anJN5lInmCNf2q09eT9J/hzKFxbPslHXDNuUb15eyV3DzWHft43acYN7cfr0uV2 SN/ztBzFa8n/Wqs42qD+FEatOhVEYAmJonW67GSV4BMXp9I1SmeGko4suZamCCdyRcjo Fosw==
Envelope-to: traductor@xxxxxxxxxxx
In-reply-to: <87ea05b6-68aa-41d1-9a64-4ec3b8771d82@googlegroups.com>
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
References: <87ea05b6-68aa-41d1-9a64-4ec3b8771d82@googlegroups.com>
Reply-to: cake-php@xxxxxxxxxxxxxxxx
Sender: cake-php@xxxxxxxxxxxxxxxx

En sábado, 29 junio 2013 19:53:49 *UTC+2, *Vanja *Dizdarević escribió:
>
> 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
>

Si por "operación LEÍDA" significas un encontrar llamada (refieres a *findById - un 
encontrar) - aquello es bastante sencillamente no cierto.

Si llamas el Modelo de método::leído<*http://libro.*cakephp.*org/2.0/*en/los modelos que/recuperan-vuestro-dato.*html#Modelo-leído> aun así, 
poblará $esto->dato.

ANUNCIO

-- 
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.



On Saturday, 29 June 2013 19:53:49 UTC+2, Vanja Dizdarević wrote:
>
> 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
>

If by "READ operation" you mean a find call (you refer to findById - a 
find) - that is quite simply not true.

If you call the method Model::read<http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-read> however, 
it will populate $this->data.

AD

-- 
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>