최근 Zend Framework (1.8.4)를 사용하여 장바구니 사이트의 주문을 볼 수있는 관리 도구를 제공하기 시작했습니다.Zend : 두 개의 객체, 하나의 행
하나의 데이터베이스 결과 행에서 여러 모델 (Zend_Db_Table_Row_Abstract
) 개체를 효율적으로 생성하고 싶습니다.
관계가 간단합니다 : 주문 고객 (외래 키 order_custid=customer.cust_id
); 고객에게 많은 주문이 있습니다.
주문로드 쉽습니다. 여기에 설명 된 방법을 사용하여 : Modeling objects with multiple table relationships in Zend Framework
... 나는 다음 각 고객을 잡을 수 있습니다.
foreach ($orderList as $o)
{
cust = $o->findParentRow('Customers');
print_r ($cust); // works as expected.
}
하지만 주문의 긴 목록을로드 할 때 -, 40 이상 말을하는 pageful -이 고통스럽게 느립니다.
는 다음 나는 시도한 가입 :
$custTable = new Customers();
$orderTable = new Orders();
$orderQuery = $orderTable->select()
->setIntegrityCheck(false) // allows joins
->from($orderTable)
->join('customers', 'cust_id=order_custid')
->where("order_status=?", 1); //incoming orders only.
$orders = $orderTable->fetchAll($orderQuery);
이 나를 위해 객체의 배열을 제공합니다. print_r($orders)
은 보호 된 멤버에서 원시 필드 이름이 order_ * 및 cust_ * 인 것으로 예상되는 열 목록을 각각 포함한다는 것을 보여줍니다.
그러나 각 Order 오브젝트에서 찾을 수있는 cust_ * 필드에서 Customer 오브젝트를 작성하는 방법은 무엇입니까?
foreach ($orders as $o) {
$cols = $o->toArray();
print_r ($cols); // looks good, has cust_* fields...
$cust = new Customer(array('table' => 'Customer', 'data' => $cols));
// fails - $cust->id, $cust->firstname, etc are empty
$cust->setFromArray($cols);
// complains about unknown 'order_' fields.
}
조인 된 행에서 Order와 Customer 개체를 동시에 만드는 좋은 방법이 있습니까? 또는 테이블 게이트웨이없이 쿼리를 실행하고 원시 결과 집합을 가져 와서 각 필드를 새로 만든 개체에 하나씩 복사해야합니까?
내가 아는 한 Zend_Db는 그렇게하지 않습니다. 나는 해결책에도 매우 관심이있다. – markus