Relacionamento entre tabelas Boa tarde, Por favor, como fazer o relacionamento entre duas tabelas. Por exemplo: buscar a cidade do cliente em outra tabela cidade, Segue, anexo, imagem do fornulário. Veja o código que estou utilizando: ...
ST
Relacionamento entre tabelas  
Boa tarde,
Por favor, como fazer o relacionamento entre duas tabelas.
Por exemplo: buscar a cidade do cliente em outra tabela cidade,

Segue, anexo, imagem do fornulário.

Veja o código que estou utilizando:

<?php/** * BookList Listing * * @version    1.0 * @package    samples * @subpackage library * @author     Pablo Dall'Oglio * @copyright  Copyright (c) 2006-2011 Adianti Solutions Ltd. (http://www.adianti.com.br) * @license    http://www.adianti.com.br/framework-license */class ClienteList extends TStandardList{    protected $form;     // registration form    protected $datagrid; // listing    protected $pageNavigation;    protected $loaded;        /**     * Class constructor     * Creates the page, the form and the listing     */    public function __construct()    {        parent::__construct();                // defines the database        parent::setDatabase('teste');                // defines the active record        parent::setActiveRecord('cliente');                // defines the filter field        parent::addFilterField('cliente_id', 'like', 'cliente_id');        parent::addFilterField('nomecliente', '=', 'nomecliente');        parent::addFilterField('cidade_id', '=', 'cidade_id');                // creates the form        $this->form = new BootstrapFormBuilder('form_search_Cliente');        $this->form->setFormTitle('');                // create the form fields        $cliente_id                = new TEntry('cliente_id');        $title             = new TEntry('nomecliente');        $cidade_id         = new 
">TDBSeekButton('cidade_id', 'teste', $this->form->getName(), 'Cidade', 'nomecidade', 'cidade_id', 'nomecidade');        $nomecidade       = new TEntry('cidades->nomecidade');                $nomecidade->setEditable(FALSE);        $cliente_id->setSize('10%');        $title->setSize('100%');        $cidade_id->setSize('10%');        $nomecidade->setSize('80%');            $this->form->addFields( [ new TLabel(_t('Code')) ], [ $cliente_id ] );        $this->form->addFields( [ new TLabel(_t('Name')) ], [ $title ] );        $this->form->addFields( [ new TLabel(_t('City')) ], [ $cidade_id, $nomecidade ] );                     $this->form->addAction(_t('Find'), new TAction(array($this, 'onSearch')), 'fa:search');        $this->form->addAction(_t('New'),  new TAction(array('ClienteForm', 'onClear')), 'fa:plus-square green');        $this->form->setData(TSession::getValue('Book_filter_data'));                // creates a DataGrid        $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);        $this->datagrid->style = 'width: 100%';        $this->datagrid->datatable = 'true';                // creates the datagrid columns                $id           = new TDataGridColumn('cliente_id','Código', 'right', 100);        $title        = new TDataGridColumn('nomecliente','Nome', 'left',200 );        $nomecidade   = new TDataGridColumn('nomecidade','Cidade','left', 190);             // creates the datagrid actions        $order1 = new TAction(array($this, 'onReload'));        $order2 = new TAction(array($this, 'onReload'));        // define the ordering parameters        $order1->setParameter('order', 'cliente_id');        $order2->setParameter('order', 'nomecliente');        // assign the ordering actions        $id->setAction($order1);        $title->setAction($order2);                // add the columns to the DataGrid        $this->datagrid->addColumn($id);        $this->datagrid->addColumn($title);        $this->datagrid->addColumn($nomecidade);                // creates two datagrid actions        $action1 = new TDataGridAction(array('ClienteForm', 'onEdit'));        $action1->setLabel(_t('Edit'));        $action1->setImage('fa:pencil-square-o blue fa-lg');        $action1->setField('cliente_id');                $action2 = new TDataGridAction(array($this, 'onDelete'));        $action2->setLabel(_t('Delete'));        $action2->setImage('fa:trash-o red fa-lg');        $action2->setField('cliente_id');                // add the actions to the datagrid        $this->datagrid->addAction($action1);        $this->datagrid->addAction($action2);                // create the datagrid model        $this->datagrid->createModel();                // creates the page navigation        $this->pageNavigation = new TPageNavigation;        $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));        $this->pageNavigation->setWidth($this->datagrid->getWidth());                // creates the page structure using a vbox        $container = new TVBox;        $container->style = 'width: 100%';        $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));        $container->add($this->form);        $container->add(TPanelGroup::pack('', $this->datagrid));        $container->add($this->pageNavigation);                // add the vbox inside the page        parent::add($container);    }}

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (3)


MG

O relacionamento é feito no "model".
Vc usa o Adianti Pró?
Através dele, vc faz o relacionando no Model Cliente, apontando para o Model Cidade.
ST

Bom dia,
Utilizo o Adianti Pro mas não estou conseguindo listar os dados no dbgrid.
MG

Posta os models: Cliente e Cidade para podermos ajudar!