Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DataObject::get() - all but latest

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

Page: 1
Go to End
Author Topic: 586 Views
  • Mackodlak
    Avatar
    Community Member
    95 Posts

    DataObject::get() - all but latest Link to this post

    Hello,
    as the title says, I need to form a DataObject::get() query with filter so that it gets all of the objects in a table except the latest entry, which is shown in a different place (so there is no repeat).

    Thank you all!

  • martimiz
    Avatar
    Forum Moderator
    1067 Posts

    Re: DataObject::get() - all but latest Link to this post

    After you retrieved the latest, you could use its ID to filter the others, as in "where ID IS NOT $LatestID"...

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: DataObject::get() - all but latest Link to this post

    What I would do is use DataObject::get with a Created DESC filter then use array_splice to knock off the last or first item.

  • Mackodlak
    Avatar
    Community Member
    95 Posts

    Re: DataObject::get() - all but latest Link to this post

    Yeah, well the thing is it is a list of DataObjects where there are DataObjects constantly being added so the ID of the latest object is constantly changing and I don't see it as a good solution.
    Array_slice might work, I will try that.
    The thing is, what I've seen be4, there is a way to do it through limit field. I've been using it be4 in a way that first argument is the number of objects you wanna skip and then the second argument is the number of them you wanna take after you skip the first number of objects.
    The pagination is working in exactly the same way. So, since I AM actually going to use pagination for them, I thougth it would be enough to set $SQL_start = 1 and then it should skip the first one (being $SQL_start = 0) and use the next 14 and then it should work well from there on. For some reason putting function getObjects ($SQL_start = 1, $paginLimit = 14) {... doesn't do it, tbh I don't understand why.

    Be4, as I have said, in another function - let's call it:

    function getOtherObjects ($skip, $num) {

          $kr = DataObject::get_one("Holder");
          $objects = ($kr) ? DataObject::get("myDataObject", "ParentID = $kr->ID", "Date DESC", "", $skip.','.$num) : false;
          return $objects;
       
       }

    it worked... I am not sure what is going on here.

    EDIT: come to think of it, wouldn't array slice do the same thing with every pagionation section? wouldn't it leave out the latest dataobject on every page?

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