not sure If I am doing something wrong, or if there is an issue with phalcon (1.2.0 -
docblock from the devtools ide stubs
/*
* @param string $fields
* @param string $intermediateModel
* @param string $intermediateFields
* @param string $intermediateReferencedFields
* @param string $referencedModel
* @param array $options
* @return \Phalcon\Mvc\Model\Relation
*/
Models, Gallery and Article joined with GalleryToArticle
$this->hasManyToMany(
'galleryId' // $fields
,'GalleryToArticle' // $intermediateModel
,'galleryId' // $intermediateFields
,'articleId' // $intermediateReferencedFields
,'Article' // $referencedModel
,'articleId' // seems to be needed, and has to be a string, is array in docblock
);
and the generated query is (fields replaced with * to make post shorter)
SELECT * FROM `Article` INNER JOIN `Gallery_to_Article` ON `Gallery_to_Article`.`articleId` = `Article`.`articleId` WHERE `Gallery_to_Article`.`articleId` = :0
when I think the WHERE should be on galleryId, indeed the value that is in the bindParams is the expected value for galleryId, however no combination of swapping the values around seems to work
when I put in placeholders:
$this->hasManyToMany(
'galleryId' // $fields
,'GalleryToArticle' // $intermediateModel
,'intermediateFields' // $intermediateFields
,'intermediateReferencedFields' // $intermediateReferencedFields
,'Article' // $referencedModel
,'unknownId' // ?
);
I get this:
SELECT * FROM `Article` INNER JOIN `Gallery_to_Article` ON `Gallery_to_Article`.`intermediateReferencedFields` = `Article`.`unknownId` WHERE `Gallery_to_Article`.`intermediateReferencedFields` = :0
when I would expect
SELECT * FROM `Article` INNER JOIN `Gallery_to_Article` ON `Gallery_to_Article`.`intermediateReferencedFields` = `Article`.`intermediateReferencedFields` WHERE `Gallery_to_Article`.`intermediateFields` = :0