cake-php
[Arriba] [Todas las Listas]

Re: Modelo::AfterFind $formato de resultados, asociaciones

To: cake-php@xxxxxxxxxxxxxxxx
Subject: Re: Modelo::AfterFind $formato de resultados, asociaciones
From: Vanja Dizdarević <lex.non.scripta@xxxxxxxxx>
Date: Sat, 29 Jun 2013 01:49:19 -0700 (PDT)
Delivery-date: Sat, 29 Jun 2013 04:49:34 -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=IWWjjxmkZob+Md3eT50r55LmjBFJ1ihvLevHcnM2QhA=; b=w560L149bod0pAvlwufO6v4GKhKfF08me5iHz/M6gyhnk0aw+Uton3qmJwrgVFY499 4p3uuVw0gMrEtOpVtRD5gOND6TILrV/sdyshmLrUJxCkiUG4dc7hpA946P74+YIZRX30 ukWt84M1ahglNLWS5iAxxPAaH2VL+9unfESxfV+7fsiHT5nVaOPUKwnQeB45B9yB1PFz +zDIwc1QJrhj0ogmX25n0qE2cpdAW0Z2B4h4T5rEoSzVJgdUHhtvDvcFZNbGvS/HDGt9 qf84Ald0Ti37xWyxyIfWFKQQLR9eQPK6NFw51EIQYhaUbyz3QXM1Zo8q3ssLlJ1F13Ng 5Nzw==
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=IWWjjxmkZob+Md3eT50r55LmjBFJ1ihvLevHcnM2QhA=; b=iySI0K8YQhzoJdrilvI1fYwdu8vUBjCj4gdBpImW6vIAEAd35EulnclMPrzlaqmefn XHwHrtAsGY6B43AawLWN+qdFIO8SYvew0l7Pb2x+gdQvU0htfMVuP4r3n9vu0rxkSXav BSDHtD0P6tCFmD3ZQ9887ZDu8i0pBkIpgkNcCLa3rO8qoH+l8hNYFoj9VDrY+RJfRxOU 7QFfcz+aYR7r4C5MKFqoSPeFLJdVer8cAWAvzqci4Q1Qh/jz8JEIjV9uk+Cn1Fqz14Ru PuUuG/p4mQtQ0Ub5akR2a0jKV1MqKXJFpsHJHtnSFFFiyX7w1pqPsk7BHEaqSmPkSK3K JZTg==
Envelope-to: traductor@xxxxxxxxxxx
In-reply-to: <99fec2a3-294e-4374-abc1-ffffece3c781@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: <12f3399f-39a3-4690-8bc8-986e870da0a0@googlegroups.com> <c253ea6d-61f4-4357-ba0f-e38cad818f32@googlegroups.com> <1c057a5d-0d1a-4219-b2a0-d056c88ffff9@googlegroups.com> <e3c1b85d-c7b2-4e2e-95cf-a5b68c0b3447@googlegroups.com> <99fec2a3-294e-4374-abc1-ffffece3c781@googlegroups.com>
Reply-to: cake-php@xxxxxxxxxxxxxxxx
Sender: cake-php@xxxxxxxxxxxxxxxx
*Thank te Andy para tomar tiempo para escribir todo aquello!

Tendría que haber hecho mi objetivo más claro, estoy de acuerdo - "qué formatos de variedad pueden ser 
esperados en el *afterFind *callback?"

Naturalmente, estoy intentando acceder sólo el dato del modelo respectivo en 
el modelo.

Después de leer vuestra respuesta y escribiendo arriba de una prueba para todas las 
asociaciones posibles, encuentra tipo y diferente *recursions, esto es mi conclusión:

### Opción 1:
$resultados = 
    [
        '*id' => '1',
        'campo1' => 'valor1'
        '*HasManyAlias' => [0 => [valores/de campos...], 1 => 
[valores/de campos...], *etc..],
        '*BelongsToAlias' => [ '*id' => 2, ...],
        '*hasOne' => [ '*id' => 5, ...]
    ]

### Opción 2:
$resultados = 
    [ 
        0 => [
            $esto->*alias =>[ '*id' => '1', 'campo1' => 'valor1' ],
            '*HasManyAlias' => [ 0 => [valores/de campos...], 1 => 
[valores/de campos...], *etc..],
            '*BelongsToAlias' => [ '*id' => 2, ...],
            '*hasOneAlias' => [ '*id' => 5, ...]
           ],
        2 => [ ... ],
        ... *etc.
    ]

 Este derecho de mirada?

Te preocupas demasiado lo que estoy intentando hacer... :) Pero la respuesta es en 
este hilo yo *posted más temprano: 
*https://grupos.*google.*com/Foro/#!Pastel/de tema-*php/*dOxsg9*Xv6*Iw

En viernes, junio 28, 2013 1:02:44 PM *UTC+2, ANUNCIO7seis escribió:
>
> *Damn lo un *typo:
>
>
> La $consulta "= falsa" primaria (un *intermediary *hasMany resultado de consulta) parece esto:
>
>
> variedad(
> 	(*int) 0 => variedad(
> 		'*HasManyAssoc' => variedad(
> 			'*id' => '1'
> 		)
> 	),
>
>         ...
> )
>
>
> (Igual cuando todo otro resultado de consulta formatos).
>
> Complacer justo mirar si en duda - es tanto más rápido/más fácil.
>
> ANUNCIO
>
> En viernes, 28 junio 2013 12:59:57 *UTC+2, ANUNCIO7seis escribió:
>>
>>
>>
>> En jueves, 27 junio 2013 22:25:02 *UTC+2, *Vanja *Dizdarević escribió:
>>>
>>> Cuando "solucionado" en el hilo enlacé a en el correo original: 
>>
>>
>>>          función pública *afterFind($resultados, $primario = falso) 
>>>                 #cnj (el método_existe($esto, '*doAfterFind')) 
>>>                           #cnj ($primario) 
>>>                                    #unknown{^*foreach ($resultados como $clave => $*val) 
>>>                                             #cnj 
>>> (*isset($*val[$esto->*alias])) 
>>>                                              
>>>         $#nom[$llave][$esto->*alias] = 
>>> $esto->*doAfterFind($resultados[$llave][$esto->*alias]); 
>>>                                                 } 
>>>                                       } 
>>>                           } más 
>>>                                   #cnj 
>>> (*isset($resultados[$esto->*primaryKey])) 
>>>                                            $#verbcj = 
>>> $esto->*doAfterFind($resultados); 
>>>                                    } más 
>>>                                             #unknown{^*foreach ($resultados como $clave => 
>>> $*val) 
>>>                                                      #cnj 
>>> (*isset($*val[$esto->*alias])) 
>>>                                                               #cnj 
>>> (*isset($*val[$esto->*alias][$esto->*primaryKey])) 
>>>                                                                
>>>         $#nom[$llave][$esto->*alias] = 
>>> $esto->*doAfterFind($resultados[$llave][$esto->*alias]); 
>>>                                                               } más 
>>>                                                                
>>>         #unknown{^*foreach ($resultados[$llave][$esto->*alias] cuando $llave2=> $*val2) 
>>>                                                                         
>>>         $#nom[$llave][$esto->*alias][$llave2] = 
>>> $esto->*doAfterFind($resultados[$llave][$esto->*alias][$llave2]); 
>>>                                                                          
>>>      } 
>>>                                                                     } 
>>>                                                           } 
>>>                                                 } 
>>>                                       } 
>>>                            } 
>>>                 } 
>>>                  resultados $de regreso; 
>>>          } 
>>> }
>>>
>>
>> Estas miradas de código para ser manera sobre complejo, posiblemente un *testament al 
>> ninguno-valor de lectura 5 año correos viejos en un *google grupo para un marco 
>> que es activamente mantenido y aplicando consejo encontrado a ciegas.
>>
>>
>>> Esto presuntamente aplica el mismo "*doAfterFind" método a todos los registros, 
>>> a toda costa del formato $de variedad de resultados pasado, tomando a cuenta todo 
>>> asociaciones posibles de un modelo primario a este modelo.
>>>
>>> Las cuestiones reales es: Qué es todos formatos de variedad podemos esperar en 
>>> la $variedad de resultados?
>>>
>>
>> Hace aquello te significa todavía no ha mirado =)?
>>
>> Un contar parece esto:
>>
>> variedad(
>> 	(*int) 0 => variedad(
>> 		(*int) 0 => variedad(
>> 			'cuenta' => '9'
>> 		)
>> 	)
>> )
>>
>>
>> un encontrar primero parece esto:
>>
>>
>> variedad(
>> 	(*int) 0 => variedad(
>> 		'*Alias' => variedad(
>> 			'*id' => '1'
>> 		),
>> 		'*HasManyAssoc' => variedad(
>> 			(*int) 0 => variedad(
>> 				'*id' => '1'
>> 			)
>> 		)
>> 	)
>> )
>>
>>
>> un encontrar todo parece esto:
>>
>> variedad(
>>
>> 	(*int) 0 => variedad(
>> 		'*Alias' => variedad(
>> 			'*id' => '1'
>> 		),
>> 		'*HasManyAssoc' => variedad(
>> 			(*int) 0 => variedad(
>> 				'*id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> La $consulta "= falsa" primaria (un *intermediary *hasMany resultado de consulta) parece esto:
>>
>>
>> variedad(
>> 	(*int) 0 => variedad(
>> 		'*HasManyAssoc' => variedad(
>> 			(*int) 0 => variedad(
>> 				'*id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> hay un patrón muy sencillo allí:
>>
>>
>> variedad($*int => variedad('*alias' => variedad('campo' => $valor)));
>>
>>
>> Con una excepción sencilla para *hasMany asociaciones, cuándo incluido en 
>> los resultados de la consulta primaria, todo primario encuentra *siempre *tener el mismo 
>> formato de resultados.
>>
>>
>>
>>> Para citar el *docs:
>>>  Si un modelo es *queried como una asociación el formato de$resultados puede 
>>> diferir; en vez del resultado normalmente conseguirías de un encontrar operación, 
>>> puedes conseguir esto:
>>>
>>> $variedad = de resultados(
>>>     'campo_1' => 'valor1',
>>>     'campo_2' => 'valor2');
>>>
>>>  
>>
>>> Tan, si deseo el *afterFind para encontrar el dato en la variedad de resultados, tengo que probar el formato de la variedad o puede confío en $valor primario?
>>>
>>
>> Yo .. Pensarte tendría que parar malgastar vuestro tiempo y *preguntar* cómo para hacer 
>> algo específicamente, de la mirada de vuestro *afterFind método, estás 
>> escribiendo alguna clase de *appmodel método que está convirtiendo/procesando todos los datos. Correcto ahora está yendo para correr en todas las consultas, bucle en todas las  llaves y por 
>> tanto probablemente afectar rendimiento incluso si está haciendo lo que lo quieres 
>> para hacer. Eres probablemente mejor de escribir cualquiera un *recursive método para 
>> manejar en el formato de resultados entero o un mucho alcance más estrecho método que 
>> *justo*  lo que específicamente quieres.
>>
>> *Qué es vuestro *afterFind el método intentando hacer?*
>> *
>> *
>> ANUNCIO
>>
>
En viernes, junio 28, 2013 1:02:44 PM *UTC+2, ANUNCIO7seis escribió:
>
> *Damn lo un *typo:
>
>
> La $consulta "= falsa" primaria (un *intermediary *hasMany resultado de consulta) parece esto:
>
>
> variedad(
> 	(*int) 0 => variedad(
> 		'*HasManyAssoc' => variedad(
> 			'*id' => '1'
> 		)
> 	),
>
>         ...
> )
>
>
> (Igual cuando todo otro resultado de consulta formatos).
>
> Complacer justo mirar si en duda - es tanto más rápido/más fácil.
>
> ANUNCIO
>
> En viernes, 28 junio 2013 12:59:57 *UTC+2, ANUNCIO7seis escribió:
>>
>>
>>
>> En jueves, 27 junio 2013 22:25:02 *UTC+2, *Vanja *Dizdarević escribió:
>>>
>>> Cuando "solucionado" en el hilo enlacé a en el correo original: 
>>
>>
>>>          función pública *afterFind($resultados, $primario = falso) 
>>>                 #cnj (el método_existe($esto, '*doAfterFind')) 
>>>                           #cnj ($primario) 
>>>                                    #unknown{^*foreach ($resultados como $clave => $*val) 
>>>                                             #cnj 
>>> (*isset($*val[$esto->*alias])) 
>>>                                              
>>>         $#nom[$llave][$esto->*alias] = 
>>> $esto->*doAfterFind($resultados[$llave][$esto->*alias]); 
>>>                                                 } 
>>>                                       } 
>>>                           } más 
>>>                                   #cnj 
>>> (*isset($resultados[$esto->*primaryKey])) 
>>>                                            $#verbcj = 
>>> $esto->*doAfterFind($resultados); 
>>>                                    } más 
>>>                                             #unknown{^*foreach ($resultados como $clave => 
>>> $*val) 
>>>                                                      #cnj 
>>> (*isset($*val[$esto->*alias])) 
>>>                                                               #cnj 
>>> (*isset($*val[$esto->*alias][$esto->*primaryKey])) 
>>>                                                                
>>>         $#nom[$llave][$esto->*alias] = 
>>> $esto->*doAfterFind($resultados[$llave][$esto->*alias]); 
>>>                                                               } más 
>>>                                                                
>>>         #unknown{^*foreach ($resultados[$llave][$esto->*alias] cuando $llave2=> $*val2) 
>>>                                                                         
>>>         $#nom[$llave][$esto->*alias][$llave2] = 
>>> $esto->*doAfterFind($resultados[$llave][$esto->*alias][$llave2]); 
>>>                                                                          
>>>      } 
>>>                                                                     } 
>>>                                                           } 
>>>                                                 } 
>>>                                       } 
>>>                            } 
>>>                 } 
>>>                  resultados $de regreso; 
>>>          } 
>>> }
>>>
>>
>> Estas miradas de código para ser manera sobre complejo, posiblemente un *testament al 
>> ninguno-valor de lectura 5 año correos viejos en un *google grupo para un marco 
>> que es activamente mantenido y aplicando consejo encontrado a ciegas.
>>
>>
>>> Esto presuntamente aplica el mismo "*doAfterFind" método a todos los registros, 
>>> a toda costa del formato $de variedad de resultados pasado, tomando a cuenta todo 
>>> asociaciones posibles de un modelo primario a este modelo.
>>>
>>> Las cuestiones reales es: Qué es todos formatos de variedad podemos esperar en 
>>> la $variedad de resultados?
>>>
>>
>> Hace aquello te significa todavía no ha mirado =)?
>>
>> Un contar parece esto:
>>
>> variedad(
>> 	(*int) 0 => variedad(
>> 		(*int) 0 => variedad(
>> 			'cuenta' => '9'
>> 		)
>> 	)
>> )
>>
>>
>> un encontrar primero parece esto:
>>
>>
>> variedad(
>> 	(*int) 0 => variedad(
>> 		'*Alias' => variedad(
>> 			'*id' => '1'
>> 		),
>> 		'*HasManyAssoc' => variedad(
>> 			(*int) 0 => variedad(
>> 				'*id' => '1'
>> 			)
>> 		)
>> 	)
>> )
>>
>>
>> un encontrar todo parece esto:
>>
>> variedad(
>>
>> 	(*int) 0 => variedad(
>> 		'*Alias' => variedad(
>> 			'*id' => '1'
>> 		),
>> 		'*HasManyAssoc' => variedad(
>> 			(*int) 0 => variedad(
>> 				'*id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> La $consulta "= falsa" primaria (un *intermediary *hasMany resultado de consulta) parece esto:
>>
>>
>> variedad(
>> 	(*int) 0 => variedad(
>> 		'*HasManyAssoc' => variedad(
>> 			(*int) 0 => variedad(
>> 				'*id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> hay un patrón muy sencillo allí:
>>
>>
>> variedad($*int => variedad('*alias' => variedad('campo' => $valor)));
>>
>>
>> Con una excepción sencilla para *hasMany asociaciones, cuándo incluido en 
>> los resultados de la consulta primaria, todo primario encuentra *siempre *tener el mismo 
>> formato de resultados.
>>
>>
>>
>>> Para citar el *docs:
>>>  Si un modelo es *queried como una asociación el formato de$resultados puede 
>>> diferir; en vez del resultado normalmente conseguirías de un encontrar operación, 
>>> puedes conseguir esto:
>>>
>>> $variedad = de resultados(
>>>     'campo_1' => 'valor1',
>>>     'campo_2' => 'valor2');
>>>
>>>  
>>
>>> Tan, si deseo el *afterFind para encontrar el dato en la variedad de resultados, tengo que probar el formato de la variedad o puede confío en $valor primario?
>>>
>>
>> Yo .. Pensarte tendría que parar malgastar vuestro tiempo y *preguntar* cómo para hacer 
>> algo específicamente, de la mirada de vuestro *afterFind método, estás 
>> escribiendo alguna clase de *appmodel método que está convirtiendo/procesando todos los datos. Correcto ahora está yendo para correr en todas las consultas, bucle en todas las  llaves y por 
>> tanto probablemente afectar rendimiento incluso si está haciendo lo que lo quieres 
>> para hacer. Eres probablemente mejor de escribir cualquiera un *recursive método para 
>> manejar en el formato de resultados entero o un mucho alcance más estrecho método que 
>> *justo*  lo que específicamente quieres.
>>
>> *Qué es vuestro *afterFind el método intentando hacer?*
>> *
>> *
>> ANUNCIO
>>
>
En viernes, junio 28, 2013 1:02:44 PM *UTC+2, ANUNCIO7seis escribió:
>
> *Damn lo un *typo:
>
>
> La $consulta "= falsa" primaria (un *intermediary *hasMany resultado de consulta) parece esto:
>
>
> variedad(
> 	(*int) 0 => variedad(
> 		'*HasManyAssoc' => variedad(
> 			'*id' => '1'
> 		)
> 	),
>
>         ...
> )
>
>
> (Igual cuando todo otro resultado de consulta formatos).
>
> Complacer justo mirar si en duda - es tanto más rápido/más fácil.
>
> ANUNCIO
>
> En viernes, 28 junio 2013 12:59:57 *UTC+2, ANUNCIO7seis escribió:
>>
>>
>>
>> En jueves, 27 junio 2013 22:25:02 *UTC+2, *Vanja *Dizdarević escribió:
>>>
>>> Cuando "solucionado" en el hilo enlacé a en el correo original: 
>>
>>
>>>          función pública *afterFind($resultados, $primario = falso) 
>>>                 #cnj (el método_existe($esto, '*doAfterFind')) 
>>>                           #cnj ($primario) 
>>>                                    #unknown{^*foreach ($resultados como $clave => $*val) 
>>>                                             #cnj 
>>> (*isset($*val[$esto->*alias])) 
>>>                                              
>>>         $#nom[$llave][$esto->*alias] = 
>>> $esto->*doAfterFind($resultados[$llave][$esto->*alias]); 
>>>                                                 } 
>>>                                       } 
>>>                           } más 
>>>                                   #cnj 
>>> (*isset($resultados[$esto->*primaryKey])) 
>>>                                            $#verbcj = 
>>> $esto->*doAfterFind($resultados); 
>>>                                    } más 
>>>                                             #unknown{^*foreach ($resultados como $clave => 
>>> $*val) 
>>>                                                      #cnj 
>>> (*isset($*val[$esto->*alias])) 
>>>                                                               #cnj 
>>> (*isset($*val[$esto->*alias][$esto->*primaryKey])) 
>>>                                                                
>>>         $#nom[$llave][$esto->*alias] = 
>>> $esto->*doAfterFind($resultados[$llave][$esto->*alias]); 
>>>                                                               } más 
>>>                                                                
>>>         #unknown{^*foreach ($resultados[$llave][$esto->*alias] cuando $llave2=> $*val2) 
>>>                                                                         
>>>         $#nom[$llave][$esto->*alias][$llave2] = 
>>> $esto->*doAfterFind($resultados[$llave][$esto->*alias][$llave2]); 
>>>                                                                          
>>>      } 
>>>                                                                     } 
>>>                                                           } 
>>>                                                 } 
>>>                                       } 
>>>                            } 
>>>                 } 
>>>                  resultados $de regreso; 
>>>          } 
>>> }
>>>
>>
>> Estas miradas de código para ser manera sobre complejo, posiblemente un *testament al 
>> ninguno-valor de lectura 5 año correos viejos en un *google grupo para un marco 
>> que es activamente mantenido y aplicando consejo encontrado a ciegas.
>>
>>
>>> Esto presuntamente aplica el mismo "*doAfterFind" método a todos los registros, 
>>> a toda costa del formato $de variedad de resultados pasado, tomando a cuenta todo 
>>> asociaciones posibles de un modelo primario a este modelo.
>>>
>>> Las cuestiones reales es: Qué es todos formatos de variedad podemos esperar en 
>>> la $variedad de resultados?
>>>
>>
>> Hace aquello te significa todavía no ha mirado =)?
>>
>> Un contar parece esto:
>>
>> variedad(
>> 	(*int) 0 => variedad(
>> 		(*int) 0 => variedad(
>> 			'cuenta' => '9'
>> 		)
>> 	)
>> )
>>
>>
>> un encontrar primero parece esto:
>>
>>
>> variedad(
>> 	(*int) 0 => variedad(
>> 		'*Alias' => variedad(
>> 			'*id' => '1'
>> 		),
>> 		'*HasManyAssoc' => variedad(
>> 			(*int) 0 => variedad(
>> 				'*id' => '1'
>> 			)
>> 		)
>> 	)
>> )
>>
>>
>> un encontrar todo parece esto:
>>
>> variedad(
>>
>> 	(*int) 0 => variedad(
>> 		'*Alias' => variedad(
>> 			'*id' => '1'
>> 		),
>> 		'*HasManyAssoc' => variedad(
>> 			(*int) 0 => variedad(
>> 				'*id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> La $consulta "= falsa" primaria (un *intermediary *hasMany resultado de consulta) parece esto:
>>
>>
>> variedad(
>> 	(*int) 0 => variedad(
>> 		'*HasManyAssoc' => variedad(
>> 			(*int) 0 => variedad(
>> 				'*id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> hay un patrón muy sencillo allí:
>>
>>
>> variedad($*int => variedad('*alias' => variedad('campo' => $valor)));
>>
>>
>> Con una excepción sencilla para *hasMany asociaciones, cuándo incluido en 
>> los resultados de la consulta primaria, todo primario encuentra *siempre *tener el mismo 
>> formato de resultados.
>>
>>
>>
>>> Para citar el *docs:
>>>  Si un modelo es *queried como una asociación el formato de$resultados puede 
>>> diferir; en vez del resultado normalmente conseguirías de un encontrar operación, 
>>> puedes conseguir esto:
>>>
>>> $variedad = de resultados(
>>>     'campo_1' => 'valor1',
>>>     'campo_2' => 'valor2');
>>>
>>>  
>>
>>> Tan, si deseo el *afterFind para encontrar el dato en la variedad de resultados, tengo que probar el formato de la variedad o puede confío en $valor primario?
>>>
>>
>> Yo .. Pensarte tendría que parar malgastar vuestro tiempo y *preguntar* cómo para hacer 
>> algo específicamente, de la mirada de vuestro *afterFind método, estás 
>> escribiendo alguna clase de *appmodel método que está convirtiendo/procesando todos los datos. Correcto ahora está yendo para correr en todas las consultas, bucle en todas las  llaves y por 
>> tanto probablemente afectar rendimiento incluso si está haciendo lo que lo quieres 
>> para hacer. Eres probablemente mejor de escribir cualquiera un *recursive método para 
>> manejar en el formato de resultados entero o un mucho alcance más estrecho método que 
>> *justo*  lo que específicamente quieres.
>>
>> *Qué es vuestro *afterFind el método intentando hacer?*
>> *
>> *
>> 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.


Thank you Andy for taking time to write all that!

I should have made my goal clearer, I agree - "what array formats can be 
expected in the afterFind callback?"

Of course, I am trying to access only the respective model's data in the 
model.

After reading your answer and writing up a test for all possible 
associations, find types and different recursions, this is my conclusion:

### Option 1:
$results = 
    [
        'id' => '1',
        'field1' => 'value1'
        'HasManyAlias' => [0 => [fields/values...], 1 => 
[fields/values...], etc..],
        'BelongsToAlias' => [ 'id' => 2, ...],
        'hasOne' => [ 'id' => 5, ...]
    ]

### Option 2:
$results = 
    [ 
        0 => [
            $this->alias =>[ 'id' => '1', 'field1' => 'value1' ],
            'HasManyAlias' => [ 0 => [fields/values...], 1 => 
[fields/values...], etc..],
            'BelongsToAlias' => [ 'id' => 2, ...],
            'hasOneAlias' => [ 'id' => 5, ...]
           ],
        2 => [ ... ],
        ... etc.
    ]

Does this look right?

You worry too much what I am trying to do... :) But the answer is in this 
thread I posted earlier: 
https://groups.google.com/forum/#!topic/cake-php/dOxsg9Xv6Iw

On Friday, June 28, 2013 1:02:44 PM UTC+2, AD7six wrote:
>
> Damn it a typo:
>
>
> The "$primary = false" query (an intermediary hasMany query result) looks like this:
>
>
> array(
> 	(int) 0 => array(
> 		'HasManyAssoc' => array(
> 			'id' => '1'
> 		)
> 	),
>
>         ...
> )
>
>
> (The same as all other query result formats).
>
> Please just look if in doubt - It's so much faster/easier.
>
> AD
>
> On Friday, 28 June 2013 12:59:57 UTC+2, AD7six wrote:
>>
>>
>>
>> On Thursday, 27 June 2013 22:25:02 UTC+2, Vanja Dizdarević wrote:
>>>
>>> As "solved" in the thread I linked to in the original post: 
>>
>>
>>>          public function afterFind($results, $primary = false) { 
>>>                 if (method_exists($this, 'doAfterFind')) { 
>>>                           if ($primary) { 
>>>                                    foreach ($results as $key => $val) { 
>>>                                             if 
>>> (isset($val[$this->alias])) { 
>>>                                              
>>>         $results[$key][$this->alias] = 
>>> $this->doAfterFind($results[$key][$this->alias]); 
>>>                                                 } 
>>>                                       } 
>>>                           } else { 
>>>                                   if 
>>> (isset($results[$this->primaryKey])) { 
>>>                                            $results = 
>>> $this->doAfterFind($results); 
>>>                                    } else { 
>>>                                             foreach ($results as $key => 
>>> $val) { 
>>>                                                      if 
>>> (isset($val[$this->alias])) { 
>>>                                                               if 
>>> (isset($val[$this->alias][$this->primaryKey])) { 
>>>                                                                
>>>         $results[$key][$this->alias] = 
>>> $this->doAfterFind($results[$key][$this->alias]); 
>>>                                                               } else { 
>>>                                                                
>>>         foreach ($results[$key][$this->alias] as $key2=> $val2) { 
>>>                                                                         
>>>         $results[$key][$this->alias][$key2] = 
>>> $this->doAfterFind($results[$key][$this->alias][$key2]); 
>>>                                                                          
>>>      } 
>>>                                                                     } 
>>>                                                           } 
>>>                                                 } 
>>>                                       } 
>>>                            } 
>>>                 } 
>>>                  return $results; 
>>>          } 
>>> }
>>>
>>
>> This code looks to be way over complex, possibly a testament to the 
>> none-value of reading 5 year old posts on a google group for a framework 
>> which is actively maintained and applying found advice blindly.
>>
>>
>>> This supposedly applies the same "doAfterFind" method to all records, 
>>> regardless of the passed $results array format, taking into account all 
>>> possible associations of a primary model to this model.
>>>
>>> The actual questions is: What are all array formats we can expect in the 
>>> $results array?
>>>
>>
>> Does that mean you still haven't looked =)?
>>
>> a count looks like this:
>>
>> array(
>> 	(int) 0 => array(
>> 		(int) 0 => array(
>> 			'count' => '9'
>> 		)
>> 	)
>> )
>>
>>
>> a find first looks like this:
>>
>>
>> array(
>> 	(int) 0 => array(
>> 		'Alias' => array(
>> 			'id' => '1'
>> 		),
>> 		'HasManyAssoc' => array(
>> 			(int) 0 => array(
>> 				'id' => '1'
>> 			)
>> 		)
>> 	)
>> )
>>
>>
>> a find all looks like this:
>>
>> array(
>>
>> 	(int) 0 => array(
>> 		'Alias' => array(
>> 			'id' => '1'
>> 		),
>> 		'HasManyAssoc' => array(
>> 			(int) 0 => array(
>> 				'id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> The "$primary = false" query (an intermediary hasMany query result) looks like this:
>>
>>
>> array(
>> 	(int) 0 => array(
>> 		'HasManyAssoc' => array(
>> 			(int) 0 => array(
>> 				'id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> There's a very simple pattern there:
>>
>>
>> array($int => array('alias' => array('field' => $value)));
>>
>>
>> With a simple exception for hasMany associations, when included in the 
>> primary query's results, all primary finds *always *have the same 
>> results format.
>>
>>
>>
>>> To quote the docs:
>>>  If a model is queried as an association the format of$results can 
>>> differ; instead of the result you would normally get from a find operation, 
>>> you may get this:
>>>
>>> $results = array(
>>>     'field_1' => 'value1',
>>>     'field_2' => 'value2');
>>>
>>>  
>>
>>> So, if I wish the afterFind to find the data in the results array, I 
>>> have to test the format of the array or can I rely on $primary value?
>>>
>>
>> I .. think you should stop wasting your time and *ask* how to do 
>> something specifically, from the look of your afterFind method, you're 
>> writing some sort of appmodel method that is converting/processing all 
>> data. Right now it's going to run on all queries, loop on all keys and 
>> therefore probably affect performance even if it's doing what you want it 
>> to do. You're probably better of writing either a recursive method to 
>> operate on the whole results format or a much narrower scope method that 
>> *just* does what you specifically want.
>>
>> *What is your afterFind method trying to do?*
>> *
>> *
>> AD
>>
>
On Friday, June 28, 2013 1:02:44 PM UTC+2, AD7six wrote:
>
> Damn it a typo:
>
>
> The "$primary = false" query (an intermediary hasMany query result) looks like this:
>
>
> array(
> 	(int) 0 => array(
> 		'HasManyAssoc' => array(
> 			'id' => '1'
> 		)
> 	),
>
>         ...
> )
>
>
> (The same as all other query result formats).
>
> Please just look if in doubt - It's so much faster/easier.
>
> AD
>
> On Friday, 28 June 2013 12:59:57 UTC+2, AD7six wrote:
>>
>>
>>
>> On Thursday, 27 June 2013 22:25:02 UTC+2, Vanja Dizdarević wrote:
>>>
>>> As "solved" in the thread I linked to in the original post: 
>>
>>
>>>          public function afterFind($results, $primary = false) { 
>>>                 if (method_exists($this, 'doAfterFind')) { 
>>>                           if ($primary) { 
>>>                                    foreach ($results as $key => $val) { 
>>>                                             if 
>>> (isset($val[$this->alias])) { 
>>>                                              
>>>         $results[$key][$this->alias] = 
>>> $this->doAfterFind($results[$key][$this->alias]); 
>>>                                                 } 
>>>                                       } 
>>>                           } else { 
>>>                                   if 
>>> (isset($results[$this->primaryKey])) { 
>>>                                            $results = 
>>> $this->doAfterFind($results); 
>>>                                    } else { 
>>>                                             foreach ($results as $key => 
>>> $val) { 
>>>                                                      if 
>>> (isset($val[$this->alias])) { 
>>>                                                               if 
>>> (isset($val[$this->alias][$this->primaryKey])) { 
>>>                                                                
>>>         $results[$key][$this->alias] = 
>>> $this->doAfterFind($results[$key][$this->alias]); 
>>>                                                               } else { 
>>>                                                                
>>>         foreach ($results[$key][$this->alias] as $key2=> $val2) { 
>>>                                                                         
>>>         $results[$key][$this->alias][$key2] = 
>>> $this->doAfterFind($results[$key][$this->alias][$key2]); 
>>>                                                                          
>>>      } 
>>>                                                                     } 
>>>                                                           } 
>>>                                                 } 
>>>                                       } 
>>>                            } 
>>>                 } 
>>>                  return $results; 
>>>          } 
>>> }
>>>
>>
>> This code looks to be way over complex, possibly a testament to the 
>> none-value of reading 5 year old posts on a google group for a framework 
>> which is actively maintained and applying found advice blindly.
>>
>>
>>> This supposedly applies the same "doAfterFind" method to all records, 
>>> regardless of the passed $results array format, taking into account all 
>>> possible associations of a primary model to this model.
>>>
>>> The actual questions is: What are all array formats we can expect in the 
>>> $results array?
>>>
>>
>> Does that mean you still haven't looked =)?
>>
>> a count looks like this:
>>
>> array(
>> 	(int) 0 => array(
>> 		(int) 0 => array(
>> 			'count' => '9'
>> 		)
>> 	)
>> )
>>
>>
>> a find first looks like this:
>>
>>
>> array(
>> 	(int) 0 => array(
>> 		'Alias' => array(
>> 			'id' => '1'
>> 		),
>> 		'HasManyAssoc' => array(
>> 			(int) 0 => array(
>> 				'id' => '1'
>> 			)
>> 		)
>> 	)
>> )
>>
>>
>> a find all looks like this:
>>
>> array(
>>
>> 	(int) 0 => array(
>> 		'Alias' => array(
>> 			'id' => '1'
>> 		),
>> 		'HasManyAssoc' => array(
>> 			(int) 0 => array(
>> 				'id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> The "$primary = false" query (an intermediary hasMany query result) looks like this:
>>
>>
>> array(
>> 	(int) 0 => array(
>> 		'HasManyAssoc' => array(
>> 			(int) 0 => array(
>> 				'id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> There's a very simple pattern there:
>>
>>
>> array($int => array('alias' => array('field' => $value)));
>>
>>
>> With a simple exception for hasMany associations, when included in the 
>> primary query's results, all primary finds *always *have the same 
>> results format.
>>
>>
>>
>>> To quote the docs:
>>>  If a model is queried as an association the format of$results can 
>>> differ; instead of the result you would normally get from a find operation, 
>>> you may get this:
>>>
>>> $results = array(
>>>     'field_1' => 'value1',
>>>     'field_2' => 'value2');
>>>
>>>  
>>
>>> So, if I wish the afterFind to find the data in the results array, I 
>>> have to test the format of the array or can I rely on $primary value?
>>>
>>
>> I .. think you should stop wasting your time and *ask* how to do 
>> something specifically, from the look of your afterFind method, you're 
>> writing some sort of appmodel method that is converting/processing all 
>> data. Right now it's going to run on all queries, loop on all keys and 
>> therefore probably affect performance even if it's doing what you want it 
>> to do. You're probably better of writing either a recursive method to 
>> operate on the whole results format or a much narrower scope method that 
>> *just* does what you specifically want.
>>
>> *What is your afterFind method trying to do?*
>> *
>> *
>> AD
>>
>
On Friday, June 28, 2013 1:02:44 PM UTC+2, AD7six wrote:
>
> Damn it a typo:
>
>
> The "$primary = false" query (an intermediary hasMany query result) looks like this:
>
>
> array(
> 	(int) 0 => array(
> 		'HasManyAssoc' => array(
> 			'id' => '1'
> 		)
> 	),
>
>         ...
> )
>
>
> (The same as all other query result formats).
>
> Please just look if in doubt - It's so much faster/easier.
>
> AD
>
> On Friday, 28 June 2013 12:59:57 UTC+2, AD7six wrote:
>>
>>
>>
>> On Thursday, 27 June 2013 22:25:02 UTC+2, Vanja Dizdarević wrote:
>>>
>>> As "solved" in the thread I linked to in the original post: 
>>
>>
>>>          public function afterFind($results, $primary = false) { 
>>>                 if (method_exists($this, 'doAfterFind')) { 
>>>                           if ($primary) { 
>>>                                    foreach ($results as $key => $val) { 
>>>                                             if 
>>> (isset($val[$this->alias])) { 
>>>                                              
>>>         $results[$key][$this->alias] = 
>>> $this->doAfterFind($results[$key][$this->alias]); 
>>>                                                 } 
>>>                                       } 
>>>                           } else { 
>>>                                   if 
>>> (isset($results[$this->primaryKey])) { 
>>>                                            $results = 
>>> $this->doAfterFind($results); 
>>>                                    } else { 
>>>                                             foreach ($results as $key => 
>>> $val) { 
>>>                                                      if 
>>> (isset($val[$this->alias])) { 
>>>                                                               if 
>>> (isset($val[$this->alias][$this->primaryKey])) { 
>>>                                                                
>>>         $results[$key][$this->alias] = 
>>> $this->doAfterFind($results[$key][$this->alias]); 
>>>                                                               } else { 
>>>                                                                
>>>         foreach ($results[$key][$this->alias] as $key2=> $val2) { 
>>>                                                                         
>>>         $results[$key][$this->alias][$key2] = 
>>> $this->doAfterFind($results[$key][$this->alias][$key2]); 
>>>                                                                          
>>>      } 
>>>                                                                     } 
>>>                                                           } 
>>>                                                 } 
>>>                                       } 
>>>                            } 
>>>                 } 
>>>                  return $results; 
>>>          } 
>>> }
>>>
>>
>> This code looks to be way over complex, possibly a testament to the 
>> none-value of reading 5 year old posts on a google group for a framework 
>> which is actively maintained and applying found advice blindly.
>>
>>
>>> This supposedly applies the same "doAfterFind" method to all records, 
>>> regardless of the passed $results array format, taking into account all 
>>> possible associations of a primary model to this model.
>>>
>>> The actual questions is: What are all array formats we can expect in the 
>>> $results array?
>>>
>>
>> Does that mean you still haven't looked =)?
>>
>> a count looks like this:
>>
>> array(
>> 	(int) 0 => array(
>> 		(int) 0 => array(
>> 			'count' => '9'
>> 		)
>> 	)
>> )
>>
>>
>> a find first looks like this:
>>
>>
>> array(
>> 	(int) 0 => array(
>> 		'Alias' => array(
>> 			'id' => '1'
>> 		),
>> 		'HasManyAssoc' => array(
>> 			(int) 0 => array(
>> 				'id' => '1'
>> 			)
>> 		)
>> 	)
>> )
>>
>>
>> a find all looks like this:
>>
>> array(
>>
>> 	(int) 0 => array(
>> 		'Alias' => array(
>> 			'id' => '1'
>> 		),
>> 		'HasManyAssoc' => array(
>> 			(int) 0 => array(
>> 				'id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> The "$primary = false" query (an intermediary hasMany query result) looks like this:
>>
>>
>> array(
>> 	(int) 0 => array(
>> 		'HasManyAssoc' => array(
>> 			(int) 0 => array(
>> 				'id' => '1'
>> 			)
>> 		)
>> 	),
>>
>>         ...
>> )
>>
>>
>> There's a very simple pattern there:
>>
>>
>> array($int => array('alias' => array('field' => $value)));
>>
>>
>> With a simple exception for hasMany associations, when included in the 
>> primary query's results, all primary finds *always *have the same 
>> results format.
>>
>>
>>
>>> To quote the docs:
>>>  If a model is queried as an association the format of$results can 
>>> differ; instead of the result you would normally get from a find operation, 
>>> you may get this:
>>>
>>> $results = array(
>>>     'field_1' => 'value1',
>>>     'field_2' => 'value2');
>>>
>>>  
>>
>>> So, if I wish the afterFind to find the data in the results array, I 
>>> have to test the format of the array or can I rely on $primary value?
>>>
>>
>> I .. think you should stop wasting your time and *ask* how to do 
>> something specifically, from the look of your afterFind method, you're 
>> writing some sort of appmodel method that is converting/processing all 
>> data. Right now it's going to run on all queries, loop on all keys and 
>> therefore probably affect performance even if it's doing what you want it 
>> to do. You're probably better of writing either a recursive method to 
>> operate on the whole results format or a much narrower scope method that 
>> *just* does what you specifically want.
>>
>> *What is your afterFind method trying to do?*
>> *
>> *
>> 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>