J'ai une table "comments" contenant
CREATE TABLE IF NOT EXISTS `xxx_comments` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`comment` text NOT NULL,
`pseudo` varchar(50) NOT NULL,
`ip` varchar(15) NOT NULL,
`object_id` int(10) NOT NULL,
`type` varchar(50) NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
tout comme une table "notes"
CREATE TABLE IF NOT EXISTS `xxx_notes` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`note` float NOT NULL,
`ip` varchar(15) NOT NULL,
`object_id` int(10) NOT NULL,
`type` varchar(50) NOT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
Les 2 tables sont construites de la même manière.
Maintenant ces table sont reliés à la table photo via la clé étrangère "object_id" si le type est "Photo" et la ça se corse..
voivi la déclaration du hasMany du model "Photo".
public $hasMany = array(
'Comment' => array(
'className' => 'Comment',
'conditions' => array('Comment.type' => 'Photo'),
'foreignKey' => 'object_id'
),
'Note' => array(
'className' => 'Note',
'conditions' => array('Note.type' => 'Photo'),
'foreignKey' => 'object_id'
)
);
L'association avec les notes fonctionnent sans aucun souci, par contre avec les commentaires, je me retrouve avec cette erreur :
"Unknown column 'Comment.photo_id' in 'on clause'"
Donc il ne prend pas en compte la surcharge de la foreignKey et va chercher celle par défaut "photo_id".
1 idée de la raison??