I have a model - "Category" which HABTM "Blog". I need to create a query that will only select categories that have more zero blogs associated with them. I'm having t开发者_高级运维rouble working out how to do this. All I've come up with is getting the categories out of the database using find('all'...) and then extracting those that have something in the $category['Blog'] array. Obviously I'd much prefer to not have to ask the database to do all that work, so a more elegant solution would be much appreciated.
Thanks for reading!
not really elegant (short), but I think this is the correct way:
- add a
blogs_category_count
field to categories table - add Category hasMany BLogsCategory with counterCache
so you just have to add a condition to that find('all')
精彩评论