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

Reply via email to