From 4485a66b3e2be41a2bfb210a869e16b536b8038d Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 9 May 2009 05:28:35 +0000 Subject: Fix for ticket #255 --- core/models/item.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'core/models') diff --git a/core/models/item.php b/core/models/item.php index 40a209f6..863d055f 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -327,11 +327,14 @@ class Item_Model extends ORM_MPTT { * the first child in the album is at position 1. */ public function get_position($child_id) { - return ORM::factory("item") - ->where("parent_id", $this->id) - ->where("id <=", $child_id) - ->orderby(array($this->sort_column => $this->sort_order)) - ->count_all(); + $result = Database::instance()->query(" + SELECT COUNT(*) AS position FROM {items} + WHERE parent_id = {$this->parent_id} + AND {$this->sort_column} <= (SELECT {$this->sort_column} + FROM {items} WHERE id = $child_id) + ORDER BY {$this->sort_column} {$this->sort_order}"); + + return $result->position; } /** -- cgit v1.2.3