Lançado Adianti Framework 8.1!
Clique aqui para saber mais
Erro ao deletar registros usando View Olá, depois que passei a usar uma view no formulário, não estou conseguindo deletar registros pela grid. Podem me ajudar ? ...
AR
Erro ao deletar registros usando View  
Olá, depois que passei a usar uma view no formulário, não estou conseguindo deletar registros pela grid. Podem me ajudar ?

  1. <?php 
  2. /**
  3.  * LancamentoDataGridView Listing
  4.   */
  5. class LancamentoDataGridView extends TPage
  6. {
  7.     protected $form;     // registration form
  8.     protected $datagrid// listing
  9.     protected $pageNavigation;
  10.     protected $formgrid;
  11.     protected $formtotais;
  12.     protected $deleteButton;
  13.     
  14.     use Adianti\base\AdiantiStandardListTrait;
  15.     
  16.     /**
  17.      * Page constructor
  18.      */
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.         
  23.         $this->setDatabase('newcoco');            // defines the database
  24.         $this->setActiveRecord('ViewLancamentos');   // defines the active record
  25.         $this->setDefaultOrder('id''asc');         // defines the default order
  26.        
  27. ?>


Erro:

SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR: cannot delete from view "view_lancamentos" DETAIL: Views that do not select from a single table or view are not automatically updatable. HINT: To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.

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


LC

A view não deleta no Banco
Para excluir tem que usar a tabela, ai você vai ter que tratar isso no onDelete
AR

Será que posso instanciar a tabela (Lancamento($param->id) ) usando o parâmetro ID ?


  1. <?php
  2.  public function onDeleteCollection$param )
  3.     {
  4.         $data $this->formgrid->getData(); // get selected records from datagrid
  5.         $this->formgrid->setData($data); // keep form filled
  6.         
  7.         if ($data)
  8.         {
  9.             $selected = array();
  10.             
  11.             // get the record id's
  12.             foreach ($data as $index => $check)
  13.             {
  14.                 if ($check == 'on')
  15.                 {
  16.                     $selected[] = substr($index,5);
  17.                 }
  18.             }
  19.             
  20.             if ($selected)
  21.             {
  22.                 // encode record id's as json
  23.                 $param['selected'] = json_encode($selected);
  24.                 
  25.                 // define the delete action
  26.                 $action = new TAction(array($this'deleteCollection'));
  27.                 $action->setParameters($param); // pass the key parameter ahead
  28.                 
  29.                 // shows a dialog to the user
  30.                 new TQuestion(AdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  31.             }
  32.         }
  33.     }
  34. ?>