3062 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 362 Views |
-
Returning Categories with at least one Article: better, prettier way?

4 February 2011 at 11:40am Last edited: 4 February 2011 11:43am
Hi,
I was wondering what would be the best way of getting all records of a model with at least one of an associated model, in a one-to-many relationship.
In this particular example, I'm trying to get a list of all news categories that contain at least one article, filtering out empty categories.
Could I streamline the following in any way using DataObject?
DataObject::get("NewsCategory", "EXISTS (SELECT 1 FROM Article WHERE SiteTree_Live.ID = NewsCategoryID)")
(NewsCategory extends Page, SiteTree)
| 362 Views | ||
|
Page:
1
|
Go to Top |

