Relational Data In Cgridview

I’m mountaineering up the Yii learning curve here… The ‘Y’ in Yii stands for Yodel right!? :lol:

I have two tables, and i want to show the description from one which relates to the value of another.

Model: LeadTypes

Table: lead_types

  • id (int)[pk]

  • group (int)

  • description (varchar)




id  |  group  |  description

--------------------------

1   |    0    |   something0

2   |    1    |   something2

3   |    2    |   something3



Model: Leads

Table: leads

  • id (int)

  • id_lead (int)[pk]

  • lead_type (int) [0,1,2]

‘lead_type_name_rel’=>array(self::BELONGS_TO, ‘LeadTypes’, ‘group’),

In the Leads grid view, I want to show LeadTypes.description where Leads.lead_type == LeadTypes.group

I’ve used BELONGS_TO etc for other things but they all have PK’s on ID, I thinkk this is causing me a problem… and im getting myself really confused. it IS showing the description, but linking to the Lead.id rather than Lead.lead_type

[color="#1C2837"][size="2"]Start with a simple example which is working and then try to modify it to your needs.[/size][/color]

[color="#1C2837"][size="2"]Guide - Declaring Relationship[/size][/color]

OK,

so… I think its working now (after a day of playing and resisting posting on here)

I deleted the lead_type.id [AI PK] and made lead_type.group the PK so this feels dirty but its working.

:angry: :D :o :-X :lol: is how i feel.