[SOLVED] Relations between tables/models

Hi all,

I’m having a complete brain fart here and can’t seem to work this out, I’ve read through countless topics about relations and I’ve got them all working but this one, and I think it’s a really simple one too.

I have two tables, ‘tbl_events’ and ‘tbl_reason_codes’ as such:

tbl_events:


id    user_id    reason

1       10         1

2       10         2

3       24         1

tbl_reason_codes:


reason    reason_text

1         Foo

2         Bar

3         FooBar

I am trying to access the ‘reason_text’ value for each ‘reason’ in the tbl_events table. At the moment for my relations in the models I have:


class Events

{

    ...

    public function relations()

    {

        return array(

            'reasonList'=>array(self::HAS_ONE, 'ReasonCodes', 'reason'),

	);

    }

    ...

}


class ReasonCodes{

    ...

    public function relations()

    {

        return array(

            'reason'=>array(self::BELONGS_TO, 'Events', 'reason'),

	);

    }

    ...

}

In the hope of accessing the reason code text for each model using something like:


$EventModel->reasonList->reason_text;

So in the above table example, I could load the row with Pk 1 into $EventModel and $EventModel->ReasonList->reason_text would equal "Foo".

But no luck so far!

Any help would be much appreciated!

Thanks,

Stu

Events BELONGS_TO ReasonCodes and ReasonCodes HAS_MANY Events.

Thank you, I knew it was something simple like that I just had a total mind block!!!

Cheers,

Stu