07.01 php saved
depinko
Tags add more
habtm  
Note
Can't get work the HABTM relationship.
  1. /models/theme.php
  2. =================
  3. class Theme extends AppModel {
  4.     var $name = 'Theme';
  5.    
  6.     var $hasMany = array('Comment');
  7.     var $belongsTo = 'User';
  8.     var $hasAndBelongsToMany = array('Tag');
  9. ...
  10. ..
  11. }
  12.  
  13. /models/tag.php
  14. ================
  15. class Tag extends AppModel {
  16.     var $name = 'Tag';
  17.     var $hasAndBelongsToMany = array('Theme');
  18. }
  19.  
  20. /controllers/themes_controller.php
  21. ==================================
  22.     function index() {
  23.         $this->pageTitle = 'Browse themes';
  24.        
  25.         $this->set('themes', $this->Theme->find('all'));
  26.  
  27.         $this->Session->write('redirectTo', '/'.$this->params['controller'].'/'.$this->params['action']);
  28.     }
  29.  
  30.  
  31. OUTPUT from /views/index.ctp:
  32. =============================
  33. Warning (512): SQL Error: 1054: Unknown column 'Tag.id' in 'on clause' [CORE/cake/libs/model/datasources/dbo_source.php, line 512]
  34.  
  35. Code | Context
  36.  
  37. $sql    =   "SELECT `Tag`.`tag_id`, `Tag`.`name`, `TagsTheme`.`tag_id`, `TagsTheme`.`theme_id` FROM `tags` AS `Tag` JOIN `tags_themes` AS `TagsTheme` ON (`TagsTheme`.`theme_id` IN (1, 2, 3, 4, 5, 6, 7, 13) AND `TagsTheme`.`tag_id` = `Tag`.`id`)  WHERE 1 = 1   "
  38. $error  = "1054: Unknown column 'Tag.id' in 'on clause'"
  39. $out    =   null
  40.  
  41.             $out = null;
  42.             if ($error) {
  43.                 trigger_error("<span style = \"color:Red;text-align:left\"><b>SQL Error:</b> {$this->error}</span>", E_USER_WARNING);
  44.  
  45. DboSource::showQuery() - CORE/cake/libs/model/datasources/dbo_source.php, line 512
  46. DboSource::execute() - CORE/cake/libs/model/datasources/dbo_source.php, line 202
  47. DboSource::fetchAll() - CORE/cake/libs/model/datasources/dbo_source.php, line 338
  48. DboSource::queryAssociation() - CORE/cake/libs/model/datasources/dbo_source.php, line 788
  49. DboSource::read() - CORE/cake/libs/model/datasources/dbo_source.php, line 653
  50. Model::find() - CORE/cake/libs/model/model.php, line 1795
  51. ThemesController::index() - APP/controllers/themes_controller.php, line 13
  52. Object::dispatchMethod() - CORE/cake/libs/object.php, line 114
  53. Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 256
  54. Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 230
  55. [main] - APP/webroot/index.php, line 84
  56.  
  57. Query: SELECT `Tag`.`tag_id`, `Tag`.`name`, `TagsTheme`.`tag_id`, `TagsTheme`.`theme_id` FROM `tags` AS `Tag` JOIN `tags_themes` AS `TagsTheme` ON (`TagsTheme`.`theme_id` IN (1, 2, 3, 4, 5, 6, 7, 13) AND `TagsTheme`.`tag_id` = `Tag`.`id`) WHERE 1 = 1
  58.  
  59.  
  60. I'm missing something?
Parsed in 0.100 seconds, using GeSHi 1.0.7.14

Modify this Paste