0
votes

I have a Provider model which has 4 has_one relationships with Category, Country, State and City.

I use find_all to ge a list of all the providers, but need to be able to filter them by category, country, state and/or city by their name.

How would I, for example, get a list of the providers in US? The providers table has a foreign key to the countries table and that table has the name of the countries.

Thanks.

1

1 Answers

0
votes

filtering by country

$country = ORM::factory('Country',$country_id);
$providers_by_country = $country->providers->find_all()->as_array();

filtering by category

$category = ORM::factory('Category',category_id);
$providers_by_category = $category->providers->find_all()->as_array();

Then, you can merge both arrays to get a full list of providers filtered by country and category