I’m using this query to fetch all tasks with a specific tag in a HABTM relationship. However for some reason it is failing to attach relevant tags to the tags_tasks and thus returning 0 because it can’t pick up anything from the tags table.
SELECT `Task` . * , `Task`.`id`
FROM `tasks` AS `Task`
LEFT JOIN `tags_tasks` AS `TagsTask` ON ( `TagsTask`.`task_id` = `Task`.`id` )
LEFT JOIN `tags` AS `FilterTag` ON ( `FilterTag`.`id` = 'TagsTask.tag_id' )
WHERE `Task`.`assigned_id` = '4de50bef-bbc8-404d-9f46-2a
When I remove the WHERE clause, it returns all tasks but with NULL entries for tag fields.
The problem was actually CakePHP creating an invalid join with the quotes instead of backticks. Thanks for pointing that out and I will investigate deeper.
You were using a string at line 3, which couldn’t possibly work.