Jump to:

3430 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » get random object

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

Page: 1
Go to End
Author Topic: 2568 Views
  • snaip
    Avatar
    Community Member
    180 Posts

    get random object Link to this post

    i need to get 4 random objects from database

    $Randomelements = DataObject::get(
    $callerClass = "PLWycieczkaPage",
    $filter = "Display = 'ON'",
    $sort = "",
    $join = "",
    $limit = 4
    );
    return $Randomelements;

    how to add RAND() to this code ?

    sec question

    how to execute in the same time two objects ?

    $Staticelements = DataObject::get(
    $callerClass = "ENWycieczkaPage",
    $filter = "Display = 'always'",
    $sort = "",
    $join = "",
    $limit = ""
    );
    return $Staticelements;

    $Randomelements = DataObject::get(
    $callerClass = "PLWycieczkaPage",
    $filter = "Display = 'sometimes'",
    $sort = "",
    $join = "",
    $limit = 4
    );
    return $Randomelements;

    in this way only "return $Staticelement" works but it stop executing "return $Randomelements"

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: get random object Link to this post

    ??

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: get random object Link to this post

    AD 2)

    $doSet1->merge($doSet2);
    return $doSet1;

    what about RAND() function in DataObject::get ?

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: get random object Link to this post

    $Randomelements = DataObject::get(
    $callerClass = "PLWycieczkaPage",
    $filter = "Display = 'sometimes'",
    $sort = "RAND()",
    $join = "",
    $limit = 4
    );

    ehhhh :/

    2568 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.