Hi,

I tried to search through the group archive but did not find any
solution. My problem is pretty simple and probably solution is also
simple for all who dealt with cake relations.

I have 3 database tables:
items with columns: id, type, status
item_types with columns: id, name
item_statuses with columns: id, name

My Items model has two hasOne relations defined:
        var $hasOne = array(
                'Type' => array(
                        'className' => 'ItemType',
                        'foreignKey' => 'id'),
                'Status' => array(
                        'className' => 'ItemStatus',
                        'foreignKey' => 'id')
        );

Model ItemType has belongsTo defined:
        var $belongsTo = array(
                'Item' => array(
                        'className' => 'Item',
                        'foreignKey' => 'type')
        );

And the same with ItemStatus model:
        var $belongsTo = array(
                'Item' => array(
                        'className' => 'Item',
                        'foreignKey' => 'status')
        );

Now the problem appears when I try to call any function within Items
controller. Here is the SQL join part that is generated:

... FROM `items` AS `Item` LEFT JOIN `item_types` AS `Type` ON
(`Type`.`id` = `Item`.`id`) LEFT JOIN `item_statuses` AS `Status` ON
(`Status`.`id` = `Item`.`id`) ...

There are two problems with the query - join with Type should be done
on Type.id = Item.type and join with Status on Status.id =
Item.status.

The solution I found refered to setting primaryKey for Items model,
but this can be done only for one of these referenced tables and does
not fit into my situation. Any ideas?

In case this makes any difference I am running Cake 1.2.0.6311 beta

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to