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 */