Hello,

I have following database tables that are defined by the customer and
cannot be changed:

|-----------------------|
| Tuopak               |
|-----------------------|
| id (primarykey)   |
| tuopaknro           |
| name                  |
| ....                       |
|                            |
|-----------------------|

|----------------------|
| Tuopakriv          |
|----------------------|
| id (primarykey)  |
| tuopaknro          |
| num                   |
| ....                      |
|                           |
|----------------------|

The tables have a relation Tuopak hasMany Tuopakriv with tuopaknro
field.

So the primaryKey field is not used as the relation key.

When I try to define the relations like so:

<?php
class Tuopak extends AppModel {
    var $name = 'Tuopak';
    var $useTable = 'tuopak';
    var $actsAs = array('Containable');
    var $deletedRecord = null;

    var $hasMany = array(
        'Tuopakriv' => array(
            'className' => 'Tuopakriv',
            'foreignKey' => false,
            'conditions' => 'Tuopak.tuopaknro = Tuopakriv.tuopaknro'
        )
    );
?>

And when querying for Tuopak records, I get an SQL error about missin
Tuopakriv.tuopaknro column because Cake is not joining the Tuopak and
Tuopakriv tables for the query.

If I use $primaryKey variable in the model, e.g. define 'tuopaknro' as
the primary key for both models, remove the conditions from the
hasMany definition and define 'tuopaknro' as the foreign key, then
cake does the joins, but then all editing and adding fails records.

Is there a way to keep the hasMany definition like described above,
but tell cake to join the tables when querying?

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