summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-05-09 05:28:35 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-05-09 05:28:35 +0000
commit4485a66b3e2be41a2bfb210a869e16b536b8038d (patch)
treede1931c54429637b266ff63e0713a5964001c0fb /core
parentcdc796aed46093c50c85910a8acc1cb28f8b4a35 (diff)
Fix for ticket #255
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;
}
/**