This is not an elegant solution, but after debuging some cakes code,
before saving or doing somenthing I use code like this:
$this->Model->primaryKey = 'myIdField';

Then magically it worked out fine.

Hope it helps.

On 15 abr, 09:39, Deftly-D <[email protected]> wrote:
> I am trying tooverridethePrimaryKeyused to join tables, but the
> query that CakePHP is generating keeps using 'id' as the primary key.
> This is in CakePHP version 1.3.7
>
> Please suggest any changes that don't involve changing the database
> structure.
>
> The models that I am trying to join are as follows:
>
> <?php
> class VUser extends AppModel {
>   var $name = 'VUser';
>
>   var $useTable = 'v_users';
>   var $primaryKey= 'userid';
>
>   var $hasMany = array(
>         'InterviewerID' => array(
>                 'className' => 'Sitelog',
>                 'foreignKey' => 'interviewerid'
>         ),
>         'ObserverID' => array(
>                 'className' => 'Sitelog',
>                 'foreignKey' => 'observerid'
>         ),
>         'CounterID' => array(
>                 'className' => 'Sitelog',
>                 'foreignKey' => 'counterid'
>         )
>   );
>
>   var $validate = array(
>         'orgid' => array('rule' => 'notEmpty'),
>         'username' => array('rule' => 'notEmpty'),
>         'phonenumber' => array('rule' => 'notEmpty'),
>         'mailaddress' => array('rule' => 'notEmpty'),
>         'loginid' => array('rule' => 'notEmpty'),
>         'roleid' => array('rule' => 'notEmpty'),
>         'terminatedate' => array('rule' => 'notEmpty'),
>         'sid' => array('rule' => 'notEmpty'),
>   );}
>
> ?>
>
> <?php
> class Sitelog extends AppModel {
>
>   var $name = 'Sitelog';
>
>   var $useTable = 'site_log';
>   var $primaryKey= 'sitelogid';
>
>   var $belongsTo = array(
>         'interviewer' => array(
>                 'className' => 'VUser',
>                 'foreignKey' => 'interviewerid'
>         ),
>         'observer' => array(
>                 'className' => 'VUser',
>                 'foreignKey' => 'observerid'
>         ),
>         'counter' => array(
>                 'className' => 'VUser',
>                 'foreignKey' => 'counterid'
>         )
>   );
>
>   var $validate = array(
>     'sitelogid' => array('rule' => 'notEmpty'),
>     'psuid' => array('rule' => 'notEmpty'),
>     'siteid' => array('rule' => 'notEmpty'),
>     'statusid' => array('rule' => 'notEmpty'),
>     'sitelogtype' => array('rule' => 'notEmpty'),
>     'interviewerid' => array('rule' => 'notEmpty'),
>     'observerid' => array('rule' => 'notEmpty'),
>     'observerdate' => array('rule' => 'notEmpty'),
>     'spanishavail' => array('rule' => 'notEmpty'),
>     'counterid' => array('rule' => 'notEmpty')
>   );}
>
> ?>

-- 
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
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to