Thursday, November 27, 2008

SQL Error: 1054 on a HABTM relationship

Dear all,

I'm having a problem in cakephp and I'm kinda desperate because I've
no idea what's causing it.
I'll try and describe the problem as accurate as possible.
I've got two tables with a HABTM relationship, did some baking on
them, but when I try to add, or delete through the baked views I get
the following error :

SQL Error: 1054: Unknown column 'TransfersUser.id' in 'field list'

The way I see it, this query is looking for a id field in the
transfers_users table, which isn't there.
So far I understand why it's giving an error. What I don't understand
is why its looking for the 'id' field.
I've checked all the models, controllers and views, but there isn't a
single mention of an 'id' field to be found anywhere.

The weird thing is, if I press F5 after the error my app actually
deleted (or added) the record.

I've added the relationships from my models below. I'm also using the
standard baked functions, so nothing of my own yet.
Hope someone can help.

relationship from usermodel

var $hasAndBelongsToMany = array(
'Transfer' => array('className' => 'Transfer',
'joinTable' => 'transfers_users',
'foreignKey' => 'transfer_id',
'associationForeignKey' => 'user_id',
'unique' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);

relationship from transfermodel

var $hasAndBelongsToMany = array(
'User' => array('className' => 'User',
'joinTable' => 'transfers_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'transfer_id',
'unique' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)

--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: