LT
OnEdit de uma tabela N:N.
Pessoal, estou com um problema que eu tenho tabelas N:N e um tabela para relaciona-las. Porem quando crio o onEdit ele esta trazendo o ID da tabela que relaciona e buscando na tabela PAI e por isso ele não encontra. O código do meu onEdit é este
public function onEdit($param)
{
try {
if (isset($param['key']))
{
TTransaction::open('mydb');
$herois = new herois($param['id']);
$herois_habilidades = $herois->belongsToMany('habilidades');
$nome_habilidade = [];
if ($herois_habilidades)
{
foreach ($herois_habilidades as $herois_habilidades)
{
$nome_habilidade[] = $herois_habilidades->habilidades_id;
}
}
$herois->nome_habilidade = $nome_habilidade;
$this->form->setData( $herois );
TTransaction::close();
}
else
{
$this->onClear($param);
}
}
catch (Exception $e)
{
new TMessage('error', $e->getMessage());
}
}
o erro que da é "objeto XX não encontrado"
XX= o id da tabela herois_habilidades
TABELAS:
HEROIS (1:N)->HEROIS_HABILIDADES<-(N:1) HABILIDADES
public function onEdit($param)
{
try {
if (isset($param['key']))
{
TTransaction::open('mydb');
$herois = new herois($param['id']);
$herois_habilidades = $herois->belongsToMany('habilidades');
$nome_habilidade = [];
if ($herois_habilidades)
{
foreach ($herois_habilidades as $herois_habilidades)
{
$nome_habilidade[] = $herois_habilidades->habilidades_id;
}
}
$herois->nome_habilidade = $nome_habilidade;
$this->form->setData( $herois );
TTransaction::close();
}
else
{
$this->onClear($param);
}
}
catch (Exception $e)
{
new TMessage('error', $e->getMessage());
}
}
o erro que da é "objeto XX não encontrado"
XX= o id da tabela herois_habilidades
TABELAS:
HEROIS (1:N)->HEROIS_HABILIDADES<-(N:1) HABILIDADES
É um formulário mestre x detalhe? O id passado para a função onEdit não deveria ser da tabela pai?
Nataniel, fiz o código abaixo para o OnEdit e deu certo.
public function onEdit($param)
{
try {
TTransaction::open('mydb');
if (isset($param['key'])) {
$key = $param['key'];
$obj = new herois($key);
$object = heroishabilidades::where('herois_id','=', $key)->load();
$chackbox = array();
if($object)
{
foreach( $object as $itens )
{
$chackbox[] = $itens->habilidades_id;
$chackbox->store();
}
}
$obj->habilidades_id = $chackbox;
$this->form->setData($obj);
TTransaction::close();
} else {
$this->form->clear(TRUE);
}
} catch (Exception $e) {
new TMessage('error', $e->getMessage());
TTransaction::rollback();
}
}