Yii Framework Forum: Model Relation with composite key - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Model Relation with composite key Rate Topic: ***** 1 Votes

#1 User is offline   Wenceslaus D'silva 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 01-November 10
  • Location:Mumbai, India

Posted 17 April 2011 - 05:38 AM

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
0

#2 User is offline   Wenceslaus D'silva 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 01-November 10
  • Location:Mumbai, India

Posted 18 April 2011 - 02:55 AM

View PostWenceslaus 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

*bump*
0

#3 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

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"
0

#4 User is offline   rajesh chaurasia 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 12-January 13
  • Location:Mohali

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)'),
);
}
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users