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.
Porém ao tentar carregar na grid apresenta este erro em alguns campos
Classe da grid
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.
- <?php
- /**
- * Pessoa Active Record
- * @author <your-name-here>
- */
- class Pessoa extends TRecord
- {
- const TABLENAME = 'pessoa';
- const PRIMARYKEY= 'id';
- const IDPOLICY = 'serial'; // {max, serial}
- private $fisica;
- private $juridica;
- private $pessoa_image;
- private $pessoa_vinculo;
- /**
- * Constructor method
- */
- public function __construct($id = NULL, $callObjectLoad = TRUE)
- {
- parent::__construct($id, $callObjectLoad);
- parent::addAttribute('criacao');
- parent::addAttribute('tipo_pessoa_id');
- parent::addAttribute('atualizacao');
- parent::addAttribute('photo_path');
- }
- /**
- * Method get_fisica
- * Sample of usage: $pessoa->fisica->attribute;
- * @returns Fisica instance
- */
- public function get_fisica()
- {
- // loads the associated object
- if (empty($this->fisica))
- $this->fisica = new Fisica($this->id);
- // returns the associated object
- return $this->fisica;
- }
- /**
- * Method get_fisica
- * Sample of usage: $pessoa->juridica->attribute;
- * @returns Fisica instance
- */
- public function get_juridica()
- {
- // loads the associated object
- if (empty($this->juridica))
- $this->juridica = new Fisica($this->id);
- // returns the associated object
- return $this->juridica;
- }
- /**
- * Method get_pessoa_image
- * Sample of usage: $pessoa->pessoa_image->attribute;
- * @returns PessoaImage instance
- */
- public function get_pessoa_image()
- {
- // loads the associated object
- if (empty($this->pessoa_image))
- $this->pessoa_image = PessoaImage::find($this->id);
- // returns the associated object
- return $this->pessoa_image;
- }
- /**
- * Method get_pessoa_vinculo
- * Sample of usage: $pessoa->pessoa_vinculo->attribute;
- * @returns PessoaVinculo instance
- */
- public function get_pessoa_vinculo()
- {
- // loads the associated object
- if (empty($this->pessoa_vinculo))
- $this->pessoa_vinculo = new PessoaVinculo($this->pessoa_id);
- // returns the associated object
- return $this->pessoa_vinculo;
- }
- public function onBeforeStore($object)
- {
- // se tiver id trata-se de uma edição
- if ($object->id){
- $object->atualizacao = date('Y-m-d H:i:s');
- }
- else{
- $object->criacao = date('Y-m-d H:i:s');
- $object->atualizacao = date('Y-m-d H:i:s');
- }
- }
- public function get_criacao_br()
- {
- return TDate::date2br($this->criacao);
- }
- public function get_atualizacao_br()
- {
- return TDate::date2br($this->atualizacao);
- }
- }
- ?>
- <?php
- /**
- * PessoaVinculo Active Record
- * @author <your-name-here>
- */
- class PessoaVinculo extends TRecord
- {
- const TABLENAME = 'pessoa_vinculo';
- const PRIMARYKEY= 'pessoa_id';
- const IDPOLICY = 'serial'; // {max, serial}
- private $pessoa;
- private $telefone;
- private $telefones;
- private $contato;
- private $tipo_vinculo;
- private $tipo_pessoa;
- private $pessoa_endereco;
- private $endereco;
- private $system_unit;
- /**
- * Constructor method
- */
- public function __construct($id = NULL, $callObjectLoad = TRUE)
- {
- parent::__construct($id, $callObjectLoad);
- parent::addAttribute('criacao');
- parent::addAttribute('atualizacao');
- parent::addAttribute('tipo_pessoa_id');
- parent::addAttribute('system_unit_id');
- parent::addAttribute('tipo_vinculo_id');
- parent::addAttribute('situacao_id');
- parent::addAttribute('ativo');
- }
- /**
- * Method set_pessoa
- * Sample of usage: $pessoa_vinculo->pessoa = $object;
- * @param $object Instance of Pessoa
- */
- public function set_pessoa(Pessoa $object)
- {
- $this->pessoa = $object;
- $this->pessoa_id = $object->id;
- }
- /**
- * Method get_pessoa
- * Sample of usage: $pessoa_vinculo->pessoa->attribute;
- * @returns Pessoa instance
- */
- public function get_pessoa()
- {
- // loads the associated object
- if (empty($this->pessoa))
- $this->pessoa = new Pessoa($this->pessoa_id);
- // returns the associated object
- return $this->pessoa;
- }
- /**
- * Method get_contato
- * Sample of usage: $pessoa_vinculo->contato->attribute;
- * @returns Contato instance
- */
- public function get_contato()
- {
- // loads the associated object
- if (empty($this->contato))
- {
- $criteria = new TCriteria;
- $criteria->add( new TFilter('pessoa_id', '=', $this->id ));
- $criteria->add(new TFilter('tipo_contato_id','IN',array(3,4,5,6,12)));
- $contato = Contato::getObjects($criteria);
- $this->contato = $contato;
- }
- // returns the associated object
- return $this->contato;
- }
- /**
- * Method get_teleefone
- * Sample of usage: $telefone->attribute;
- * @returns Telefone instance
- */
- public function get_telefone()
- {
- // loads the associated object
- if (empty($this->telefone)){
- $this->telefone = Telefone::where('pessoa_id','=',$this->pessoa_id)->first();
- }
- // returns the associated object
- return $this->telefone;
- }
- public function getTelefones()
- {
- // loads the associated object
- if (empty($this->telefones)){
- $this->telefones = Telefone::where('pessoa_id','=',$this->pessoa_id)->load();
- }
- // returns the associated object
- return $this->telefones;
- }
- /**
- * Method get_pessoa_endereco
- * Sample of usage: $pessoa_endereco->attribute;
- * @returns PessoaEndereco instance
- */
- public function get_pessoa_endereco()
- {
- // loads the associated object
- if (empty($this->pessoa_endereco))
- $this->pessoa_endereco = PessoaEndereco::where('pessoa_id','=',$this->pessoa_id)->first();
- // returns the associated object
- return $this->pessoa_endereco;
- }
- /**
- * Method set_tipo_vinculo
- * Sample of usage: $pessoa_vinculo->tipo_vinculo = $object;
- * @param $object Instance of TipoVinculo
- */
- public function set_tipo_vinculo(TipoVinculo $object)
- {
- $this->tipo_vinculo = $object;
- $this->tipo_vinculo_id = $object->id;
- }
- /**
- * Method get_tipo_vinculo
- * Sample of usage: $pessoa_vinculo->tipo_vinculo->attribute;
- * @returns TipoVinculo instance
- */
- public function get_tipo_vinculo()
- {
- // loads the associated object
- if (empty($this->tipo_vinculo))
- $this->tipo_vinculo = new TipoVinculo($this->tipo_vinculo_id);
- // returns the associated object
- return $this->tipo_vinculo;
- }
- /**
- * Method set_tipo_pessoa
- * Sample of usage: $pessoa_vinculo->tipo_pessoa = $object;
- * @param $object Instance of TipoPessoa
- */
- public function set_tipo_pessoa(TipoPessoa $object)
- {
- $this->tipo_pessoa = $object;
- $this->tipo_pessoa_id = $object->id;
- }
- /**
- * Method get_tipo_pessoa
- * Sample of usage: $pessoa_vinculo->tipo_pessoa->attribute;
- * @returns TipoPessoa instance
- */
- public function get_tipo_pessoa()
- {
- // loads the associated object
- if (empty($this->tipo_pessoa))
- $this->tipo_pessoa = new TipoPessoa($this->tipo_pessoa_id);
- // returns the associated object
- return $this->tipo_pessoa;
- }
- public function onBeforeStore($object)
- {
- // se tiver id trata-se de uma edição
- if (!empty($object->pessoa_id))
- {
- $object->atualizacao = date('Y-m-d H:i:s');
- }
- else{
- $object->criacao = date('Y-m-d H:i:s');
- $object->atualizacao = date('Y-m-d H:i:s');
- }
- }
- public function get_criacao_br()
- {
- return TDate::date2br($this->criacao);
- }
- public function get_atualizacao_br()
- {
- return TDate::date2br($this->atualizacao);
- }
- /**
- * Method get_system_unit
- * Sample of usage: $pessoa_vinculo->system_unit->attribute;
- * @returns SystemUnit instance
- */
- public function get_system_unit()
- {
- try
- {
- // open a transaction with database 'db'
- TTransaction::open('permission');
- // loads the associated object
- $this->system_unit = new SystemUnit($this->system_unit_id);
- // returns the associated object
- return $this->system_unit;
- TTransaction::close();
- }
- catch (Exception $e)
- {
- }
- }
- }
- ?>
Porém ao tentar carregar na grid apresenta este erro em alguns campos
Classe da grid
- <?php
- class DataGridClienteJuridico extends TPage
- {
- private $datagrid, $pageNavigation, $loaded;
- public function __construct()
- {
- parent::__construct();
- // creates one datagrid
- $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid);
- $this->datagrid->width = '100%';
- // add the columns
- $this->datagrid->addColumn(new TDataGridColumn('pessoa_id','#','center',''));
- $nome = $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->nome',_t('Name'),'left',''));
- $data_cadastro = $this->datagrid->addColumn(new TDataGridColumn('criacao_br','Data Cadastro','left',''));
- $telefone = $this->datagrid->addColumn(new TDataGridColumn('telefone->numero','Telefone','left',''));
- $unidade = $this->datagrid->addColumn(new TDataGridColumn('system_unit->name','Unit','left',''));
- $cpf = $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->cpf','CNPJ','left',''));
- $rg = $this->datagrid->addColumn(new TDataGridColumn('pessoa->fisica->rg','IE','left',''));
- $cidade = $this->datagrid->addColumn(new TDataGridColumn('pessoa_endereco->endereco->estado->nome','Cidade','left',''));
- $uf = $this->datagrid->addColumn(new TDataGridColumn('pessoa_endereco->endereco->estado->uf','UF','left',''));
- $editar = $this->datagrid->addColumn(new TDataGridColumn('editar','','center'));
- $deletar = $this->datagrid->addColumn(new TDataGridColumn('deletar','','center'));
- $data_cadastro->enableAutoHide(500);
- $telefone->enableAutoHide(600);
- //$unidade->enableAutoHide(700);
- $cpf->enableAutoHide(800);
- $rg->enableAutoHide(900);
- $uf->enableAutoHide(1000);
- $cidade->enableAutoHide(1000);
- $uf->setDataProperty('style','font-weight: bold');
- // creates the datagrid model
- $this->datagrid->createModel();
- // creates the page navigation
- $this->pageNavigation = new TPageNavigation;
- $this->pageNavigation->setAction(new TAction([$this, 'onReload']));
- $this->pageNavigation->setWidth($this->datagrid->getWidth());
- $this->pageNavigation->enableCounters();
- // search box
- $input_search = new TEntry('input_search');
- $input_search->placeholder = _t('Search');
- $input_search->setSize('100%');
- // enable fuse search by column name
- $this->datagrid->enableSearch($input_search,'pessoa_id,criacao_br,pessoa->fisica->nome,telefone->numero,pessoa->fisica->cpf,pessoa->fisica->rg');
- $panel = new TPanelGroup('{$cliente}');
- $panel->addHeaderWidget($input_search);
- $panel->add($this->datagrid)->style = 'overflow-x:auto';
- $panel->addFooter($this->pageNavigation);
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->style = 'width: 100%';
- //$vbox->add(new TXMLBreadCrumb('menu.xml',__CLASS__));
- $vbox->add($panel);
- parent::add($vbox);
- }
- /**
- * method onReload()
- * Load the datagrid with the database objects
- */
- function onReload($param = NULL)
- {
- try
- {
- // open a transaction with database 'db'
- TTransaction::open('db');
- // creates a repository for PessoaVinculo
- $repository = new TRepository('PessoaVinculo');
- $limit = 10;
- // creates a criteria
- $criteria = new TCriteria;
- $criteria->add(new TFilter('tipo_pessoa_id','=', 2));
- $criteria->add(new TFilter('system_unit_id','=', TSession::getValue('userunitid')));
- $criteria->add(new TFilter('tipo_vinculo_id','=', 2));
- $criteria->add(new TFilter('situacao_id', '=', 1));
- // default order
- if (empty($param['order']))
- {
- $param['order'] = 'pessoa_id';
- $param['direction'] = 'asc';
- }
- $criteria->setProperties($param); // order, offset
- $criteria->setProperty('limit', $limit);
- // load the objects according to criteria
- $objects = $repository->load($criteria);
- $this->datagrid->clear();
- if ($objects)
- {
- // iterate the collection of active records
- foreach ($objects as $object)
- {
- //cria os botões de ação e adiciona a datagrid
- $edit = new TElement('i');
- $edit->class="fa fa-search blue";
- $action = new TAction(['JuridicaForm','onEdit'],['pessoa_id'=>"$object->pessoa_id"]);
- $action->setParameter('key',$object->pessoa_id);
- $object->editar = $edit;
- $a = new TActionLink($edit, $action);
- $a->class = 'btn_transparent';
- $del = new TElement('i');
- $del->class ="fa fa-trash-alt red";
- $action1 = new TAction(array($this, 'onDelete'));
- $action1->setParameter('key',$object->pessoa_id);
- $object->deletar = $del;
- $b = new TActionLink($del, $action1);
- $b->class = 'btn_transparent';
- $object->editar = $a;
- $object->deletar = $b;
- // add the object inside the datagrid
- $this->datagrid->addItem($object);
- }
- }
- // reset the criteria for record count
- $criteria->resetProperties();
- $count = $repository->count($criteria);
- $this->pageNavigation->setCount($count); // count of records
- $this->pageNavigation->setProperties($param); // order, page
- $this->pageNavigation->setLimit($limit); // limit
- // close the transaction
- TTransaction::close();
- $this->loaded = true;
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Executed when the user clicks at the view button
- */
- public static function onView($param)
- {
- // get the parameter and shows the message
- $code = $param['pessoa_id'];
- $name = $param['pessoa->fisica->nome'];
- new TMessage('info', "The code is: <b>$code</b> <br> The name is : <b>$name</b>");
- }
- /**
- * Ask before deletion
- */
- public static function onDelete($param)
- {
- // define the delete action
- $action = new TAction(array(__CLASS__, 'Delete'));
- $action->setParameters($param); // pass the key parameter ahead
- // shows a dialog to the user
- new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
- }
- /**
- * Delete a record
- */
- public static function Delete($param)
- {
- try
- {
- $key = $param['key']; // get the parameter $key
- $system_unit_id = TSession::getValue('userunitid');
- TTransaction::open('db'); // open a transaction with database
- $cliente = PessoaVinculo::where('pessoa_id','=', $key)
- ->where('system_unit_id','=',$system_unit_id)
- ->set('ativo', 0)
- ->update();
- TTransaction::close(); // close the transaction
- $pos_action = new TAction([__CLASS__, 'onReload']);
- new TMessage('info', AdiantiCoreTranslator::translate('Record deleted'), $pos_action); // success message
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * shows the page
- */
- function show()
- {
- $this->onReload();
- parent::show();
- }
- }
- ?>
Resolvido ....
Só foi colocar o retorno depois que fecha a transação