Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Query multiple page classes for pagination - can't merge DataObjectSets?

Go to End

2 Posts   746 Views


Community Member, 59 Posts

2 November 2011 at 2:09am

Edited: 02/11/2011 2:15am


In the course of a project, due to poor planning we added two unrelated page types, VideoPage and ArticlePage that both have a YouTube string holding the YouTube ID. ArticlePage, the newer one was added later for some content purposes and -could- absorb a VideoPage (it has more variables, but the video variable is the same and really for the client's workflow, it would be a hindrance AND more than 200 VideoPages are already live and still being added to some sections. Also the holder pages function with them as well.

Now. On a particular page I need to aggregate both these page types to show ALL the pages where the YouTube string isn't empty - that means, ArticlePages and VideoPages, and the dataobjectset needs to be paginated.

I was thinking first to migrate the old page type into the new one. Due to the live and draft stages and the fragile SiteTree table this sounds like a bit of a dangerous task. The VideoPages either wouldn't be in the ArticlePage tables or I would lose the video variable if changing the class type.

So now I am guessing a custom SQL query will do. How can I select VideoPages and ArticlePages WHERE Video!="" but still preserve the pagination capabilities? Merging dataobjectsets therefore doesn't work.


class VideoPage extends Page {

	 static $db = array(
	 	"YouTube" => "Varchar(255)"



class ArticlePage extends Page implements PermissionProvider {

	static $db = array(
		"YouTube" => "Varchar(255)",


class PhotoVideoCollector extends Page {


function getPaginatedVideos() { 
	if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0; 
	$SQL_start = (int)$_GET['start']; 
	if(!isset($this->NumberItems) || $this->NumberItems<=0) {
	else {
		$n= $this->NumberItems;
	return $this->getAllVideos($SQL_start,$n);

public function getAllVideos($start=0,$n=0, $random=false) {
		if($random) {
		else {
			$sort = "Created DESC";
		$doSet = DataObject::get( 
			$callerClass = "VideoPage", 
			$filter = "YouTube !=''",
			$join = "", 
			$limit = "{$start},$n"
		return $doSet ? $doSet : false;

Thanks for any insight!


Forum Moderator, 1848 Posts

2 November 2011 at 3:35am