Wednesday, June 2, 2010

One to Many question

Hello. I don't know if I'm doing things well, so I'll fire my
question.
I have a model relationship this way: Student hasMany ForeignSchool.
First, I'll show my scenario, files and relevant code, then I'll
explain the problem.

SCENARIO:
* Model file student.php (hasmany declaration):
var $hasMany = array(

'ForeignSchool' => array(

'className' => 'ForeignSchool',

'foreignKey' => 'student_id',

'dependent' => true,

),

);

* Model file foreign_school.php (belongsto declaration):
var $belongsTo = array(

'Student' => array(

'className' => 'Student',

'foreignKey' => 'student_id',

),

);

* Controller file students_controller.php (find call test):
$this->Student->id = 2; //test hard code
$foreignSchools = $this->Student->ForeignSchool->find('all');

$this->set(compact('foreignSchools'));


* And in the corresponding view file:
print_r($foreignSchools);

PROBLEM:
The call to print_r($foreignSchools) is showing all the foreign
schools but not the schools of the current Student. Is it something
I'm missing that is avoiding the "filtering" of the foreign schools
shown in the view?

Thanks a lot!

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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

No comments: