diff --git a/app_model.php b/app_model.php index 97f8611..424965c 100644 --- a/app_model.php +++ b/app_model.php @@ -38,8 +38,7 @@ */ class AppModel extends Model { - //var $actsAs = array('Containable'); - var $actsAs = array('Linkable'); + var $actsAs = array('Containable', 'Linkable'); /** * Get Enum Values diff --git a/controllers/accounts_controller.php b/controllers/accounts_controller.php index f317b0c..6e3ffc2 100644 --- a/controllers/accounts_controller.php +++ b/controllers/accounts_controller.php @@ -170,7 +170,6 @@ class AccountsController extends AppController { } // Get details about the account and its ledgers (no ledger entries yet) - $this->Account->Behaviors->attach('Containable'); $account = $this->Account->find ('first', array('contain' => @@ -184,7 +183,6 @@ class AccountsController extends AppController { 'conditions' => array(array('Account.id' => $id)), ) ); - $this->Account->Behaviors->detach('Containable'); // Get all ledger entries of the CURRENT ledger $entries = $this->Account->findLedgerEntries($id); diff --git a/controllers/contacts_controller.php b/controllers/contacts_controller.php index 360429a..2e2100a 100644 --- a/controllers/contacts_controller.php +++ b/controllers/contacts_controller.php @@ -65,16 +65,17 @@ class ContactsController extends AppController { $this->redirect(array('action'=>'index')); } - $this->Contact->Behaviors->attach('Containable'); - $this->Contact->contain - (array(// Models - 'ContactPhone', - 'ContactEmail', - 'ContactAddress', - 'Customer') - ); - $contact = $this->Contact->read(null, $id); - $this->Contact->Behaviors->detach('Containable'); + $contact = $this->Contact->find + ('first', array + ('contain' => array + (// Models + 'ContactPhone', + 'ContactEmail', + 'ContactAddress', + 'Customer'), + + 'conditions' => array('Contact.id' => $id), + )); // Prepare to render. $title = $contact['Contact']['display_name']; diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index f98d1d6..a866b96 100644 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -117,26 +117,27 @@ class CustomersController extends AppController { $this->redirect(array('action'=>'index')); } - $this->Customer->Behaviors->attach('Containable'); - $this->Customer->contain - (array(// Models - 'Contact' => - array(// Models - 'ContactPhone', - 'ContactEmail', - 'ContactAddress', - ), - 'Account', - 'Lease' => - array('Unit' => - array('order' => array('sort_order'), - 'fields' => array('id', 'name'), - ), - ), - ) - ); - $customer = $this->Customer->read(null, $id); - $this->Customer->Behaviors->detach('Containable'); + $customer = $this->Customer->find + ('first', array + ('contain' => array + (// Models + 'Contact' => + array(// Models + 'ContactPhone', + 'ContactEmail', + 'ContactAddress', + ), + 'Account', + 'Lease' => + array('Unit' => + array('order' => array('sort_order'), + 'fields' => array('id', 'name'), + ), + ), + ), + + 'conditions' => array('Customer.id' => $id), + )); // Add the lease balance to each lease. foreach ($customer['Lease'] AS &$lease) { diff --git a/controllers/leases_controller.php b/controllers/leases_controller.php index f0952fe..ecc593a 100644 --- a/controllers/leases_controller.php +++ b/controllers/leases_controller.php @@ -120,7 +120,6 @@ class LeasesController extends AppController { } // Get details about the lease and its ledgers (no ledger entries yet) - $this->Lease->Behaviors->attach('Containable'); $lease = $this->Lease->find ('first', array('contain' => @@ -134,7 +133,6 @@ class LeasesController extends AppController { 'limit' => 2 ) ); - $this->Lease->Behaviors->detach('Containable'); // Summarize each ledger $this->Lease->statsMerge($lease, diff --git a/controllers/ledger_entries_controller.php b/controllers/ledger_entries_controller.php index 21ed6af..1132c68 100644 --- a/controllers/ledger_entries_controller.php +++ b/controllers/ledger_entries_controller.php @@ -33,7 +33,6 @@ class LedgerEntriesController extends AppController { } // Get the LedgerEntry and related fields - $this->LedgerEntry->Behaviors->attach('Containable'); $entry = $this->LedgerEntry->find ('first', array('contain' => array('MonetarySource.id', @@ -51,15 +50,15 @@ class LedgerEntriesController extends AppController { 'fields' => array('LedgerEntry.id', 'LedgerEntry.amount', 'LedgerEntry.comment'), + + 'conditions' => array('LedgerEntry.id' => $id), )); - $this->LedgerEntry->Behaviors->detach('Containable'); // Because 'DebitLedger' and 'CreditLedger' both relate to 'Account', // CakePHP will not include them in the LedgerEntry->find (or so it // seems). We'll have to break out each Account separately. // Get the Account from DebitLedger - $this->LedgerEntry->DebitLedger->Account->Behaviors->attach('Containable'); $account = $this->LedgerEntry->DebitLedger->Account->find ('first', array('contain' => true, @@ -67,10 +66,8 @@ class LedgerEntriesController extends AppController { 'conditions' => array('Account.id' => $entry['DebitLedger']['account_id']), )); $entry['DebitLedger'] = array_merge($entry['DebitLedger'], $account); - $this->LedgerEntry->DebitLedger->Account->Behaviors->detach('Containable'); // Get the Account from CreditLedger - $this->LedgerEntry->CreditLedger->Account->Behaviors->attach('Containable'); $account = $this->LedgerEntry->CreditLedger->Account->find ('first', array('contain' => true, @@ -78,7 +75,6 @@ class LedgerEntriesController extends AppController { 'conditions' => array('Account.id' => $entry['CreditLedger']['account_id']), )); $entry['CreditLedger'] = array_merge($entry['CreditLedger'], $account); - $this->LedgerEntry->CreditLedger->Account->Behaviors->detach('Containable'); // Prepare to render. $title = "Ledger Entry #{$entry['LedgerEntry']['id']}"; diff --git a/controllers/ledgers_controller.php b/controllers/ledgers_controller.php index 965270f..ac13fb4 100644 --- a/controllers/ledgers_controller.php +++ b/controllers/ledgers_controller.php @@ -118,7 +118,6 @@ class LedgersController extends AppController { } // Get details about the ledger itself (no entries yet) - $this->Ledger->Behaviors->attach('Containable'); $ledger = $this->Ledger->find ('first', array('contain' => @@ -128,7 +127,6 @@ class LedgersController extends AppController { 'conditions' => array(array('Ledger.id' => $id)), ) ); - $this->Ledger->Behaviors->detach('Containable'); // Get all ledger entries of this ledger $ledger['LedgerEntry'] = $this->Ledger->findLedgerEntries diff --git a/controllers/transactions_controller.php b/controllers/transactions_controller.php index 6a49247..d54b2eb 100644 --- a/controllers/transactions_controller.php +++ b/controllers/transactions_controller.php @@ -97,30 +97,30 @@ class TransactionsController extends AppController { $this->redirect(array('action'=>'index')); } - $this->Transaction->Behaviors->attach('Containable'); - $this->Transaction->contain - (array(// Models - 'LedgerEntry' => array('fields' => array('LedgerEntry.id', - 'LedgerEntry.amount', - 'LedgerEntry.comment'), - //Models + $transaction = $this->Transaction->find + ('first', + array('contain' => + array(// Models + 'LedgerEntry' => array('fields' => array('LedgerEntry.id', + 'LedgerEntry.amount', + 'LedgerEntry.comment'), + //Models - 'DebitLedger' => array - ('fields' => array('DebitLedger.id', 'DebitLedger.sequence'), - 'Account' => array - ('fields' => array('Account.id', 'Account.name')), - ), + 'DebitLedger' => array + ('fields' => array('DebitLedger.id', 'DebitLedger.sequence'), + 'Account' => array + ('fields' => array('Account.id', 'Account.name')), + ), - 'CreditLedger' => array - ('fields' => array('CreditLedger.id', 'CreditLedger.sequence'), - 'Account' => array - ('fields' => array('Account.id', 'Account.name')), - ), - ), - ) - ); - $transaction = $this->Transaction->read(null, $id); - $this->Transaction->Behaviors->detach('Containable'); + 'CreditLedger' => array + ('fields' => array('CreditLedger.id', 'CreditLedger.sequence'), + 'Account' => array + ('fields' => array('Account.id', 'Account.name')), + ), + ), + ), + 'conditions' => array('Transaction.id' => $id), + )); // Figure out the transaction total $total = 0; diff --git a/controllers/units_controller.php b/controllers/units_controller.php index 9fcb630..6326447 100644 --- a/controllers/units_controller.php +++ b/controllers/units_controller.php @@ -152,16 +152,16 @@ class UnitsController extends AppController { $this->redirect(array('action'=>'')); } - $this->Unit->Behaviors->attach('Containable'); - $this->Unit->contain - (array(// Models - 'UnitSize', - 'Lease' => array('Customer'), - 'CurrentLease' => array('Customer') - ) - ); - $unit = $this->Unit->read(null, $id); - $this->Unit->Behaviors->detach('Containable'); + $unit = $this->Unit->find + ('first', + array('contain' => + array(// Models + 'UnitSize', + 'Lease' => array('Customer'), + 'CurrentLease' => array('Customer') + ), + 'conditions' => array('Unit.id' => $id), + )); // Get the balance on each lease. foreach ($unit['Lease'] AS &$lease) {