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

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


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


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 (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. ?>