Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Paging a $many_many DataObjectSet

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

Page: 1
Go to End
Author Topic: 1276 Views
  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Paging a $many_many DataObjectSet Link to this post

    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

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Paging a $many_many DataObjectSet Link to this post

    You missed some backticks:

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

    1276 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.