Advance table relations

Hi, I need some help managing some advance table relations.

I have used simpler relations before so I know how it works, maybe it’s easier than it looks?

The table "Swim_Club" contains information about swimteams.

Here is the SQL query displaying information about a specific team with an id of 184.




SELECT     Swim_Club.name AS ClubName, Club_Group.name AS GroupName, Club_Group.club_group_type, Swim_Club.swim_club_id

FROM         Club_Group_Content INNER JOIN Club_Group ON Club_Group_Content.group_id = Club_Group.club_group_id 

        INNER JOIN Swim_Club ON Club_Group_Content.swim_club_id = Swim_Club.swim_club_id

WHERE     (Club_Group.club_group_type = 1 OR Club_Group.club_group_type = 2) AND (Swim_Club.swim_club_id = 184)



How can I put this up in the models and displaying it in a CGridview?

this is not so advanced, is a simply access to a relation (a "table") data with inner relations…

to solve your question:

[list=1][]first at all, create a new view in your db model as i show at bottom.[]using Gii, create a new Model for your new view named: "VClubFiltered"[*]use Yii over this view as normal as other models.[/list]

create a view on db model:





create view VClubFiltered(name, groupname, grouptype, clubid) as

SELECT 	

	Swim_Club.name AS ClubName, Club_Group.name AS GroupName, Club_Group.club_group_type, Swim_Club.swim_club_id

FROM     	

	Club_Group_Content INNER JOIN Club_Group ON Club_Group_Content.group_id = Club_Group.club_group_id 

INNER JOIN 

	Swim_Club ON Club_Group_Content.swim_club_id = Swim_Club.swim_club_id;


  /* please note the absent value for WHERE clause */




I don’t fully understand, im not very good at handeling the commandline.

I Have currently created the Swim_Club table with the crud generator.

The easiest way for me would be to specify the relations in the model created för Swim_Club, the problem is that when I create the first relation:


'clubgroupcontent' => array(self::BELONGS_TO, 'ClubGroupContent', 'swim_club_id')

it says "Trying to get property of non-object"

Is there a way to run that sql query this way instead?