Relation between tables without primary key

217 views Asked by At

Two tables 1 and 2, where id_schedule in 2 table is not primary key:

enter image description here

Task is to get the dates from table 2. I have the following code:

public function relations()
{
    return array(
        'scheduleTitles' => array(self::BELONGS_TO, 'ObjectScheduleTranslate', 'id'),
        'scheduleDates'  => array(self::BELONGS_TO, 'ObjectScheduleDate', array('id' => 'id_schedule'))
    );
}

OK, first relation works well, second (for this task, exactly) returns only one record (this one 2013-12-30 00:00:00)which is first in screen.

Trying to use another approach, I coded the relation in first model:

'scheduleDates'  => array(self::BELONGS_TO, 'ObjectScheduleDate', 'id')

at second model:

'scheduleDatesId' => array(self::HAS_MANY, 'ObjectSchedule', 'id_schedule')

which returns my empty set.

What am I doing wrong ?

0

There are 0 answers