MO
Erro cadastro
Fechado
Pessoal estou numa fase péssima, por gentileza estou fazendo testes de cadastro para implementar em um sistema que estou fazendo. Eu fiz um cadastro pelo Studio
e está apresentando um erro, onde não existe nem o campo que ele apresenta, eu não estou conseguindo enxergar onde está o erro, segue o código e campos:
Model: CompFam
e está apresentando um erro, onde não existe nem o campo que ele apresenta, eu não estou conseguindo enxergar onde está o erro, segue o código e campos:
Model: CompFam
- <?php
- /**
- * CompFam Active Record
- * @author <your-name-here>
- */
- class CompFam extends TRecord
- {
- const TABLENAME = 'comp_fam';
- const PRIMARYKEY= 'id';
- const IDPOLICY = 'serial'; // {max, serial}
- private $tipo_nec_esp;
- private $ocupacaoprof;
- private $escolaridade;
- private $titulars;
- private $estado_civil;
- private $sitconjugal;
- private $situacao_trab;
- private $beneficio;
- private $tempo_trabalho;
- private $grauparent;
- private $renda_mensal;
- /**
- * Constructor method
- */
- public function __construct(2579 = NULL, $callObjectLoad = TRUE)
- {
- parent::__construct(2579, $callObjectLoad);
- parent::addAttribute('compf_nome');
- parent::addAttribute('compf_Idade');
- parent::addAttribute('compf_renda');
- parent::addAttribute('compf_valbenef');
- parent::addAttribute('compf_localtrabalho');
- parent::addAttribute('compf_titular_id');
- parent::addAttribute('compf_renda_comp_id');
- parent::addAttribute('compf_situacaotrab_id');
- parent::addAttribute('compf_escolaridade_id');
- parent::addAttribute('compf_ocupacaoprof_id');
- parent::addAttribute('compf_tipo_nec_esp_id');
- parent::addAttribute('compf_tempo_trabalho_id');
- parent::addAttribute('compf_renda_mensal_id');
- parent::addAttribute('compf_grauparent_id');
- parent::addAttribute('compf_estado_civil_id');
- parent::addAttribute('compf_sitconjugal_id');
- parent::addAttribute('compf_qualnecespecial');
- }
- /**
- * Method set_tipo_nec_esp
- * Sample of usage: $comp_fam->tipo_nec_esp = $object;
- * @param $object Instance of TipoNecEsp
- */
- public function set_tipo_nec_esp(TipoNecEsp $object)
- {
- $this->tipo_nec_esp = $object;
- $this->tipo_nec_esp_id = $object->id;
- }
- /**
- * Method get_tipo_nec_esp
- * Sample of usage: $comp_fam->tipo_nec_esp->attribute;
- * @returns TipoNecEsp instance
- */
- public function get_tipo_nec_esp()
- {
- // loads the associated object
- if (empty($this->tipo_nec_esp))
- $this->tipo_nec_esp = new TipoNecEsp($this->tipo_nec_esp_id);
- // returns the associated object
- return $this->tipo_nec_esp;
- }
- /**
- * Method set_ocupacaoprof
- * Sample of usage: $comp_fam->ocupacaoprof = $object;
- * @param $object Instance of Ocupacaoprof
- */
- public function set_ocupacaoprof(Ocupacaoprof $object)
- {
- $this->ocupacaoprof = $object;
- $this->ocupacaoprof_id = $object->id;
- }
- /**
- * Method get_ocupacaoprof
- * Sample of usage: $comp_fam->ocupacaoprof->attribute;
- * @returns Ocupacaoprof instance
- */
- public function get_ocupacaoprof()
- {
- // loads the associated object
- if (empty($this->ocupacaoprof))
- $this->ocupacaoprof = new Ocupacaoprof($this->ocupacaoprof_id);
- // returns the associated object
- return $this->ocupacaoprof;
- }
- /**
- * Method set_escolaridade
- * Sample of usage: $comp_fam->escolaridade = $object;
- * @param $object Instance of Escolaridade
- */
- public function set_escolaridade(Escolaridade $object)
- {
- $this->escolaridade = $object;
- $this->escolaridade_id = $object->id;
- }
- /**
- * Method get_escolaridade
- * Sample of usage: $comp_fam->escolaridade->attribute;
- * @returns Escolaridade instance
- */
- public function get_escolaridade()
- {
- // loads the associated object
- if (empty($this->escolaridade))
- $this->escolaridade = new Escolaridade($this->escolaridade_id);
- // returns the associated object
- return $this->escolaridade;
- }
- /**
- * Method addTitular
- * Add a Titular to the CompFam
- * @param $object Instance of Titular
- */
- public function addTitular(Titular $object)
- {
- $this->titulars[] = $object;
- }
- /**
- * Method getTitulars
- * Return the CompFam' Titular's
- * @return Collection of Titular
- */
- public function getTitulars()
- {
- return $this->titulars;
- }
- /**
- * Method set_estado_civil
- * Sample of usage: $comp_fam->estado_civil = $object;
- * @param $object Instance of EstadoCivil
- */
- public function set_estado_civil(EstadoCivil $object)
- {
- $this->estado_civil = $object;
- $this->estado_civil_id = $object->id;
- }
- /**
- * Method get_estado_civil
- * Sample of usage: $comp_fam->estado_civil->attribute;
- * @returns EstadoCivil instance
- */
- public function get_estado_civil()
- {
- // loads the associated object
- if (empty($this->estado_civil))
- $this->estado_civil = new EstadoCivil($this->estado_civil_id);
- // returns the associated object
- return $this->estado_civil;
- }
- /**
- * Method set_sitconjugal
- * Sample of usage: $comp_fam->sitconjugal = $object;
- * @param $object Instance of Sitconjugal
- */
- public function set_sitconjugal(Sitconjugal $object)
- {
- $this->sitconjugal = $object;
- $this->sitconjugal_id = $object->id;
- }
- /**
- * Method get_sitconjugal
- * Sample of usage: $comp_fam->sitconjugal->attribute;
- * @returns Sitconjugal instance
- */
- public function get_sitconjugal()
- {
- // loads the associated object
- if (empty($this->sitconjugal))
- $this->sitconjugal = new Sitconjugal($this->sitconjugal_id);
- // returns the associated object
- return $this->sitconjugal;
- }
- /**
- * Method set_situacao_trab
- * Sample of usage: $comp_fam->situacao_trab = $object;
- * @param $object Instance of SituacaoTrab
- */
- public function set_situacao_trab(SituacaoTrab $object)
- {
- $this->situacao_trab = $object;
- $this->situacao_trab_id = $object->id;
- }
- /**
- * Method get_situacao_trab
- * Sample of usage: $comp_fam->situacao_trab->attribute;
- * @returns SituacaoTrab instance
- */
- public function get_situacao_trab()
- {
- // loads the associated object
- if (empty($this->situacao_trab))
- $this->situacao_trab = new SituacaoTrab($this->situacao_trab_id);
- // returns the associated object
- return $this->situacao_trab;
- }
- /**
- * Method set_beneficio
- * Sample of usage: $comp_fam->beneficio = $object;
- * @param $object Instance of Beneficio
- */
- public function set_beneficio(Beneficio $object)
- {
- $this->beneficio = $object;
- $this->beneficio_id = $object->id;
- }
- /**
- * Method get_beneficio
- * Sample of usage: $comp_fam->beneficio->attribute;
- * @returns Beneficio instance
- */
- public function get_beneficio()
- {
- // loads the associated object
- if (empty($this->beneficio))
- $this->beneficio = new Beneficio($this->beneficio_id);
- // returns the associated object
- return $this->beneficio;
- }
- /**
- * Method set_tempo_trabalho
- * Sample of usage: $comp_fam->tempo_trabalho = $object;
- * @param $object Instance of TempoTrabalho
- */
- public function set_tempo_trabalho(TempoTrabalho $object)
- {
- $this->tempo_trabalho = $object;
- $this->tempo_trabalho_id = $object->id;
- }
- /**
- * Method get_tempo_trabalho
- * Sample of usage: $comp_fam->tempo_trabalho->attribute;
- * @returns TempoTrabalho instance
- */
- public function get_tempo_trabalho()
- {
- // loads the associated object
- if (empty($this->tempo_trabalho))
- $this->tempo_trabalho = new TempoTrabalho($this->tempo_trabalho_id);
- // returns the associated object
- return $this->tempo_trabalho;
- }
- /**
- * Method set_grauparent
- * Sample of usage: $comp_fam->grauparent = $object;
- * @param $object Instance of Grauparent
- */
- public function set_grauparent(Grauparent $object)
- {
- $this->grauparent = $object;
- $this->grauparent_id = $object->id;
- }
- /**
- * Method get_grauparent
- * Sample of usage: $comp_fam->grauparent->attribute;
- * @returns Grauparent instance
- */
- public function get_grauparent()
- {
- // loads the associated object
- if (empty($this->grauparent))
- $this->grauparent = new Grauparent($this->grauparent_id);
- // returns the associated object
- return $this->grauparent;
- }
- /**
- * Method set_renda_mensal
- * Sample of usage: $comp_fam->renda_mensal = $object;
- * @param $object Instance of RendaMensal
- */
- public function set_renda_mensal(RendaMensal $object)
- {
- $this->renda_mensal = $object;
- $this->renda_mensal_id = $object->id;
- }
- /**
- * Method get_renda_mensal
- * Sample of usage: $comp_fam->renda_mensal->attribute;
- * @returns RendaMensal instance
- */
- public function get_renda_mensal()
- {
- // loads the associated object
- if (empty($this->renda_mensal))
- $this->renda_mensal = new RendaMensal($this->renda_mensal_id);
- // returns the associated object
- return $this->renda_mensal;
- }
- /**
- * Reset aggregates
- */
- public function clearParts()
- {
- $this->titulars = array();
- }
- /**
- * Load the object and its aggregates
- * @param 2579 object ID
- */
- public function load(2579)
- {
- // load the related Titular objects
- $repository = new TRepository('Titular');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('comp_fam_id', '=', 2579));
- $this->titulars = $repository->load($criteria);
- // load the object itself
- return parent::load(2579);
- }
- /**
- * Store the object and its aggregates
- */
- public function store()
- {
- // store the object itself
- parent::store();
- // delete the related Titular objects
- $criteria = new TCriteria;
- $criteria->add(new TFilter('comp_fam_id', '=', $this->id));
- $repository = new TRepository('Titular');
- $repository->delete($criteria);
- // store the related Titular objects
- if ($this->titulars)
- {
- foreach ($this->titulars as $titular)
- {
- unset($titular->id);
- $titular->comp_fam_id = $this->id;
- $titular->store();
- }
- }
- }
- /**
- * Delete the object and its aggregates
- * @param 2579 object ID
- */
- public function delete(2579 = NULL)
- {
- 2579 = isset(2579) ? 2579 : $this->id;
- // delete the related Titular objects
- $repository = new TRepository('Titular');
- $criteria = new TCriteria;
- $criteria->add(new TFilter('comp_fam_id', '=', 2579));
- $repository->delete($criteria);
- // delete the object itself
- parent::delete(2579);
- }
- }
- Cadastro:
- <?php
- /**
- * CompFamForm Form
- * @author <your name here>
- */
- class CompFamForm extends TPage
- {
- protected $form; // form
- /**
- * Form constructor
- * @param $param Request
- */
- public function __construct( $param )
- {
- parent::__construct();
- // creates the form
- $this->form = new TQuickForm('form_CompFam');
- $this->form->class = 'tform'; // change CSS class
- $this->form->style = 'display: table;width:100%'; // change style
- // define the form title
- $this->form->setFormTitle('CompFam');
- // create the form fields
- 2579 = new TEntry('id');
- $compf_nome = new TEntry('compf_nome');
- $compf_Idade = new TEntry('compf_Idade');
- $compf_renda = new TEntry('compf_renda');
- $compf_valbenef = new TEntry('compf_valbenef');
- $compf_localtrabalho = new TEntry('compf_localtrabalho');
- $compf_titular_id = new TEntry('compf_titular_id');
- $compf_renda_comp_id = new TEntry('compf_renda_comp_id');
- $compf_situacaotrab_id = new TEntry('compf_situacaotrab_id');
- $compf_escolaridade_id = new TEntry('compf_escolaridade_id');
- $compf_ocupacaoprof_id = new TEntry('compf_ocupacaoprof_id');
- $compf_tipo_nec_esp_id = new TEntry('compf_tipo_nec_esp_id');
- $compf_tempo_trabalho_id = new TEntry('compf_tempo_trabalho_id');
- $compf_renda_mensal_id = new TEntry('compf_renda_mensal_id');
- $compf_grauparent_id = new TEntry('compf_grauparent_id');
- $compf_estado_civil_id = new TEntry('compf_estado_civil_id');
- $compf_sitconjugal_id = new TEntry('compf_sitconjugal_id');
- $compf_qualnecespecial = new TEntry('compf_qualnecespecial');
- // add the fields
- $this->form->addQuickField('Id', 2579, 100 );
- $this->form->addQuickField('Compf Nome', $compf_nome, 200 );
- $this->form->addQuickField('Compf Idade', $compf_Idade, 100 );
- $this->form->addQuickField('Compf Renda', $compf_renda, 100 );
- $this->form->addQuickField('Compf Valbenef', $compf_valbenef, 100 );
- $this->form->addQuickField('Compf Localtrabalho', $compf_localtrabalho, 200 );
- $this->form->addQuickField('Compf Titular Id', $compf_titular_id, 100 );
- $this->form->addQuickField('Compf Renda Comp Id', $compf_renda_comp_id, 100 );
- $this->form->addQuickField('Compf Situacaotrab Id', $compf_situacaotrab_id, 100 );
- $this->form->addQuickField('Compf Escolaridade Id', $compf_escolaridade_id, 100 );
- $this->form->addQuickField('Compf Ocupacaoprof Id', $compf_ocupacaoprof_id, 100 );
- $this->form->addQuickField('Compf Tipo Nec Esp Id', $compf_tipo_nec_esp_id, 100 );
- $this->form->addQuickField('Compf Tempo Trabalho Id', $compf_tempo_trabalho_id, 100 );
- $this->form->addQuickField('Compf Renda Mensal Id', $compf_renda_mensal_id, 100 );
- $this->form->addQuickField('Compf Grauparent Id', $compf_grauparent_id, 100 );
- $this->form->addQuickField('Compf Estado Civil Id', $compf_estado_civil_id, 100 );
- $this->form->addQuickField('Compf Sitconjugal Id', $compf_sitconjugal_id, 100 );
- $this->form->addQuickField('Compf Qualnecespecial', $compf_qualnecespecial, 200 );
- if (!empty(2579))
- {
- 2579->setEditable(FALSE);
- }
- /** samples
- $this->form->addQuickFields('Date', array($date1, new TLabel('to'), $date2)); // side by side fields
- $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
- $fieldX->setSize( 100, 40 ); // set size
- **/
- // create the form actions
- $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
- $this->form->addQuickAction(_t('New'), new TAction(array($this, 'onClear')), 'bs:plus-sign green');
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- /**
- * Save form data
- * @param $param Request
- */
- public function onSave( $param )
- {
- try
- {
- TTransaction::open('permission'); // open a transaction
- /**
- // Enable Debug logger for SQL operations inside the transaction
- TTransaction::setLogger(new TLoggerSTD); // standard output
- TTransaction::setLogger(new TLoggerTXT('log.txt')); // file
- **/
- $this->form->validate(); // validate form data
- $object = new CompFam; // create an empty object
- $data = $this->form->getData(); // get form data as array
- $object->fromArray( (array) $data); // load the object with data
- $object->store(); // save the object
- // get the generated id
- $data->id = $object->id;
- $this->form->setData($data); // fill form data
- TTransaction::close(); // close the transaction
- new TMessage('info', TAdiantiCoreTranslator::translate('Record saved'));
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- $this->form->setData( $this->form->getData() ); // keep form data
- TTransaction::rollback(); // undo all pending operations
- }
- }
- /**
- * Clear form data
- * @param $param Request
- */
- public function onClear( $param )
- {
- $this->form->clear();
- }
- /**
- * Load object to form data
- * @param $param Request
- */
- public function onEdit( $param )
- {
- try
- {
- if (isset($param['key']))
- {
- $key = $param['key']; // get the parameter $key
- TTransaction::open('permission'); // open a transaction
- $object = new CompFam($key); // instantiates the Active Record
- $this->form->setData($object); // fill the form
- TTransaction::close(); // close the transaction
- }
- else
- {
- $this->form->clear();
- }
- }
- catch (Exception $e) // in case of exception
- {
- new TMessage('error', $e->getMessage()); // shows the exception error message
- TTransaction::rollback(); // undo all pending operations
- }
- }
- }
- Tabela Mysql
- CREATE TABLE `comp_fam` (
- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
- `compf_nome` varchar(100) DEFAULT NULL,
- `compf_Idade` int(11) DEFAULT NULL,
- `compf_renda` float DEFAULT NULL,
- `compf_valbenef` float DEFAULT NULL,
- `compf_localtrabalho` varchar(100) DEFAULT NULL,
- `compf_titular_id` bigint(20) unsigned NOT NULL,
- `compf_renda_comp_id` bigint(20) unsigned NOT NULL,
- `compf_situacaotrab_id` int(11) NOT NULL,
- `compf_escolaridade_id` bigint(20) unsigned NOT NULL,
- `compf_ocupacaoprof_id` bigint(20) unsigned NOT NULL,
- `compf_tipo_nec_esp_id` bigint(20) unsigned NOT NULL,
- `compf_tempo_trabalho_id` bigint(20) unsigned NOT NULL,
- `compf_renda_mensal_id` bigint(20) unsigned NOT NULL,
- `compf_grauparent_id` bigint(20) unsigned NOT NULL,
- `compf_estado_civil_id` bigint(20) unsigned NOT NULL,
- `compf_sitconjugal_id` int(11) NOT NULL,
- `compf_qualnecespecial` varchar(100) DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `id` (`id`),
- KEY `fk_comp_fam_titular_idx` (`compf_titular_id`),
- KEY `fk_comp_fam_situacao_trab1_idx` (`compf_situacaotrab_id`),
- KEY `fk_comp_fam_escolaridade1_idx` (`compf_escolaridade_id`),
- KEY `fk_comp_fam_ocupacaoprof1_idx` (`compf_ocupacaoprof_id`),
- KEY `fk_comp_fam_tipo_nec_esp1_idx` (`compf_tipo_nec_esp_id`),
- KEY `fk_comp_fam_tempo_trabalho1_idx` (`compf_tempo_trabalho_id`),
- KEY `fk_comp_fam_renda_mensal1_idx` (`compf_renda_mensal_id`),
- KEY `fk_comp_fam_grauparent1_idx` (`compf_grauparent_id`),
- KEY `fk_comp_fam_estado_civil1_idx` (`compf_estado_civil_id`),
- KEY `sitconjugal_id` (`compf_sitconjugal_id`),
- KEY `renda_comp_id` (`compf_renda_comp_id`),
- CONSTRAINT `comp_fam_fk` FOREIGN KEY (`compf_sitconjugal_id`) REFERENCES `sitconjugal` (`id`),
- CONSTRAINT `fk_comp_fam_escolaridade1` FOREIGN KEY (`compf_escolaridade_id`) REFERENCES `escolaridade` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT `fk_comp_fam_estado_civil1` FOREIGN KEY (`compf_estado_civil_id`) REFERENCES `estado_civil` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT `fk_comp_fam_grauparent1` FOREIGN KEY (`compf_grauparent_id`) REFERENCES `grauparent` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT `fk_comp_fam_ocupacaoprof1` FOREIGN KEY (`compf_ocupacaoprof_id`) REFERENCES `ocupacaoprof` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT `fk_comp_fam_renda_comp1` FOREIGN KEY (`compf_renda_comp_id`) REFERENCES `renda_compl` (`id`),
- CONSTRAINT `fk_comp_fam_renda_mensal1` FOREIGN KEY (`compf_renda_mensal_id`) REFERENCES `renda_mensal` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT `fk_comp_fam_sittrabalhista1` FOREIGN KEY (`compf_situacaotrab_id`) REFERENCES `situacao_trab` (`id`),
- CONSTRAINT `fk_comp_fam_tempo_trabalho1` FOREIGN KEY (`compf_tempo_trabalho_id`) REFERENCES `tempo_trabalho` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT `fk_comp_fam_tipo_nec_esp1` FOREIGN KEY (`compf_tipo_nec_esp_id`) REFERENCES `tipo_nec_esp` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT `fk_comp_fam_titular` FOREIGN KEY (`compf_titular_id`) REFERENCES `titular` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- A tela de erro segue em anexo
Pelo que percebi, ao criar o model pelo Studio você criou um relacionamento com a tabela Titular. Por isso, sempre que você carrega um objeto do tipo CompFam, automicamente o model busca na tabela titular os itens relacionados. Veja o método load do model CompFam:
Se este relacionamento está correto, então sugiro que confira o nome da coluna 'comp_fam_id' do model Titular, pois é essa coluna que está sendo utilizada para realizar o filtro.