J
J
jeston2014-01-22 20:39:19
Yii
jeston, 2014-01-22 20:39:19

How to implement linking Yii tables not by primary key?

I have two tables No. 1 ObjectSchedule and No. 2 ObjectScheduleDate, the relationship between them
YFbtV.png
I want to get the id_schedule associated with it in No. 2, which is not the primary key, by id in No. 1.
I write the following code in the model for #1 ObjectSchedule:

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

similarly for #2 ObjectScheduleDate:
return array(
                     'scheduleDatesId' => array(self::HAS_ONE, 'ObjectSchedule', 'id_schedule'),
                    );

As a result, I get nothing, an empty answer. OK, I'm a little more sophisticated, I write like this:
return array(
                     
                      'scheduleDates'  => array(self::BELONGS_TO, 'ObjectScheduleDate',  array('id' => 'id_schedule'))
                    );

So I get only the first record with the date (which I noted on the screen) instead of three.
I'm confused and asking for help.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rowdy Ro, 2014-01-22
@rowdyro

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question