Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Problema ao carregar dados em datagrid de um form mestre/detalhe Boa tarde a todos, Estou com um problema ao carregar os dados em um datagrid de um formulário mestre/detalhe para edição de cadastros. O formulário mestre carrega os dados normalmente, a dificuldade está em carregar os dados no datagrid do formulário de detalhe. Alguém poderia me ajudar? Desde já agradeço a atenção. Segue código: FORMULÁRIO MESTRE DETALHE: ...
ET
Problema ao carregar dados em datagrid de um form mestre/detalhe  
Boa tarde a todos,
Estou com um problema ao carregar os dados em um datagrid de um formulário mestre/detalhe para edição de cadastros.
O formulário mestre carrega os dados normalmente, a dificuldade está em carregar os dados no datagrid do formulário de detalhe.

Alguém poderia me ajudar? Desde já agradeço a atenção.

Segue código:

FORMULÁRIO MESTRE DETALHE:
  1. <?php
  2. /**
  3.  * ClienteForm Form
  4.  * @author  <your name here>
  5.  */
  6. class ClienteForm extends TPage
  7. {
  8.     protected $form// form
  9.     
  10.     use adianti\base\AdiantiMasterDetailTrait;
  11.     
  12.     /**
  13.      * Form constructor
  14.      * @param $param Request
  15.      */
  16.     public function __construct$param )
  17.     {
  18.         parent::__construct();
  19.         
  20.         $this->form = new BootstrapFormBuilder('list_Cliente');
  21.         $this->form->setFormTitle('Cliente');
  22.         // master fields
  23.         $id = new TEntry('id');
  24.         $codigo_cliente = new TEntry('codigo_cliente');
  25.         $data_cadastro = new TDate('data_cadastro');
  26.         $nome = new TEntry('nome');
  27.         $sexo_id = new TDBCombo('sexo_id''microerp''Sexo''id''{sexo}','id asc');
  28.         $rg = new TEntry('rg');
  29.         $orgao_expeditor = new TEntry('orgao_expeditor');
  30.         $cpf = new TEntry('cpf');
  31.         $profissao = new TEntry('profissao');
  32.         $religiao = new TEntry('religiao');
  33.         $estado_civil = new TEntry('estado_civil');
  34.         $data_nascimento = new TDate('data_nascimento');
  35.         $idade = new TEntry('idade');
  36.         $data_falecimento = new TDate('data_falecimento');
  37.         $telefone_um = new TEntry('telefone_um');
  38.         $telefone_dois = new TEntry('telefone_dois');
  39.         $celular = new TEntry('celular');
  40.         $uf_id = new TDBUniqueSearch('uf_id''microerp''Cidade''id''uf','id asc'  );
  41.         $cidade_id = new TDBUniqueSearch('cidade_id''microerp''Cidade''id''nome','id asc'  );
  42.         $area_id = new TDBCombo('area_id''microerp''Area''id''{area}','id asc');
  43.         $bairro_id = new TDBUniqueSearch('bairro_id''microerp''Cidade''id''bairro','id asc'  );
  44.         $numero = new TEntry('numero'); 
  45.         $cep = new TEntry('cep');
  46.         $referencia = new TEntry('referencia');
  47.         $complemento = new TEntry('complemento');
  48.         $data_admissao = new TDate('data_admissao');
  49.         $data_carencia = new TDate('data_carencia');
  50.         $primeiro_vencimento = new TDate('primeiro_vencimento');
  51.         // detail fields
  52.         $dependente_nome = new TEntry('dependente_nome');
  53.         $dependente_data_admissao = new TDate('dependente_data_admissao');
  54.         $dependente_data_carencia = new TDate('dependente_data_carencia');
  55.         $status_dependente_id = new TDBCombo('status_dependente_id''microerp''StatusDependente''id''{status_dependente}','id asc');
  56.         $dependente_id = new THidden('dependente_id');
  57.         $nome->addValidation('Nome', new TRequiredValidator()); 
  58.         $sexo_id->addValidation('Sexo', new TRequiredValidator()); 
  59.         $rg->addValidation('RG', new TRequiredValidator()); 
  60.         $cpf->addValidation('CPF', new TRequiredValidator()); 
  61.         $idade->addValidation('Idade', new TRequiredValidator()); 
  62.         $uf_id->addValidation('UF', new TRequiredValidator()); 
  63.         $cidade_id->addValidation('Cidade', new TRequiredValidator()); 
  64.         $area_id->addValidation('Area', new TRequiredValidator()); 
  65.         $bairro_id->addValidation('Bairro', new TRequiredValidator()); 
  66.         $cep->addValidation('CEP', new TRequiredValidator());  
  67.         $uf_id->setMinLength(1);
  68.         $cidade_id->setMinLength(2);
  69.         $bairro_id->setMinLength(2);
  70.         $cpf->setMaxLength(14);
  71.         $rg->setMaxLength(20);
  72.         $cep->setMaxLength(9);
  73.         $telefone_um->setMaxLength(11);
  74.         $telefone_dois->setMaxLength(11);
  75.         $celular->setMaxLength(11);
  76.         $numero->setMaxLength(4);
  77.         $data_cadastro->setDatabaseMask('yyyy-mm-dd');
  78.         $data_nascimento->setDatabaseMask('yyyy-mm-dd');
  79.         $data_falecimento->setDatabaseMask('yyyy-mm-dd');
  80.         $data_admissao->setDatabaseMask('yyyy-mm-dd');
  81.         $data_carencia->setDatabaseMask('yyyy-mm-dd');
  82.         $primeiro_vencimento->setDatabaseMask('yyyy-mm-dd');
  83.         $data_cadastro->setMask('dd/mm/yyyy');
  84.         $data_nascimento->setMask('dd/mm/yyyy');
  85.         $data_falecimento->setMask('dd/mm/yyyy');
  86.         $data_admissao->setMask('dd/mm/yyyy');
  87.         $data_carencia->setMask('dd/mm/yyyy');
  88.         $primeiro_vencimento->setMask('dd/mm/yyyy');
  89.         $dependente_data_admissao->setDatabaseMask('yyyy-mm-dd');
  90.         $dependente_data_carencia->setDatabaseMask('yyyy-mm-dd');
  91.         $dependente_data_admissao->setMask('dd/mm/yyyy');
  92.         $dependente_data_carencia->setMask('dd/mm/yyyy');
  93.         $id->setEditable(false);
  94.         $id->setSize(100);
  95.         $codigo_cliente->setSize('72%');
  96.         $data_cadastro->setSize('72%');
  97.         $nome->setSize('72%');
  98.         $sexo_id->setSize('10%');
  99.         $rg->setSize('72%');
  100.         $orgao_expeditor->setSize('70%');
  101.         $cpf->setSize('72%');
  102.         $profissao->setSize('70%');
  103.         $religiao->setSize('72%');
  104.         $estado_civil->setSize('70%');
  105.         $data_nascimento->setSize('70%');
  106.         $idade->setSize('70%');
  107.         $data_falecimento->setSize('70%');
  108.         $telefone_um->setSize('70%');
  109.         $telefone_dois->setSize('70%');
  110.         $celular->setSize('70%');
  111.         $uf_id->setSize('70%');
  112.         $cidade_id->setSize('72%');
  113.         $area_id->setSize('72%');
  114.         $bairro_id->setSize('72%');
  115.         $numero->setSize('70%');
  116.         $complemento->setSize('70%');
  117.         $cep->setSize('70%');
  118.         $referencia->setSize('70%');
  119.         $data_admissao->setSize('70%');
  120.         $data_carencia->setSize('70%');
  121.         $primeiro_vencimento->setSize('70%');
  122.         $id->setEditable(FALSE);
  123.         $status_dependente_id->setSize(100);
  124.         $dependente_nome->setSize('70%');
  125.         $dependente_data_admissao->setSize('70%');
  126.         $dependente_data_carencia->setSize('70%');
  127.         $status_dependente_id->setSize('70%');
  128.         
  129.         // master fields
  130.         $this->form->addFields([new TLabel('Id:')],[$id]);
  131.         $this->form->addFields([new TLabel('Codigo Cliente:')],[$codigo_cliente], [new TLabel('Data Cadastro:')],[$data_cadastro]);
  132.         $this->form->addFields([new TLabel('Nome:''#ff0000')],[$nome], [new TLabel('Sexo:''#ff0000')],[$sexo_id]);
  133.         $this->form->addFields([new TLabel('RG:''#ff0000')],[$rg], [new TLabel('Orgão Expeditor:')],[$orgao_expeditor]);
  134.         $this->form->addFields([new TLabel('CPF:''#ff0000')],[$cpf], [new TLabel('Profissão:')],[$profissao]);
  135.         $this->form->addFields([new TLabel('Religião:')],[$religiao], [new TLabel('Estado Civil:')],[$estado_civil]);
  136.         $this->form->addFields([new TLabel('Data Nascimento:')],[$data_nascimento], [new TLabel('Idade:''#ff0000')],[$idade], [new TLabel('Data Falecimento:')],[$data_falecimento]);
  137.         $this->form->addFields([new TLabel('Telefone 1:')],[$telefone_um], [new TLabel('Telefone 2:')],[$telefone_dois], [new TLabel('Celular:')],[$celular]);
  138.         $this->form->addFields([new TLabel('UF:''#ff0000')],[$uf_id], [new TLabel('Cidade:''#ff0000')],[$cidade_id], [new TLabel('Área:''#ff0000')],[$area_id]);
  139.         $this->form->addFields([new TLabel('Bairro:''#ff0000')],[$bairro_id], [new TLabel('Número:')],[$numero], [new TLabel('CEP:''#ff0000')],[$cep]);
  140.         $this->form->addFields([new TLabel('Complemento:')],[$complemento], [new TLabel('Referência:')],[$referencia]);
  141.         $this->form->addFields([new TLabel('Data Admissão:')],[$data_admissao], [new TLabel('Data Carência:')],[$data_carencia], [new TLabel('Primeiro Vencimento:')],[$primeiro_vencimento]);
  142.         
  143.         // detail fields
  144.         $this->form->addContent([new TFormSeparator('Dependentes''#333333''18''#eeeeee')]);
  145.         //$this->form->addFields([new TLabel('Id:')],[$id]);
  146.         $this->form->addFields([new TLabel('Nome:')],[$dependente_nome]);
  147.         $this->form->addFields([new TLabel('Data Admissão:')],[$dependente_data_admissao], [new TLabel('Data Carência:')],[$dependente_data_carencia]);
  148.         $this->form->addFields([new TLabel('Status do Dependente:')],[$status_dependente_id]);
  149.         $this->form->addFields([$dependente_id]);
  150.         // add button
  151.         $add_dependente = new TButton('add_dependente');
  152.         $add_dependente->setAction(new TAction(array($this'onAddDependente')), 'Adicionar');
  153.         $add_dependente->setImage('fa:plus #51c249');
  154.         $this->form->addFields([$add_dependente]);
  155.         
  156.         // detail datagrid
  157.         $this->item_dependente_list = new BootstrapDatagridWrapper(new TQuickGrid);
  158.         $this->item_dependente_list->style 'width:100%';
  159.         $this->item_dependente_list->class .= ' table-bordered';
  160.         $this->item_dependente_list->disableDefaultClick();
  161.         $this->item_dependente_list->addQuickColumn('''edit''left'50);
  162.         $this->item_dependente_list->addQuickColumn('''delete''left'50);
  163.         
  164.         $col_dependente_id        $this->item_dependente_list->addQuickColumn('Dependente''dependente_nome''left');
  165.         $col_data_admissao        $this->item_dependente_list->addQuickColumn('Data Admissão''dependente_data_admissao''left');
  166.         $col_data_carencia             $this->item_dependente_list->addQuickColumn('Data Carência''dependente_data_carencia''right');
  167.         $col_status_dependente             $this->item_dependente_list->addQuickColumn('Status Dependente''status_dependente_id''right'); 
  168.         
  169.         $this->item_dependente_list->createModel();
  170.         
  171.         $this->form->addContent([$this->item_dependente_list]);
  172.         
  173.         // create the form actions
  174.         $this->form->addAction('Salvar', new TAction([$this'onSave']), 'fa:floppy-o')->addStyleClass('btn-primary');
  175.         $this->form->addAction('Limpar formulário', new TAction([$this'onClear']), 'fa:eraser #dd5a43');
  176.         // vertical box container
  177.         $container = new TVBox;
  178.         $container->style 'width: 100%';
  179.         $container->class 'form-container';
  180.         $container->add(new TXMLBreadCrumb('menu.xml''ClienteList'));
  181.         $container->add($this->form);
  182.         
  183.         parent::add($container);
  184.     }
  185.     
  186.     /**
  187.      * Adiciona dependente ao cliente
  188.      * @param $param Request
  189.      */
  190.     public function onAddDependente$param )
  191.     {
  192.         try
  193.         {
  194.             $data $this->form->getData();
  195.             if(!$data->dependente_nome)
  196.             {
  197.                 throw new Exception(AdiantiCoreTranslator::translate('The field ^1 is required''Dependente'));
  198.             }
  199.             
  200.             $item_dependente_items TSession::getValue('item_dependente_items');
  201.             $key = !empty($data->dependente_id) ? $data->dependente_id uniqid();
  202.             
  203.             $fields = []; 
  204.             $fields['dependente_nome'] = $data->dependente_nome;
  205.             $fields['dependente_data_admissao'] = $data->dependente_data_admissao;
  206.             $fields['dependente_data_carencia']      = $data->dependente_data_carencia;
  207.             $fields['status_dependente_id']      = $data->status_dependente_id;
  208.             $item_dependente_items$key ]        = $fields;
  209.             
  210.             TSession::setValue('item_dependente_items'$item_dependente_items);
  211.             // limpa os campos do item do dependente
  212.             $data->dependente_nome '';
  213.             $data->dependente_data_admissao '';
  214.             $data->dependente_data_carencia '';
  215.             $data->status_dependente_id '';
  216.             $data->dependente_id '';
  217.             
  218.             $this->form->setData($data);
  219.             $this->onReload$param );
  220.         }
  221.         catch (Exception $e)
  222.         {
  223.             $this->form->setData$this->form->getData());
  224.             new TMessage('error'$e->getMessage());
  225.         }
  226.     }
  227.     /**
  228.      * Recarrega tudo
  229.      * @param $param Request
  230.      */
  231.     public function onReload($params null)
  232.     {
  233.         $this->loaded TRUE;
  234.         $this->onReloadDependenteItemDependente($params);
  235.     }
  236.     
  237.     /**
  238.      * Recarrega itens do dependente
  239.      * @param $param Request
  240.      */
  241.     public function onReloadDependenteItemDependente$param )
  242.     {
  243.         $items TSession::getValue('item_dependente_items'); 
  244.         $this->item_dependente_list->clear(); 
  245.         if($items
  246.         { 
  247.             $cont 1
  248.             foreach ($items as $key => $item
  249.             {
  250.                 $rowItem = new StdClass;
  251.                 $action_del = new TAction(array($this'onDeleteItemDependente')); 
  252.                 $action_del->setParameter('item_dependente_id_row_id'$key);   
  253.                 $action_edi = new TAction(array($this'onEditItemDependente'));  
  254.                 $action_edi->setParameter('item_dependente_id_row_id'$key);  
  255.                 $button_del = new TButton('delete_item_dependente'.$cont);
  256.                 $button_del->class 'btn btn-default btn-sm';
  257.                 $button_del->setAction($action_del'');
  258.                 $button_del->setImage('fa:trash-o'); 
  259.                 $button_del->setFormName($this->form->getName());
  260.                 $button_edi = new TButton('edit_item_dependente'.$cont);
  261.                 $button_edi->class 'btn btn-default btn-sm';
  262.                 $button_edi->setAction($action_edi'');
  263.                 $button_edi->setImage('bs:edit');
  264.                 $button_edi->setFormName($this->form->getName());
  265.                 $rowItem->edit   $button_edi;
  266.                 $rowItem->delete $button_del;
  267.                 
  268.                 $rowItem->status_dependente_id '';
  269.                 
  270.                 if (isset($item['status_dependente_id']) && $item['status_dependente_id'])
  271.                 {
  272.                     TTransaction::open('microerp');
  273.                     $statusdependente StatusDependente::find($item['status_dependente_id']);
  274.                     $rowItem->status_dependente_id $statusdependente->render('{status_dependente}');
  275.                     TTransaction::close();
  276.                 }
  277.                 
  278.                 $rowItem->dependente_nome = isset($item['dependente_nome']) ? $item['dependente_nome'] : '';
  279.                 $rowItem->dependente_data_admissao      = isset($item['dependente_data_admissao']) ? $item['dependente_data_admissao'] : '';
  280.                 $rowItem->dependente_data_carencia      = isset($item['dependente_data_carencia']) ? $item['dependente_data_carencia'] : '';
  281.                 $rowItem->status_dependente_id      = isset($item['status_dependente_id']) ? $item['status_dependente_id'] : '';
  282.                 $this->item_dependente_list->addItem($rowItem);
  283.                 $cont ++;
  284.             } 
  285.         } 
  286.     } 
  287.     
  288.     /**
  289.      * Edita item dependente
  290.      * @param $param Request
  291.      */
  292.     public function onEditItemDependente$param )
  293.     {
  294.         $data $this->form->getData();
  295.         // read session items
  296.         $items TSession::getValue('item_dependente_items');
  297.         // get the session item
  298.         $item $items[$param['item_dependente_id_row_id']];
  299.         $data->dependente_nome $item['dependente_nome'];
  300.         $data->dependente_data_admissao $item['dependente_data_admissao'];
  301.         $data->dependente_data_carencia      $item['dependente_data_carencia'];
  302.         $data->status_dependente_id      $item['status_dependente_id'];
  303.         $data->dependente_id         $param['item_dependente_id_row_id'];
  304.         
  305.         // fill product fields
  306.         $this->form->setData$data );
  307.         $this->onReload$param );
  308.     }
  309.     
  310.     /**
  311.      * Exclui item do pedido
  312.      * @param $param Request
  313.      */
  314.     public function onDeleteItemDependente$param )
  315.     {
  316.         $data $this->form->getData();
  317.         $data->dependente_nome '';
  318.         $data->dependente_data_admissao '';
  319.         $data->dependente_data_carencia      '';
  320.         $data->status_dependente_id      '';
  321.         $this->form->setData$data );
  322.         // read session items
  323.         $items TSession::getValue('item_dependente_items');
  324.         // delete the item from session
  325.         unset($items[$param['item_dependente_id_row_id']]);
  326.         TSession::setValue('item_dependente_items'$items);
  327.         
  328.         $this->onReload$param );
  329.     }
  330.     /**
  331.      * Limpa formulário
  332.      * @param $param Request
  333.      */
  334.     public function onClear$param )
  335.     {
  336.         $this->form->clear();
  337.         TSession::setValue('item_dependente_items'null);
  338.         $this->onReload();
  339.     }
  340.     
  341.     /**
  342.      * Salva registro
  343.      * @param $param Request
  344.      */
  345.     public function onSave($param null
  346.     {
  347.         try
  348.         {
  349.             TTransaction::open('microerp');
  350.             
  351.             $this->form->validate();
  352.             $data $this->form->getData();
  353.             
  354.             $object = new Cliente
  355.             $object->fromArray( (array) $data);
  356.             $object->store(); 
  357.             
  358.             $this->storeItems('Dependente''cliente_id'$object'item_dependente',
  359.                 function($masterObject$detailObject) { 
  360.             });
  361.             $object->store();
  362.             $data->id $object->id
  363.             $this->form->setData($data);
  364.             TTransaction::close();
  365.             
  366.             new TMessage('info'AdiantiCoreTranslator::translate('Record saved'));
  367.         }
  368.         catch (Exception $e)
  369.         {
  370.             new TMessage('error'$e->getMessage());
  371.             $this->form->setData$this->form->getData() );
  372.             TTransaction::rollback();
  373.         }
  374.     }
  375.     
  376.     /**
  377.      * Edita formulário
  378.      * @param $param Request
  379.      */
  380.     public function onEdit$param )
  381.     {
  382.         try
  383.         {
  384.             if (isset($param['key']))
  385.             {
  386.                 $key $param['key'];
  387.                 TTransaction::open('microerp');
  388.                 
  389.                 $object = new Cliente($key); 
  390.                 $this->loadItems('Dependente''cliente_id'$object'item_dependente');
  391.                  
  392.                 $this->form->setData($object); 
  393.                 $this->onReload();
  394.                 TTransaction::close(); 
  395.             }
  396.             else
  397.             {
  398.                 $this->form->clear();
  399.             }
  400.         }
  401.         catch (Exception $e)
  402.         {
  403.             new TMessage('error'$e->getMessage());
  404.             TTransaction::rollback();
  405.         }
  406.     }
  407.     
  408.     /**
  409.      * Exibe a página
  410.      * @param $param Request
  411.      */
  412.     public function show() 
  413.     { 
  414.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') ) 
  415.         { 
  416.             $this->onReloadfunc_get_arg(0) );
  417.         }
  418.         parent::show();
  419.     }
  420. }
  421. ?>


