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, biapar, Willr, Ingo, swaiba

Paging a $many_many DataObjectSet


Go to End
Reply


2 Posts   1535 Views

Avatar
NickJacobs

Community Member, 146 Posts

12 February 2010 at 3:27pm

Edited: 12/02/2010 5:19pm

Hi, I have a couple of related pagetypes which I need to draw dataObjectSets from and paginate the results:

BrandCategoryPage.php

class BrandCategoryPage extends Page {
   	
	static $many_many = array('BrandPages' => 'BrandPage');
	
}

function getCMSFields() {
   $f = parent::getCMSFields();
    
   $areasTablefield = new ManyManyComplexTableField(
         $this,
         'BrandPages',
         'BrandPage',
         array(
	    'Title' => 'Title'
         ),
         'getCMSFields_forPopup'
      );
        $areasTablefield->setAddTitle( 'Brands' );
	$f->addFieldToTab( 'Root.Content.Brands', $areasTablefield );
      	
   return $f;
}

and BrandPage.php

class BrandPage extends Page {
   
   static $has_one = array(
   'Logo' => 'Image'
   );
   
   static $belongs_many_many = array(
    "BrandCategoryPages" => "BrandCategoryPage"
  );
  
 
   function getCMSFields() {
   $f = parent::getCMSFields();
   $f->addFieldToTab("Root.Content.Images", new ImageField('Logo'));
    	
   return $f;
}

what i wanted to do was something like this:

function BrandPages_Paged() {
  if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
  $SQL_start = (int)$_GET['start'];
  $doSet = DataObject::get(
    $callerClass = "BrandPage",
    $filter = "BrandCategoryID=$this->ID",
    $sort = "",
    $join = "",
    $limit = "{$SQL_start},2"
  );
 
  return $doSet ? $doSet : false;
}

but this throws errors....

Anyone know how I can relate back to the category this way?

Cheers

Avatar
baba-papa

Community Member, 279 Posts

15 February 2010 at 12:48pm

You missed some backticks:

$filter = "`BrandCategoryID`=$this->ID"