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, "[email protected]"
<[email protected]> 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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to