Fixed duplicate row entries and other paginate issues. The fix might be a hack, but it works for now.

git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@23 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-05-28 09:07:53 +00:00
parent 8393403443
commit 7433e6868c
2 changed files with 27 additions and 7 deletions

View File

@@ -13,17 +13,24 @@ class ContactsController extends AppController {
function current() {
$this->Contact->recursive = 0;
$this->set('contacts', $this->paginate(array('Lease.closed_date IS NULL',
//'Contact.'
)));
$this->Contact->bindModel(array('hasOne' => array('ContactsLease',
'Lease' => array(
'foreignKey' => false,
'conditions' => array('Lease.id = ContactsLease.lease_id')
))),
false);
$this->set('contacts', $this->paginate(array('Lease.close_date IS NULL',
'ContactsLease.type != "ALTERNATE"')));
$this->render('index');
}
function all() {
$this->Contact->recursive = 2;
//$contacts = $this->paginate();
$this->set('contacts', $this->paginate());
$this->Contact->recursive = 0;
$this->Contact->bindModel(array('hasOne' => array('ContactsLease')),
false);
$this->set('contacts', $this->paginate(array('ContactsLease.type != "ALTERNATE"')));
$this->render('index');
}

View File

@@ -72,5 +72,18 @@ class Contact extends AppModel {
),
);
// Overriding pagination, since the controller using HABTM joins that
// result in duplicate rows. This may not be the best way to handle
// things (especially if the query return a really large number of rows,
// but it does seem to work.
function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null) {
$conditions[] ="1=1 GROUP BY Contact.id";
return $this->findAll($conditions, $fields, $order, $limit, $page, $recursive);
}
function paginateCount($conditions = null, $recursive = 0) {
$rows = $this->paginate($conditions, null, null, null, null, $recursive);
return count($rows);
}
}
?>