MODEL DA TABELA CLIENTE:
  1. <?php
  2. class Cliente extends TRecord
  3. {
  4.     const TABLENAME  'cliente';
  5.     const PRIMARYKEY 'id';
  6.     const IDPOLICY   'serial'// {max, serial}
  7.     
  8.     /**
  9.      * Constructor method
  10.      */
  11.     public function __construct($id NULL$callObjectLoad TRUE)
  12.     {
  13.         parent::__construct($id$callObjectLoad);
  14.         parent::addAttribute('codigo_cliente');
  15.         parent::addAttribute('data_cadastro');
  16.         parent::addAttribute('nome');
  17.         parent::addAttribute('sexo_id');
  18.         parent::addAttribute('rg');
  19.         parent::addAttribute('orgao_expeditor');
  20.         parent::addAttribute('cpf');
  21.         parent::addAttribute('profissao');
  22.         parent::addAttribute('religiao');
  23.         parent::addAttribute('estado_civil');
  24.         parent::addAttribute('data_nascimento');
  25.         parent::addAttribute('idade');
  26.         parent::addAttribute('data_falecimento');
  27.         parent::addAttribute('telefone_um');
  28.         parent::addAttribute('telefone_dois');
  29.         parent::addAttribute('celular');
  30.         parent::addAttribute('uf_id');
  31.         parent::addAttribute('cidade_id');
  32.         parent::addAttribute('bairro_id');
  33.         parent::addAttribute('numero');
  34.         parent::addAttribute('complemento');
  35.         parent::addAttribute('cep');
  36.         parent::addAttribute('referencia');
  37.         parent::addAttribute('data_admissao');
  38.         parent::addAttribute('data_carencia');
  39.         parent::addAttribute('primeiro_vencimento');
  40.         parent::addAttribute('area_id');
  41.     }
  42.    
  43.         /**
  44.      * Method set_status_dependente
  45.      * Sample of usage: $var->area = $object;
  46.      * @param $object Instance of Cidade
  47.      */
  48.     public function set_area(Area $object)
  49.     {
  50.         $this->area $object;
  51.         $this->area_id $object->id;
  52.     }
  53.     
  54.     /**
  55.      * Method get_status_dependente
  56.      * Sample of usage: $var->area->attribute;
  57.      * @returns Cidade instance
  58.      */
  59.     public function get_area()
  60.     {
  61.         
  62.         // loads the associated object
  63.         if (empty($this->area))
  64.             $this->area = new Area($this->area_id);
  65.         
  66.         // returns the associated object
  67.         return $this->area;
  68.     }
  69.         /**
  70.      * Method set_status_dependente
  71.      * Sample of usage: $var->sexo = $object;
  72.      * @param $object Instance of Cidade
  73.      */
  74.     public function set_sexo(Sexo $object)
  75.     {
  76.         $this->sexo $object;
  77.         $this->sexo_id $object->id;
  78.     }
  79.     
  80.     /**
  81.      * Method get_status_dependente
  82.      * Sample of usage: $var->sexo->attribute;
  83.      * @returns Cidade instance
  84.      */
  85.     public function get_sexo()
  86.     {
  87.         
  88.         // loads the associated object
  89.         if (empty($this->sexo))
  90.             $this->sexo = new Sexo($this->sexo_id);
  91.         
  92.         // returns the associated object
  93.         return $this->sexo;
  94.     }
  95.     /**
  96.      * Method set_uf
  97.      * Sample of usage: $var->uf = $object;
  98.      * @param $object Instance of Cidade
  99.      */
  100.     public function set_uf(Cidade $object)
  101.     {
  102.         $this->uf $object;
  103.         $this->uf_id $object->id;
  104.     }
  105.     
  106.     /**
  107.      * Method get_uf
  108.      * Sample of usage: $var->uf->attribute;
  109.      * @returns Cidade instance
  110.      */
  111.     public function get_uf()
  112.     {
  113.         
  114.         // loads the associated object
  115.         if (empty($this->uf))
  116.             $this->uf = new Cidade($this->uf_id);
  117.         
  118.         // returns the associated object
  119.         return $this->uf;
  120.     }
  121.      /**
  122.      * Method set_cidade
  123.      * Sample of usage: $var->cidade = $object;
  124.      * @param $object Instance of Cidade
  125.      */
  126.     public function set_cidade(Cidade $object)
  127.     {
  128.         $this->cidade $object;
  129.         $this->cidade_id $object->id;
  130.     }
  131.     /**
  132.      * Method get_cidade
  133.      * Sample of usage: $var->cidade->attribute;
  134.      * @returns Cidade instance
  135.      */
  136.     public function get_cidade()
  137.     {
  138.         
  139.         // loads the associated object
  140.         if (empty($this->cidade))
  141.             $this->cidade = new Cidade($this->cidade_id);
  142.         
  143.         // returns the associated object
  144.         return $this->cidade;
  145.     }
  146.      /**
  147.      * Method set_bairro
  148.      * Sample of usage: $var->bairro = $object;
  149.      * @param $object Instance of Cidade
  150.      */
  151.     public function set_bairro(Cidade $object)
  152.     {
  153.         $this->bairro $object;
  154.         $this->bairro_id $object->id;
  155.     }
  156.     
  157.     /**
  158.      * Method get_uf
  159.      * Sample of usage: $var->bairro->attribute;
  160.      * @returns Cidade instance
  161.      */
  162.     public function get_bairro()
  163.     {
  164.         
  165.         // loads the associated object
  166.         if (empty($this->bairro))
  167.             $this->bairro = new Cidade($this->bairro_id);
  168.         
  169.         // returns the associated object
  170.         return $this->bairro;
  171.     }
  172. }
  173. ?>


