I've never done anything like this but you can tell the Campaign model
what the primary key is using the $primaryKey attribute.
http://book.cakephp.org/2.0/en/models/model-attributes.html#primarykey
class Campaign extends AppModel {
$primaryKey = 'code';
}
On Wed, Aug 7, 2013 at 6:59 AM, NikNik <key5com@gmail.com> wrote:
>
> Hello,
> I must work on a pretty old database and I am forced to use a table (
> Campaign ) that didn't have a numeric primary key .
> The former primary key was the field "code" varchar(6). So I had to add an
> autoincrement id field.
>
> Campaign hasMany Users
>
> in the Campaign model I then have:
>
> public $hasMany = array(
> 'User' => array(
> 'className' => 'User',
> 'foreignKey' => false,
> 'conditions' => 'User.campaign_id=Campaign.code'
> )
> );
>
> in the User model I have:
>
> public $belongsTo = array(
> 'Campaign'=>array(
> 'className' => 'Campaign',
> 'foreignKey'=>false,
> 'conditions'=> array('User.campaign_id = Campaign.code')
> ),
> );
>
>
> But when I go to /campaigns/view/103
> the campaign data are shown correctly but if I want to show also the related
> Users belonging to the given Campaign_id
> I get
> Column not found: 1054 Unknown column 'Campaign.code' in 'where clause'
>
> And the breaking query is:
>
> SELECT `User`.`id`, `User`.`field2`, `User`.`field3`, `User`.`field4` FROM
> `mydb`.`users` AS `User` WHERE `Campaign`.`code`=`User`.`campaign_id`
>
> No join is created so th Campaign.code is unknown...
>
>
> I know I should change the model structure but It would mean change a huge
> amount of things..
>
>
> Please help
> THANKS
>
> --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cake-php+unsubscribe@googlegroups.com.
> To post to this group, send email to cake-php@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
Simon Males
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
Wednesday, August 7, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment