Edición de «Como ejecutar sentencia JOIN en un find() en KumbiaPHP Framework»
De KumbiaPHP Framework Wiki
Advertencia: no has iniciado sesión. Tu dirección IP se hará pública si haces cualquier edición. Si inicias sesión o creas una cuenta, tus ediciones se atribuirán a tu nombre de usuario, además de otros beneficios.
Puedes deshacer la edición. Antes de deshacer la edición, comprueba la siguiente comparación para verificar que realmente es lo que quieres hacer, y entonces guarda los cambios para así efectuar la reversión.
Revisión actual | Tu texto | ||
Línea 1: | Línea 1: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
La sentencia JOIN en SQL permite combinar registros de dos o más tablas en una base de datos relacional. En el Lenguaje de Consultas Estructurado (SQL), hay tres tipo de JOIN: interno, externo, y cruzado. | La sentencia JOIN en SQL permite combinar registros de dos o más tablas en una base de datos relacional. En el Lenguaje de Consultas Estructurado (SQL), hay tres tipo de JOIN: interno, externo, y cruzado. | ||
Línea 10: | Línea 4: | ||
== Creamos Nuestras tablas y le agregamos registros == | == Creamos Nuestras tablas y le agregamos registros == | ||
− | < | + | <pre> |
CREATE TABLE username( | CREATE TABLE username( | ||
id int(11) NOT NULL AUTO_INCREMENT, | id int(11) NOT NULL AUTO_INCREMENT, | ||
Línea 39: | Línea 33: | ||
(2, 'Carlos Beltran', 'Presidencia'), | (2, 'Carlos Beltran', 'Presidencia'), | ||
(3, 'Luis Marcano', 'Auditoria'); | (3, 'Luis Marcano', 'Auditoria'); | ||
− | </ | + | </pre> |
== Creando nuestros Modelos == | == Creando nuestros Modelos == | ||
Línea 46: | Línea 40: | ||
<source lang="php" line> | <source lang="php" line> | ||
<?php | <?php | ||
− | class Username extends ActiveRecord | + | |
− | + | class Username extends ActiveRecord{ | |
+ | |||
} | } | ||
+ | ?> | ||
</source> | </source> | ||
'''''[app]/models/usuario.php:''''' | '''''[app]/models/usuario.php:''''' | ||
<source lang="php" line> | <source lang="php" line> | ||
<?php | <?php | ||
− | class Usuario extends ActiveRecord | + | |
− | + | class Usuario extends ActiveRecord{ | |
+ | |||
public function getInnerJoin(){ | public function getInnerJoin(){ | ||
return $this->find('columns: usuario.id, nombres, departamento, username', | return $this->find('columns: usuario.id, nombres, departamento, username', | ||
Línea 69: | Línea 66: | ||
'join: right outer join username on usuario.id = username.usuario_id'); | 'join: right outer join username on usuario.id = username.usuario_id'); | ||
} | } | ||
+ | |||
} | } | ||
?> | ?> | ||
</source> | </source> | ||
− | + | Aqui mostramos los distintos metodos como podemos utilizar el find, para relacionar dos o mas tablas tablas en una consulta. | |
== Creamos nuestro Controller == | == Creamos nuestro Controller == | ||
Línea 81: | Línea 79: | ||
<?php | <?php | ||
− | class UsuarioController extends | + | class UsuarioController extends ApplicationController{ |
public function index(){ | public function index(){ | ||
− | + | ||
− | + | $this->inner = $this->Usuario->getInnerJoin(); | |
− | + | $this->left = $this->Usuario->getleftJoin(); | |
− | + | $this->right = $this->Usuario->getrightJoin(); | |
} | } | ||
} | } | ||
Línea 106: | Línea 104: | ||
</tr> | </tr> | ||
<?php foreach($inner As $i): ?> | <?php foreach($inner As $i): ?> | ||
− | + | <? echo tr_color('#ff0000', '#fff')?> | |
− | + | <td><?php echo $i->username ?></td> | |
− | + | <td><?php echo $i->nombres ?></td> | |
− | + | <td><?php echo $i->departamento ?></td> | |
− | |||
<?php endforeach; ?> | <?php endforeach; ?> | ||
</table> | </table> | ||
Línea 122: | Línea 119: | ||
</tr> | </tr> | ||
<?php foreach($left As $i): ?> | <?php foreach($left As $i): ?> | ||
− | + | <? echo tr_color('#ff0000', '#fff')?> | |
− | + | <td><?php echo $i->username ?></td> | |
− | + | <td><?php echo $i->nombres ?></td> | |
− | + | <td><?php echo $i->departamento ?></td> | |
− | |||
<?php endforeach; ?> | <?php endforeach; ?> | ||
</table> | </table> | ||
Línea 138: | Línea 134: | ||
</tr> | </tr> | ||
<?php foreach($right As $i): ?> | <?php foreach($right As $i): ?> | ||
− | + | <? echo tr_color('#ff0000', '#fff')?> | |
− | + | <td><?php echo $i->username ?></td> | |
− | + | <td><?php echo $i->nombres ?></td> | |
− | + | <td><?php echo $i->departamento ?></td> | |
− | |||
<?php endforeach; ?> | <?php endforeach; ?> | ||
</table> | </table> | ||
Línea 149: | Línea 144: | ||
== Screenshots == | == Screenshots == | ||
− | [[Archivo: | + | [[Archivo:screenshots.jpg]] |
− | |||
− | |||
− |