New to Yii, but loving it so far. Basically I’m doing a real-estate type site where I have the following Models:
Property - Contains info such as address, name, owner information etc. (HAS_MANY Listing)
Listing - contains info such as price, number bedrooms, number bathrooms.
Property for instance would be an apartment building, and the listings would be a 1 bedroom 1 bathroom option or a 3 bedroom, 2 bath option.
So I’m trying to apply some filtering functionality to the Property index such that I can only show Properties that have listings with a specified number of bedrooms and bathrooms etc.
So far I’ve managed to get most of the way towards the filtering using some custom scopes as follows. (Property.min_price and Property.max_price being updated when listings are created/updated/deleted)
$properties = Property::model()->isVisible()->ofType($search_type)->minPrice($min_price)->maxPrice($max_price)->findAll($criteria);
but after staring at the problem for a few hours its still beyond me how to work in filtering properties based on it’s children’s # bedrooms and bathrooms. Any ideas?