ที่จริงแล้วgetAllIdsเป็นวิธีที่ดีที่สุดในการทำมัน ตัวอย่างเช่นในโมเดลรีซอร์สคอลเล็กชันผลิตภัณฑ์เมธอดจะเป็นดังนี้:
public function getAllIds($limit = null, $offset = null)
{
$idsSelect = $this->_getClearSelect();
$idsSelect->columns('e.' . $this->getEntity()->getIdFieldName());
$idsSelect->limit($limit, $offset);
$idsSelect->resetJoinLeft();
return $this->getConnection()->fetchCol($idsSelect, $this->_bindParams);
}
ดังนั้นทุกอย่างจะถูกเรียกคืนจากการเลือกเพียงครั้งเดียวและไม่จำเป็นต้องทำซ้ำ ในรูปแบบทรัพยากรนามธรรมมันมีลักษณะเช่นนี้:
public function getAllIds()
{
$idsSelect = clone $this->getSelect();
$idsSelect->reset(Zend_Db_Select::ORDER);
$idsSelect->reset(Zend_Db_Select::LIMIT_COUNT);
$idsSelect->reset(Zend_Db_Select::LIMIT_OFFSET);
$idsSelect->reset(Zend_Db_Select::COLUMNS);
$idsSelect->columns($this->getResource()->getIdFieldName(), 'main_table');
return $this->getConnection()->fetchCol($idsSelect);
}
ดังนั้นทุกอย่างที่ขยายMage_Core_Model_Resource_Db_Collection_Abstractควรใช้สิ่งนี้เว้นแต่จะระบุไว้เป็นอย่างอื่น
วิธีที่คุณดูมาจากคลาสฐานVarien_Data_Collectionแต่มันถูกเขียนทับในลูกของมัน
$this->_getClearSelect()ดู