I've found a solution for this problem in the Internet. Now, I can save 
model Trivia and its related objectsTrivia Pregunta, but saveAll does 
not save the related objects TriviaOpcion for each TriviaPregunta

somebody can help me?

José Selesán escribió:
> Hi people. I have an issue saving a model and its related models.
> I have thre tables:
> - trivias(id, titulo)
> - trivia_preguntas(id, trivia_id, texto)
> - trivia_opciones(id, pregunta_id, texto, correcta)
>
> And the corresponding models:
>
> class Trivia extends AppModel
> {
>    var $name = 'Trivia';
>    var $transactional = true;
>    var $hasMany = array('Preguntas' =>
>                       array('className' => 'TriviaPregunta',
>                             'foreignKey' => 'trivia_id')
>                    );   }
>
> class TriviaPregunta extends AppModel
> {
>    var $name = 'TriviaPregunta';
>
>    var $belongsTo = array('Trivia' =>
>                                        array('className' => 'Trivia',
>                                                    'foreignKey' => 
> 'trivia_id')
>                                    );
>                                     var $hasMany = array('Opciones' =>
>                       array('className' => 'TriviaOpcion',
>                             'foreignKey' => 'pregunta_id')
>                    );                     }
>
> class TriviaOpcion extends AppModel
> {
>    var $name = 'TriviaOpcion';
>                                      var $belongsTo = array('Pregunta' =>
>                                        array('className' => 
> 'TriviaPregunta',
>                                                    'foreignKey' => 
> 'pregunta_id')
>                                    );              }
>
> The problem is that when I call $this->Trivia->saveAll($this->data), I 
> get this error message:
> "Field 'trivia_id doesn't have a default value" and if I look at the 
> SQL instructions I realize that Cake is not associating the inserted 
> id for model trivia with the trivia_id field in the table 'preguntas' 
> (Cake tries to execute "INSERT INTO trivia_preguntas (texto) VALUES 
> ('pregunta 1')")
>
> What can I do to save my model and their related models?
>
> Thanks in advance
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to