Hey guys
How can I use grid and filter in that condition:
are 4 tables, country , state , city and user
country(id, country_name)
state (id, country_id, state_name)
city (id, state_id, city_name)
user (id, city_id, fields…)
Country model relations
return array(
'states' => array(self::HAS_MANY, 'State', 'country_id'),
);
State relations
return array(
'countries' => array(self::BELONGS_TO, 'Country', 'country_id'),
'cities' => array(self::HAS_MANY, 'City', 'state_id'),
);
City relations
return array(
'states' => array(self::BELONGS_TO, 'State', 'state_id'),
'users' => array(self::HAS_MANY, 'User', 'city_id'),
);
User relations
return array(
'cities' => array(self::BELONGS_TO, 'City', 'city_id'),
);
How can I bring on User grid, the fields country and state also, and how can I apply filters? I want to filters users by country… or filter by state … or in City grid filter by country also…
anyone know how if is possible using CGridView?
a simple equivalent query:
SELECT fields FROM user
JOIN city ON city.id=user.city_id
JOIN state ON state.id=city.state_id
JOIN country on country.id=state.country_id