Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Erro ao carregar campos grid Olá pessoal, Estou recebendo a seguinte mensagem ao carregar itens na grid SQLSTATE[HY000]: General error: 1 no such table: pessoa. Aguém pode me ajudar ? segue fonte abaixo. ...
RB
Erro ao carregar campos grid  
Olá pessoal,
Estou recebendo a seguinte mensagem ao carregar itens na grid
SQLSTATE[HY000]: General error: 1 no such table: pessoa.

Aguém pode me ajudar ?
segue fonte abaixo.

  1. <?php
  2. /**
  3.  * Pessoa Active Record
  4.  * @author  <your-name-here>
  5.  */
  6. class Pessoa extends TRecord
  7. {
  8.     const TABLENAME 'pessoa';
  9.     const PRIMARYKEY'id';
  10.     const IDPOLICY =  'serial'// {max, serial}
  11.     
  12.   private $fisica;
  13.   private $juridica;
  14.   private $pessoa_image;
  15.   private $pessoa_vinculo;
  16.   /**
  17.    * Constructor method
  18.    */
  19.   public function __construct($id NULL$callObjectLoad TRUE)
  20.   {
  21.       parent::__construct($id$callObjectLoad);
  22.       parent::addAttribute('criacao');
  23.       parent::addAttribute('tipo_pessoa_id');
  24.       parent::addAttribute('atualizacao');
  25.       parent::addAttribute('photo_path');
  26.   }
  27.   
  28.   /**
  29.    * Method get_fisica
  30.    * Sample of usage: $pessoa->fisica->attribute;
  31.    * @returns Fisica instance
  32.    */
  33.   public function get_fisica()
  34.   {
  35.       // loads the associated object
  36.     if (empty($this->fisica))
  37.       $this->fisica = new Fisica($this->id);
  38.       // returns the associated object
  39.     return $this->fisica;
  40.   }
  41.   /**
  42.    * Method get_fisica
  43.    * Sample of usage: $pessoa->juridica->attribute;
  44.    * @returns Fisica instance
  45.    */
  46.   public function get_juridica()
  47.   {
  48.       // loads the associated object
  49.     if (empty($this->juridica))
  50.       $this->juridica = new Fisica($this->id);
  51.       // returns the associated object
  52.     return $this->juridica;
  53.   }
  54.   
  55.   /**
  56.    * Method get_pessoa_image
  57.    * Sample of usage: $pessoa->pessoa_image->attribute;
  58.    * @returns PessoaImage instance
  59.    */
  60.   public function get_pessoa_image()
  61.   {
  62.       // loads the associated object
  63.       if (empty($this->pessoa_image))
  64.           $this->pessoa_image PessoaImage::find($this->id);
  65.   
  66.       // returns the associated object
  67.       return $this->pessoa_image;
  68.   }
  69.   
  70.  
  71.   /**
  72.    * Method get_pessoa_vinculo
  73.    * Sample of usage: $pessoa->pessoa_vinculo->attribute;
  74.    * @returns PessoaVinculo instance
  75.    */
  76.   public function get_pessoa_vinculo()
  77.   {
  78.       // loads the associated object
  79.       if (empty($this->pessoa_vinculo))
  80.           $this->pessoa_vinculo = new PessoaVinculo($this->pessoa_id);
  81.   
  82.       // returns the associated object
  83.       return $this->pessoa_vinculo;
  84.   }
  85.   
  86.  public function onBeforeStore($object)
  87.   {
  88.         // se tiver id trata-se de uma edição
  89.     if ($object->id){
  90.       $object->atualizacao date('Y-m-d H:i:s');
  91.     }    
  92.     else{
  93.       $object->criacao date('Y-m-d H:i:s');
  94.       $object->atualizacao date('Y-m-d H:i:s');
  95.     }
  96.   }
  97.   public function get_criacao_br()
  98.   {
  99.     return TDate::date2br($this->criacao);
  100.   }
  101.   public function get_atualizacao_br()
  102.   {
  103.     return TDate::date2br($this->atualizacao);
  104.   }
  105. }
  106. ?>

  1. <?php
  2. /**
  3.  * PessoaVinculo Active Record
  4.  * @author  <your-name-here>
  5.  */
  6. class PessoaVinculo extends TRecord
  7. {
  8.     const TABLENAME 'pessoa_vinculo';
  9.     const PRIMARYKEY'pessoa_id';
  10.     const IDPOLICY =  'serial'// {max, serial}   
  11.     
  12.     private $pessoa;
  13.     private $telefone;
  14.     private $telefones;
  15.     private $contato;
  16.     private $tipo_vinculo;
  17.     private $tipo_pessoa;
  18.     private $pessoa_endereco;
  19.     private $endereco;
  20.     private $system_unit;
  21.     /**
  22.      * Constructor method
  23.      */
  24.     public function __construct($id NULL$callObjectLoad TRUE)
  25.     {
  26.         parent::__construct($id$callObjectLoad);
  27.         parent::addAttribute('criacao');
  28.         parent::addAttribute('atualizacao');
  29.         parent::addAttribute('tipo_pessoa_id');
  30.         parent::addAttribute('system_unit_id');
  31.         parent::addAttribute('tipo_vinculo_id');
  32.         parent::addAttribute('situacao_id');
  33.         parent::addAttribute('ativo');
  34.     }
  35.     
  36.     /**
  37.      * Method set_pessoa
  38.      * Sample of usage: $pessoa_vinculo->pessoa = $object;
  39.      * @param $object Instance of Pessoa
  40.      */
  41.     public function set_pessoa(Pessoa $object)
  42.     {
  43.         $this->pessoa $object;
  44.         $this->pessoa_id $object->id;
  45.     }
  46.     
  47.     /**
  48.      * Method get_pessoa
  49.      * Sample of usage: $pessoa_vinculo->pessoa->attribute;
  50.      * @returns Pessoa instance
  51.      */
  52.     public function get_pessoa()
  53.     {
  54.         // loads the associated object
  55.         if (empty($this->pessoa))
  56.             $this->pessoa = new Pessoa($this->pessoa_id);
  57.     
  58.         // returns the associated object
  59.         return $this->pessoa;
  60.     }
  61.     /**
  62.      * Method get_contato
  63.      * Sample of usage: $pessoa_vinculo->contato->attribute;
  64.      * @returns Contato instance
  65.      */
  66.     public function get_contato()
  67.     {
  68.         // loads the associated object
  69.         if (empty($this->contato))
  70.         {
  71.             $criteria = new TCriteria;
  72.             $criteria->add( new TFilter('pessoa_id''='$this->id ));
  73.             $criteria->add(new TFilter('tipo_contato_id','IN',array(3,4,5,6,12)));
  74.             $contato Contato::getObjects($criteria);
  75.             
  76.             $this->contato $contato;
  77.         }   
  78.         // returns the associated object
  79.         return $this->contato;
  80.     }
  81.     /**
  82.      * Method get_teleefone
  83.      * Sample of usage: $telefone->attribute;
  84.      * @returns Telefone instance
  85.      */
  86.     public function get_telefone()
  87.     {
  88.         // loads the associated object
  89.         if (empty($this->telefone)){
  90.             $this->telefone Telefone::where('pessoa_id','=',$this->pessoa_id)->first();
  91.         }            
  92.         // returns the associated object
  93.         return $this->telefone;
  94.     } 
  95.     public function getTelefones()
  96.     {
  97.         // loads the associated object
  98.         if (empty($this->telefones)){
  99.             $this->telefones Telefone::where('pessoa_id','=',$this->pessoa_id)->load();
  100.         }            
  101.         // returns the associated object
  102.         return $this->telefones;
  103.     } 
  104.     
  105.     /**
  106.      * Method get_pessoa_endereco
  107.      * Sample of usage: $pessoa_endereco->attribute;
  108.      * @returns PessoaEndereco instance
  109.      */
  110.     public function get_pessoa_endereco()
  111.     {
  112.         // loads the associated object
  113.         if (empty($this->pessoa_endereco))
  114.             $this->pessoa_endereco PessoaEndereco::where('pessoa_id','=',$this->pessoa_id)->first();
  115.         // returns the associated object
  116.         return $this->pessoa_endereco;
  117.     }
  118.         
  119.     /**
  120.      * Method set_tipo_vinculo
  121.      * Sample of usage: $pessoa_vinculo->tipo_vinculo = $object;
  122.      * @param $object Instance of TipoVinculo
  123.      */
  124.     public function set_tipo_vinculo(TipoVinculo $object)
  125.     {
  126.         $this->tipo_vinculo $object;
  127.         $this->tipo_vinculo_id $object->id;
  128.     }
  129.     
  130.     /**
  131.      * Method get_tipo_vinculo
  132.      * Sample of usage: $pessoa_vinculo->tipo_vinculo->attribute;
  133.      * @returns TipoVinculo instance
  134.      */
  135.     public function get_tipo_vinculo()
  136.     {
  137.         // loads the associated object
  138.         if (empty($this->tipo_vinculo))
  139.             $this->tipo_vinculo = new TipoVinculo($this->tipo_vinculo_id);
  140.     
  141.         // returns the associated object
  142.         return $this->tipo_vinculo;
  143.     }    
  144.     
  145.     /**
  146.      * Method set_tipo_pessoa
  147.      * Sample of usage: $pessoa_vinculo->tipo_pessoa = $object;
  148.      * @param $object Instance of TipoPessoa
  149.      */
  150.     public function set_tipo_pessoa(TipoPessoa $object)
  151.     {
  152.         $this->tipo_pessoa $object;
  153.         $this->tipo_pessoa_id $object->id;
  154.     }
  155.     
  156.     /**
  157.      * Method get_tipo_pessoa
  158.      * Sample of usage: $pessoa_vinculo->tipo_pessoa->attribute;
  159.      * @returns TipoPessoa instance
  160.      */
  161.     public function get_tipo_pessoa()
  162.     {
  163.         // loads the associated object
  164.         if (empty($this->tipo_pessoa))
  165.             $this->tipo_pessoa = new TipoPessoa($this->tipo_pessoa_id);
  166.     
  167.         // returns the associated object
  168.         return $this->tipo_pessoa;
  169.     }
  170.     public function onBeforeStore($object)
  171.     {
  172.         // se tiver id trata-se de uma edição
  173.         if (!empty($object->pessoa_id))
  174.         {
  175.             $object->atualizacao date('Y-m-d H:i:s');
  176.         }    
  177.         else{
  178.             $object->criacao date('Y-m-d H:i:s');
  179.             $object->atualizacao date('Y-m-d H:i:s');
  180.         }
  181.     }
  182.     public function get_criacao_br()
  183.     {
  184.         return TDate::date2br($this->criacao);
  185.     }
  186.     public function get_atualizacao_br()
  187.     {
  188.         return TDate::date2br($this->atualizacao);
  189.     }
  190.     /**
  191.    * Method get_system_unit
  192.    * Sample of usage: $pessoa_vinculo->system_unit->attribute;
  193.    * @returns SystemUnit instance
  194.    */
  195.   public function get_system_unit()
  196.   {    
  197.     try 
  198.     {
  199.         // open a transaction with database 'db'
  200.         TTransaction::open('permission');
  201.         // loads the associated object
  202.         $this->system_unit = new SystemUnit($this->system_unit_id);
  203.   
  204.         // returns the associated object
  205.         return $this->system_unit;
  206.        TTransaction::close();
  207.     } 
  208.     catch (Exception $e
  209.     {
  210.        
  211.     } 
  212.   }
  213. }
  214. ?>


Porém ao tentar carregar na grid apresenta este erro em alguns campos


Classe da grid
  1. <?php
  2. class DataGridClienteJuridico extends TPage
  3. {
  4.     private $datagrid$pageNavigation$loaded;
  5.     
  6.     public function __construct()
  7.     {
  8.         parent::__construct();
  9.         
  10.         // creates one datagrid
  11.         $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
  12.         $this->datagrid->width '100%';
  13.         
  14.         // add the columns
  15.         $this->datagrid->addColumn(new TDataGridColumn('pessoa_id','#','center',''));
  16.         $nome $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->nome',_t('Name'),'left',''));
  17.         $data_cadastro $this->datagrid->addColumn(new TDataGridColumn('criacao_br','Data Cadastro','left',''));
  18.         $telefone $this->datagrid->addColumn(new TDataGridColumn('telefone->numero','Telefone','left',''));
  19.         $unidade $this->datagrid->addColumn(new TDataGridColumn('system_unit->name','Unit','left',''));
  20.         $cpf $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->cpf','CNPJ','left',''));
  21.         $rg $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->rg','IE','left',''));
  22.         $cidade $this->datagrid->addColumn(new TDataGridColumn('pessoa_endereco->endereco->estado->nome','Cidade','left',''));
  23.         $uf $this->datagrid->addColumn(new TDataGridColumn('pessoa_endereco->endereco->estado->uf','UF','left',''));
  24.         $editar $this->datagrid->addColumn(new TDataGridColumn('editar','','center'));
  25.         $deletar $this->datagrid->addColumn(new TDataGridColumn('deletar','','center'));
  26.         $data_cadastro->enableAutoHide(500);
  27.         $telefone->enableAutoHide(600);
  28.         //$unidade->enableAutoHide(700);
  29.         $cpf->enableAutoHide(800);
  30.         $rg->enableAutoHide(900);
  31.         $uf->enableAutoHide(1000);
  32.         $cidade->enableAutoHide(1000);
  33.         $uf->setDataProperty('style','font-weight: bold');
  34.                 
  35.         // creates the datagrid model
  36.         $this->datagrid->createModel();
  37.         // creates the page navigation
  38.         $this->pageNavigation = new TPageNavigation;
  39.         $this->pageNavigation->setAction(new TAction([$this'onReload']));
  40.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  41.         $this->pageNavigation->enableCounters();
  42.         
  43.         // search box
  44.         $input_search = new TEntry('input_search');
  45.         $input_search->placeholder _t('Search');
  46.         $input_search->setSize('100%');
  47.         
  48.         // enable fuse search by column name
  49.         $this->datagrid->enableSearch($input_search,'pessoa_id,criacao_br,pessoa->fisica->nome,telefone->numero,pessoa->fisica->cpf,pessoa->fisica->rg');
  50.         
  51.         $panel = new TPanelGroup('{$cliente}');
  52.         $panel->addHeaderWidget($input_search);
  53.         $panel->add($this->datagrid)->style 'overflow-x:auto';
  54.         $panel->addFooter($this->pageNavigation);
  55.         
  56.         // wrap the page content using vertical box
  57.         $vbox = new TVBox;
  58.         $vbox->style 'width: 100%';
  59.         //$vbox->add(new TXMLBreadCrumb('menu.xml',__CLASS__));
  60.         $vbox->add($panel);
  61.         parent::add($vbox);
  62.     }
  63.     
  64.     /**
  65.      * method onReload()
  66.      * Load the datagrid with the database objects
  67.      */
  68.     function onReload($param NULL)
  69.     {
  70.         try
  71.         {
  72.             // open a transaction with database 'db'
  73.             TTransaction::open('db');
  74.             
  75.             // creates a repository for PessoaVinculo
  76.             $repository = new TRepository('PessoaVinculo');
  77.             $limit 10;
  78.             
  79.             // creates a criteria
  80.             $criteria = new TCriteria;
  81.             $criteria->add(new TFilter('tipo_pessoa_id','='2));
  82.             $criteria->add(new TFilter('system_unit_id','='TSession::getValue('userunitid')));
  83.             $criteria->add(new TFilter('tipo_vinculo_id','='2));
  84.             $criteria->add(new TFilter('situacao_id''='1));             
  85.             
  86.             // default order
  87.             if (empty($param['order']))
  88.             {
  89.                 $param['order'] = 'pessoa_id';
  90.                 $param['direction'] = 'asc';
  91.             }
  92.             
  93.             $criteria->setProperties($param); // order, offset
  94.             $criteria->setProperty('limit'$limit);            
  95.                       
  96.             // load the objects according to criteria
  97.             $objects $repository->load($criteria);
  98.             
  99.             $this->datagrid->clear();
  100.             if ($objects)
  101.             {
  102.                 // iterate the collection of active records
  103.                 foreach ($objects as $object)
  104.                 {
  105.                     //cria os botões de ação e adiciona a datagrid
  106.                     $edit = new TElement('i');
  107.                     $edit->class="fa fa-search blue";
  108.                    
  109.                     $action = new TAction(['JuridicaForm','onEdit'],['pessoa_id'=>"$object->pessoa_id"]);
  110.                     $action->setParameter('key',$object->pessoa_id);
  111.                     $object->editar $edit;
  112.                     $a = new TActionLink($edit$action);
  113.                     $a->class 'btn_transparent';
  114.                     $del = new TElement('i');
  115.                     $del->class ="fa fa-trash-alt red";
  116.                     $action1 = new TAction(array($this'onDelete'));
  117.                     $action1->setParameter('key',$object->pessoa_id);
  118.                     $object->deletar $del;
  119.                     $b = new TActionLink($del$action1);
  120.                     $b->class 'btn_transparent';
  121.                     $object->editar $a;
  122.                     $object->deletar $b;
  123.                     // add the object inside the datagrid
  124.                     $this->datagrid->addItem($object);
  125.                 }
  126.             }
  127.             
  128.             // reset the criteria for record count
  129.             $criteria->resetProperties();
  130.             $count $repository->count($criteria);
  131.             
  132.             $this->pageNavigation->setCount($count); // count of records
  133.             $this->pageNavigation->setProperties($param); // order, page
  134.             $this->pageNavigation->setLimit($limit); // limit
  135.             
  136.             // close the transaction
  137.             TTransaction::close();
  138.             $this->loaded true;
  139.         }
  140.         catch (Exception $e// in case of exception
  141.         {
  142.             new TMessage('error'$e->getMessage()); // shows the exception error message
  143.             TTransaction::rollback(); // undo all pending operations
  144.         }
  145.     }
  146.     
  147.     /**
  148.      * Executed when the user clicks at the view button
  149.      */
  150.     public static function onView($param)
  151.     {
  152.         // get the parameter and shows the message
  153.         $code $param['pessoa_id'];
  154.         $name $param['pessoa->fisica->nome'];
  155.         new TMessage('info'"The code is: <b>$code</b> <br> The name is : <b>$name</b>");
  156.     }
  157.     /**
  158.      * Ask before deletion
  159.      */
  160.     public static function onDelete($param)
  161.     {
  162.         // define the delete action
  163.         $action = new TAction(array(__CLASS__'Delete'));
  164.         $action->setParameters($param); // pass the key parameter ahead
  165.         
  166.         // shows a dialog to the user
  167.         new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  168.     }
  169.     
  170.     /**
  171.      * Delete a record
  172.      */
  173.     public static function Delete($param)
  174.     {
  175.         try
  176.         {  
  177.             $key $param['key']; // get the parameter $key
  178.             $system_unit_id =  TSession::getValue('userunitid');
  179.             TTransaction::open('db'); // open a transaction with database
  180.             $cliente PessoaVinculo::where('pessoa_id','='$key)
  181.                     ->where('system_unit_id','=',$system_unit_id)
  182.                     ->set('ativo'0)
  183.                     ->update();
  184.             TTransaction::close(); // close the transaction
  185.             
  186.             $pos_action = new TAction([__CLASS__'onReload']);
  187.                         
  188.             new TMessage('info'AdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
  189.         }
  190.         catch (Exception $e// in case of exception
  191.         {
  192.             new TMessage('error'$e->getMessage()); // shows the exception error message
  193.             TTransaction::rollback(); // undo all pending operations
  194.         }
  195.     }
  196.     
  197.    /**
  198.      * shows the page
  199.      */
  200.     function show()
  201.     {
  202.         $this->onReload();
  203.         parent::show();
  204.     }
  205. ?>


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 (1)


RB

Resolvido ....

Só foi colocar o retorno depois que fecha a transação

  1. <?php
  2. //......
  3.  /**
  4.    * Method get_system_unit
  5.    * Sample of usage: $pessoa_vinculo->system_unit->attribute;
  6.    * @returns SystemUnit instance
  7.    */
  8.   public function get_system_unit()
  9.     {    
  10.         try 
  11.         {
  12.             // open a transaction with database 'db'
  13.             TTransaction::open('permission');
  14.             // loads the associated object
  15.             $this->system_unit SystemUnit::where('id','=',$this->system_unit_id)->first();
  16.             TTransaction::close();
  17.             // returns the associated object
  18.             return $this->system_unit;
  19.         } 
  20.         catch (Exception $e
  21.         {
  22.         } 
  23.     }
  24. ?>