MODEL DA TABELA DEPENDENTE:
  1. <?php
  2. class Dependente extends TRecord
  3. {
  4.     const TABLENAME  'dependente';
  5.     const PRIMARYKEY 'dependente_id';
  6.     const IDPOLICY   =  'serial'// {max, serial}
  7.     
  8.     
  9.     
  10.     /**
  11.      * Constructor method
  12.      */
  13.     public function __construct($id NULL$callObjectLoad TRUE)
  14.     {
  15.         parent::__construct($dependente_id$callObjectLoad);
  16.         parent::addAttribute('dependente_nome');
  17.         parent::addAttribute('dependente_data_admissao');
  18.         parent::addAttribute('dependente_data_carencia');
  19.         parent::addAttribute('cliente_id');
  20.         parent::addAttribute('status_dependente_id');
  21.     }
  22.     /**
  23.      * Method set_cliente
  24.      * Sample of usage: $var->cliente = $object;
  25.      * @param $object Instance of Cidade
  26.      */
  27.     public function set_cliente(Cliente $object)
  28.     {
  29.         $this->cliente $object;
  30.         $this->cliente_id $object->id;
  31.     }
  32.     
  33.     /**
  34.      * Method     public function get_cliente()
  35.      * Sample of usage: $var->cliente->attribute;
  36.      * @returns Cidade instance
  37.      */
  38.     public function get_cliente()
  39.     {
  40.         
  41.         // loads the associated object
  42.         if (empty($this->cliente))
  43.             $this->cliente = new Cliente($this->cliente_id);
  44.         
  45.         // returns the associated object
  46.         return $this->cliente;
  47.     }
  48.      /**
  49.      * Method set_status_dependente
  50.      * Sample of usage: $var->status_dependente = $object;
  51.      * @param $object Instance of Cidade
  52.      */
  53.     public function set_status_dependente(StatusDependente $object)
  54.     {
  55.         $this->status_dependente $object;
  56.         $this->status_dependente_id $object->id;
  57.     }
  58.     
  59.     /**
  60.      * Method get_status_dependente
  61.      * Sample of usage: $var->status_dependente->attribute;
  62.      * @returns Cidade instance
  63.      */
  64.     public function get_status_dependente()
  65.     {
  66.         
  67.         // loads the associated object
  68.         if (empty($this->status_dependente))
  69.             $this->status_dependente = new StatusDependente($this->status_dependente_id);
  70.         
  71.         // returns the associated object
  72.         return $this->status_dependente;
  73.     }
  74. }
  75. ?>


MODEL DA TABELA STATUS DEPENDENTE:
  1. <?php
  2. class StatusDependente extends TRecord
  3. {
  4.     const TABLENAME  'status_dependente';
  5.     const PRIMARYKEY 'id';
  6.     const IDPOLICY   =  'serial'// {max, serial}
  7.     
  8.     
  9.     
  10.     /**
  11.      * Constructor method
  12.      */
  13.     public function __construct($id NULL$callObjectLoad TRUE)
  14.     {
  15.         parent::__construct($id$callObjectLoad);
  16.         parent::addAttribute('status_dependente');
  17.     }
  18. }
  19. ?>

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (2)


NR

Tem algumas diferenças entre o nome dos campos e os identificadores de sessão. Ex:
  1. <?php
  2. $dependente_nome = new TEntry('dependente_nome');
  3. //onEdit
  4. $this->loadItems('Dependente''cliente_id'$object'item_dependente'); // item_dependente é o identificador da sessão, então vai gravar os dados no array da sessão como "item_dependente_dependente_nome"
  5. ?>

Sugiro criar esse mestre x detalhe pelo Studio e comparar com o atual para encontrar as diferenças
ET

OK, deu certo Nataniel. Obrigado.