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/site@23 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -13,17 +13,24 @@ class ContactsController extends AppController {
|
|||||||
|
|
||||||
function current() {
|
function current() {
|
||||||
$this->Contact->recursive = 0;
|
$this->Contact->recursive = 0;
|
||||||
$this->set('contacts', $this->paginate(array('Lease.closed_date IS NULL',
|
$this->Contact->bindModel(array('hasOne' => array('ContactsLease',
|
||||||
//'Contact.'
|
'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');
|
$this->render('index');
|
||||||
}
|
}
|
||||||
|
|
||||||
function all() {
|
function all() {
|
||||||
$this->Contact->recursive = 2;
|
$this->Contact->recursive = 0;
|
||||||
|
$this->Contact->bindModel(array('hasOne' => array('ContactsLease')),
|
||||||
//$contacts = $this->paginate();
|
false);
|
||||||
$this->set('contacts', $this->paginate());
|
|
||||||
|
$this->set('contacts', $this->paginate(array('ContactsLease.type != "ALTERNATE"')));
|
||||||
$this->render('index');
|
$this->render('index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user