summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/models/item.php13
1 files changed, 8 insertions, 5 deletions
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;
}
/**