My problem is I am trying to get data from 5 different tables all the tables
are related and I can create a sql query to get what I want. Here it is.

[code]
SELECT accounts.account_number, trailers.id, members.first_name,
balances.balance, loans.loan_description, delinquent_loans.days_delinquent,
delinquent_loans.amount_delinquent, delinquent_loans.next_contact,
delinquent_loans.last_contact
FROM accounts, trailers, members, balances, accounts_trailers, loans,
delinquent_loans
WHERE delinquent_loans.loan_id = loans.id
AND loans.accounts_trailer_id = accounts_trailers.id
AND accounts_trailers.account_id = accounts.id
AND accounts_trailers.trailer_id = trailers.id
AND accounts.member_id = members.id
AND balances.accounts_trailer_id = accounts_trailers.id
AND members.first_name
REGEXP '^[a-l]'
ORDER BY delinquent_loans.days_delinquent DESC
[/code]

What I don't understand is how to this query in cakePHP the proper way. I'm
sure I can just use the query function and paste the previous query but I
would like to do this the right way. My reading of the cookbook brings me to
trying to use contain, so what I have thus far is this:

[code]
$this->recursive = -1;
                return $this->find('all', array(
                        'contain'=>array(
                                'Loan' => array(
                                        'fields' => array('id', 
'loan_description'),
                                        'AccountsTrailer' => array(
                                                'Account' => array(
                                                        'fields' => array('id', 
'account_number'),
                                                        'Member' => array(
                                                                'fields' => 
array('id', 'first_name'),
                                                                'conditions' => 
array(  'first_name regexp \'^[a-l]\'',
                                        ),
                                                ),
                                                'Balance' => array(
                                                        'fields' => array('id', 
'balance'),
                                                ),
                                                'Trailer',
                                ),
                        ),
                        'order' => array('`DelinquentLoan`.`days_delinquent` 
desc'),
                        'fields' => array('id', 'days_delinquent', 
'amount_delinquent',
'next_contact', 'last_contact'),
                        )
                );
[/code]

I have read the cookbook and formatted this script exactly the way the
cookbook says to do it.  It just doesn't look as though the containable is
working.  The only data I get is from 2 tables DelinquentLoan and Loan. Any
help is appreciated, thank you.

--
View this message in context: 
http://cakephp.1045679.n5.nabble.com/cakephp-find-all-with-several-tables-tp5077723p5077723.html
Sent from the CakePHP mailing list archive at Nabble.com.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to