Tuesday, September 2, 2014

cakephp how to find a field that is joined by related tables

I am new to cakephp and having problem in solving the Class and Subject
relations.

I have three tables:

**studclass** **subjectclass** **subject**
id id id
class_name studclassID(foreignKey)
subject_name
subjectID(foreignKey)
Relationship:

(Studclass Model)

public $hasMany = array(
'ClassSubjects' => array(
'className' => 'SubjectClass',
'foreignKey' => 'classID',
)
);
(Subject Model)

public $hasMany = array(
'SubjectsClass' => array(
'className' => 'SubjectClass',
'foreignKey' => 'subjectID',
)
);
(SubjectClass Model)

public $belongsTo = array(
'Studclass' => array(
'className' => 'Studclass',
'foreignKey' => 'classID'
),
'Subject' => array(
'className' => 'Subject',
'foreignKey' => 'subjectID'
));
Array Generated by Studclass View:

array(
'Sclass' => array(
'id' => '1',
'class_name' => 'BCA1'
),
'ClassSubjects' => array(
(int) 0 => array(
'id' => '1',
'subjectID' => '1',
'classID' => '1'
),
(int) 1 => array(
'id' => '2',
'subjectID' => '2',
'classID' => '1'
),
(int) 2 => array(
'id' => '3',
'subjectID' => '3',
'classID' => '1'
)
)
)

so what I want is instead of SubjectID in Studclass view I want to display
subject_name.....can any one help me how to do that...I am new to cakephp
and having hard time dealing with it...Thanks in advance



--
View this message in context: http://cakephp.1045679.n5.nabble.com/cakephp-how-to-find-a-field-that-is-joined-by-related-tables-tp5719481.html
Sent from the CakePHP mailing list archive at Nabble.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: