When you say it doesnt work when adding a user, what actually happens? At a guess I would take a look at the fact your edit form has the Student ID's already assigned in the data array but obviously when adding students they're not assigned and therefore your $this->Subject- >Student->CourseMembership->saveAll() has no idea what student it is associating records to.
As you are saving the students as part of $this->Subject->saveAll() you have no way of then seperating the newly created student id's to inject them into the the data array before calling $this->Subject- >Student->CourseMembership->saveAll(). HTH, Paul. On Aug 16, 1:12 pm, Adexe Rivera <[email protected]> wrote: > Hi, > > I'm new on Cakephp, I trying use hasMany Through relationships, after > read this,http://book.cakephp.org/view/1650/hasMany-through-The-Join-Model. > > First of all, I have a model Subjects > > Subject hasMany Student > Student belongsTo Subject > > Now the problem, with hasMany through. > > Course hasMany Student > Student hasMany Course > CourseMembership belongsTo Course, Student > > In function add(), from subject controller, can't create N-students > with the existing N-courses. > > But in function edit(), works fine with this form, in view: > > echo $this->Form->create('Subject'); > > if($count < 3) > { > for($i=1; $i <= 2; $i++) > { > echo $this->Form->input('Student.' . $count . > '.CourseMembership.' . $i . '.course_id', array('type' => 'hidden', > 'value' => $i)); > echo $this->Form->input('Student.' . $count . > '.CourseMembership.' . $i . '.student_id', array('type' => 'hidden', > 'value' => $student['student']['id'])); > echo $this->Form->input('Student.' . $count . > '.CourseMembership.' . $i . '.hours', array('type' => 'hidden', > 'value' => 10)); > } > > } > > and controller: > > if (!empty($this->data)) { > if ($this->Subject->saveAll($this->data)) { > foreach ($this->data['Student'] as $value) { > if(!empty($value['CourseMembership'])) > > $this->Subject->Student->CourseMembership->saveAll($value['CourseMembership']); > > } > ... > > I need help. > > Thanks. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
