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 /

DataObject::get() - all but latest


Reply


4 Posts   685 Views

Avatar
Mackodlak

Community Member, 95 Posts

27 September 2011 at 7:19pm

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!

Avatar
martimiz

Forum Moderator, 1132 Posts

28 September 2011 at 1:00am

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

Avatar
Ryan M.

Community Member, 309 Posts

28 September 2011 at 9:02am

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.

Avatar
Mackodlak

Community Member, 95 Posts

28 September 2011 at 8:42pm

Edited: 28/09/2011 9:47pm

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?