LT
OnSave nao esta gravando na tabela intermediaria.
Olá, pessoal
Eu tenho 3 tabelas, HEROIS(1:N)->HEROIS_HABILIDADES<-(N:1)HABILIDADES.
Criei o cadastro de herois e suas habilidades pré cadastradas. Quando criei o OnSave ele não esta gravando na tabela herois habilidades o herois_id e as habilidades_id , só esta gravando um novo heroi na tabela herois. Segue o OnSave:
public function onSave($param)
{
try {
TTransaction::open('mydb');
$this->form->validate();
$data = $this->form->getData();
$herois = new herois;
$herois->fromArray((array) $data);
$herois->store();
$data->id = $herois->id;
heroishabilidades::where('herois_id', '=', $herois->id)->delete();
$this->form->setData($data);
var_dump($data);
if (!empty($param['nome_habilidade'])) {
foreach ($param['nome_habilidade'] as $habilidades_id) {
$herois_habilidades = new heroishabilidades;
$herois_habilidades->habilidades_id = $habilidades_id;
$herois_habilidades->herois_id = $herois->id;
$herois_habilidades->store();
}
}
TTransaction::close();
Eu tenho 3 tabelas, HEROIS(1:N)->HEROIS_HABILIDADES<-(N:1)HABILIDADES.
Criei o cadastro de herois e suas habilidades pré cadastradas. Quando criei o OnSave ele não esta gravando na tabela herois habilidades o herois_id e as habilidades_id , só esta gravando um novo heroi na tabela herois. Segue o OnSave:
public function onSave($param)
{
try {
TTransaction::open('mydb');
$this->form->validate();
$data = $this->form->getData();
$herois = new herois;
$herois->fromArray((array) $data);
$herois->store();
$data->id = $herois->id;
heroishabilidades::where('herois_id', '=', $herois->id)->delete();
$this->form->setData($data);
var_dump($data);
if (!empty($param['nome_habilidade'])) {
foreach ($param['nome_habilidade'] as $habilidades_id) {
$herois_habilidades = new heroishabilidades;
$herois_habilidades->habilidades_id = $habilidades_id;
$herois_habilidades->herois_id = $herois->id;
$herois_habilidades->store();
}
}
TTransaction::close();
Qual o conteúdo de $param['nome_habilidade']? Faça um var_dump ou print e poste aqui.
Analise também o log de sql. Use o comando abaixo logo após abrir a transação: