Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Random Items from DOM (Only from published pages)

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1199 Views
  • drye
    Community Member
    49 Posts

    Random Items from DOM (Only from published pages) Link to this post

    I'm trying to get some random products from a DOM, however I want them to only be from currently published pages.

    RIght now I have this:

       public function getSpecialItems($limit)
        //DataObject::get($obj, $filter, $sort, $join, $limit);
        return DataObject::get("SpecialItem","SpecialHolderID != 5","RAND()","",$limit);

    Because my SpecialHolder with ID 5 isn't published and I don't want the results to include it. I'd rather this be more automatic and not hard coded. Any thoughts?

  • UncleCheese
    4085 Posts

    Re: Random Items from DOM (Only from published pages) Link to this post

    You need to use a join.

    return DataObject::get(
    "INNER JOIN `SpecialHolder` ON `SpecialHolder`ID = SpecialItem.SpecialHolderID",

    It should automatically add the "_Live" suffix to SpecialHolder table, which will nullify the SpecialItem records that aren't attached to a _Live table.

    Probably not the best way to do that, though.

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.