Hi All,
I need help in creating a model relation to a table with composite key.
Scenario:-
Table 1.
id (primary)
level
Table 2.
id (primary)
program
Table 3.
id (primary)
section
table 4.
id (primary)
user
table 5.
id (primary)
year
table 6.
id (primary)
term
Table 7.
id (primary)
levelId, (FK)
programId, (FK)
sectionId, (FK)
userId, (FK)
yearId (FK)
valid
Table 8.
userId, programId, sectionId, termId, yearId (composite key)
Grade
Now
I am calling the Table 7 model data and getting all the info, foreach user i need the grade based on the composite key in Table 8.
How can i make a relation to get the info.
Kindly help!!!!
Regards,
Wenceslaus D'silva
Page 1 of 1
Model Relation with composite key
#2
Posted 18 April 2011 - 02:55 AM
Wenceslaus D, on 17 April 2011 - 05:38 AM, said:
Hi All,
I need help in creating a model relation to a table with composite key.
Scenario:-
Table 1.
id (primary)
level
Table 2.
id (primary)
program
Table 3.
id (primary)
section
table 4.
id (primary)
user
table 5.
id (primary)
year
table 6.
id (primary)
term
Table 7.
id (primary)
levelId, (FK)
programId, (FK)
sectionId, (FK)
userId, (FK)
yearId (FK)
valid
Table 8.
userId, programId, sectionId, termId, yearId (composite key)
Grade
Now
I am calling the Table 7 model data and getting all the info, foreach user i need the grade based on the composite key in Table 8.
How can i make a relation to get the info.
Kindly help!!!!
Regards,
Wenceslaus D'silva
I need help in creating a model relation to a table with composite key.
Scenario:-
Table 1.
id (primary)
level
Table 2.
id (primary)
program
Table 3.
id (primary)
section
table 4.
id (primary)
user
table 5.
id (primary)
year
table 6.
id (primary)
term
Table 7.
id (primary)
levelId, (FK)
programId, (FK)
sectionId, (FK)
userId, (FK)
yearId (FK)
valid
Table 8.
userId, programId, sectionId, termId, yearId (composite key)
Grade
Now
I am calling the Table 7 model data and getting all the info, foreach user i need the grade based on the composite key in Table 8.
How can i make a relation to get the info.
Kindly help!!!!
Regards,
Wenceslaus D'silva
*bump*
#3
Posted 18 April 2011 - 07:57 AM
Add this to your Model:
public function primaryKey()
{
return array('userId', 'programId', 'sectionId', 'termId', 'yearId');
}
"Less noise - more signal"
#4
Posted 17 March 2013 - 11:51 PM
hi i have used in my relation
public function relations() {
return array(
'relation name' => array(self::MANY_MANY, 'User(relate table)', '{{table name(composite table)}}(column1, column2)'),
);
}
public function relations() {
return array(
'relation name' => array(self::MANY_MANY, 'User(relate table)', '{{table name(composite table)}}(column1, column2)'),
);
}
Share this topic:
Page 1 of 1

Help











