On 06/06/2010 18:54, John Andersen wrote:
There is nothing wrong with your associations/relationships between
the Invoice, Client and Country models.
You just have to read up on the recursive attribute in the model, see:
http://book.cakephp.org/view/1057/Model-Attributes#recursive-1063

That should give you a hint :)

Next I suggest you study the Containable behavior, as that will make
life easier for you in the future, with regard to finding related
information. See:
http://book.cakephp.org/view/1323/Containable

Last I also suggest you conform to the CakePHP conventions, see:
http://book.cakephp.org/view/901/CakePHP-Conventions
Note specially the Model naming (hint: className =>  InvoicesRows)!

Enjoy,
    John

On Jun 6, 7:05 pm, "phpcoder2...@googlemail.com"
<phpcoder2...@gmail.com>  wrote:
Hey guys, new here so please be gentle ;) lol here is my issue i need
help getting my head around.

I have the following models

invoice.php
client.php
country.php

client has country_id in db which relates to id in the country table
and pulls the correct country. this pulls out by using belongsTo
country in my client model and works great! my problem now is when i
go into an invoice it pulls the the client because im using belongsTo
client in the invoice model and using hasMany invoices in my client
model, this works great except the invoice only pulls the client
details along with the invoice data and doesnt fetch the country...
can anyone help me?

heres the code too:

invoice model

<?php

class Invoice extends AppModel
{

     var $name = 'Invoice';
     var $hasMany = array(
         'InvoiceRows' =>  array(
             'className' =>  'InvoicesRows',
             'foreignKey' =>  'invoice_id',
             'order' =>  'InvoiceRows.delta ASC',
         ),
     );
     var $belongsTo = array(
         'Client' =>  array(
             'className' =>  'Client',
         ),
     );

}

my client model

<?php

class Client extends AppModel
{

     var $name = 'Client';
     var $hasMany = array(
         'Invoices' =>  array(
             'className' =>  'Invoice',
             'foreignKey' =>  'client_id',
             'order' =>  'Invoices.invoice_no DESC',
         ),
     );
     var $belongsTo = array(
         'Country' =>  array(
             'className' =>  'Country',
             'foreignKey' =>  'country_id',
         ),
     );

}

can anyone see anything wrong?

thanks Chris
Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
thanks for your reply John, id just stumbled upon recursive before thie email, its bringing my Country data but inside of the Client data, every where else im accessing it outside Client, so Client -> data, Country -> data but recursive is fetching Client -> data, Country. I though id changed InvoicesRow to InvoiceRows (thats better right?); guess i hadnt lol, thanks

Chris

--
Best Regards Christopher Hanson

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en

Reply via email to