Lançado Adianti Framework 7.6!
Clique aqui para saber mais
TDBMultiSearch não grava Dados Pessoal estou usando TDBMultiSearch para gravar os municipios de carregamento da da MDF-e mas não esta gravando, fica em branco, estou tentando gravar em uma tabela que se chama "Carregamento". O que pode ser ? Form: Store() ...
RA
TDBMultiSearch não grava Dados  
Pessoal estou usando TDBMultiSearch para gravar os municipios de carregamento da da MDF-e mas não esta gravando, fica em branco, estou tentando gravar em uma tabela que se chama "Carregamento". O que pode ser ?

Form:
  1. <?php  
  2. ...
  3. $Carregamento= new TDBMultiSearch('Municipio_ID''mdfe''municipio''ID_Municipio','Nome''UF');
  4. .
  5. .
  6. .
  7. ?>


Store()
  1. <?php
  2.  public function store()
  3.     {
  4.         // store the object itself
  5.         parent::store();
  6.     
  7.         // delete the related Carregamento objects
  8.         $criteria = new TCriteria;
  9.         $criteria->add(new TFilter('mdfe_id''='$this->id));
  10.         $repository = new TRepository('Carregamento');
  11.         $repository->delete($criteria);
  12.         // store the related Carregamento objects
  13.         if ($this->carregamentos)
  14.         {
  15.             foreach ($this->carregamentos as $carregamento)
  16.             {
  17.                 unset($carregamento->id);
  18.                 $carregamento->mdfe_id $this->id;
  19.                 $carregamento->store();
  20.             }
  21.         }
  22.        ...    
  23. ?>

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


RA

No onSave esta assim:

  1. <?php
  2.  /**
  3.      * Save form data
  4.      * @param $param Request
  5.      */
  6.     public function onSave$param )
  7.     {
  8.         try
  9.         {
  10.             TTransaction::open('mdfe'); // open a transaction
  11.             
  12.             /**
  13.             // Enable Debug logger for SQL operations inside the transaction
  14.             TTransaction::setLogger(new TLoggerSTD); // standard output
  15.             TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
  16.             **/
  17.             
  18.             $this->form->validate(); // validate form data
  19.             $data $this->form->getData(); // get form data as array
  20.             
  21.          
  22.             
  23.             $object = new Mdfe;  // create an empty object
  24.             $object->fromArray( (array) $data); // load the object with data
  25.             $object->store(); // save the object
  26.             
  27.           
  28.                   
  29.             
  30.             
  31.             // get the generated ID_Mdfe
  32.             $data->ID_Mdfe $object->ID_Mdfe;
  33.             
  34.             $this->form->setData($data); // fill form data
  35.             TTransaction::close(); // close the transaction
  36.             
  37.             new TMessage('info'TAdiantiCoreTranslator::translate('Record saved'));
  38.         }
  39.         catch (Exception $e// in case of exception
  40.         {
  41.             new TMessage('error'$e->getMessage()); // shows the exception error message
  42.             $this->form->setData$this->form->getData() ); // keep form data
  43.             TTransaction::rollback(); // undo all pending operations
  44.         }
  45.     }
  46.     ?>
NR

A sua função onSave não está fazendo o tratamento da composição.

Você vai precisar fazer o foreach dos municípios e adicionar os itens, antes de chamar a função store:
  1. <?php
  2. foreach ($data->Municipio_ID as $municipio_id)
  3. {
  4.       $carregamento = new Carregamento();
  5.       $carregamento->Municipio_ID $municipio_id//conferir nome do atributo
  6.       $object->addCarregamento($carregamento); //conferir nome da função
  7. }
  8. ?>
RA

Nataniel Rabaioli Não funcionou.
NR

Como ficou a onSave?
RA

Nataniel Rabaioli não entendi esse foreach no onSave, pois já não é feito no model em Store() ?

  1. <?php
  2.  public function store()
  3.     {
  4.         // store the object itself
  5.         parent::store();
  6.     
  7.         // delete the related Carregamento objects
  8.         $criteria = new TCriteria;
  9.         $criteria->add(new TFilter('mdfe_id''='$this->id));
  10.         $repository = new TRepository('Carregamento');
  11.         $repository->delete($criteria);
  12.         // store the related Carregamento objects
  13.         if ($this->carregamentos)
  14.         {
  15.             foreach ($this->carregamentos as $carregamento)
  16.             {
  17.                 unset($carregamento->id);
  18.                 $carregamento->mdfe_id $this->id;
  19.                 $carregamento->store();
  20.             }
  21.         }
  22.        ...    
  23. ?>