views:

10

answers:

0

Hi! I have 2 many-to-many tables and 1 association table for them:

1. Student
StudentID (PK)

2. NextOfKin
NextOfKin (PK)

3. StudentNextOfKin
StudentID, NextOfKinID (PK)
FK StudentID References Student(StudentID)
FK NextOfKinID References NextOfKin(NextOfKinID)

With the following codes, i am able to create a new NextOfKin record in DB. But the PK of both Student and the new NextOfKin is not added into the association table. Can anyone help?

$studentRecord = $this->StudentRecord;
$studentRecord->NextOfKin = new NextOfKinRecord;
//Populate other properties
//$studentRecord->NextOfKin->Name = $this->txtName->SafeText;
//$studentRecord->NextOfKin->ContactNumber = $this->txtContactNo->SafeText;

$studentRecord->NextOfKin->save();
$studentRecord->save();

My activerecord class for student:

class StudentRecord extends TActiveRecord
{
    const TABLE='Student';

    public $StudentID;
    //public $OtherProperties;

    public static function finder($className=__CLASS__)
    {
        return parent::finder($className);
    }

    public static $RELATIONS=array
    (
            'NextOfKin' => array(self::MANY_TO_MANY, 'NextOfKinRecord', 'StudentNextOfKin')
    );
}

My activerecord class for nextofkin:

class NextOfKinRecord extends TActiveRecord
{
    const TABLE='NextOfKin';

    public $NextOfKinID;
    //public $OtherProperties;


    public static function finder($className=__CLASS__)
    {
        return parent::finder($className);
    }

    public static $RELATIONS=array
    (
            'Students' => array(self::MANY_TO_MANY, 'StudentRecord', 'StudentNextOfKin')
    );

}