I'm just learning CakePHP, my simple app links two tables with a hasAndBelongsToMany relationship. I was expecting that the scaffolding would enable me to associate posts with tags but it doesn't.
Here is the code:
SQL
CREATE TABLE `posts` (
`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`content` TEXT,
PRIMARY KEY ( `id` )
);
CREATE TABLE `tags` (
`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 100 ) DEFAULT NULL ,
PRIMARY KEY ( `id` )
);
CREATE TABLE `posts_tags` (
`id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
`post_id` INT( 11 ) UNSIGNED DEFAULT NULL ,
`tag_id` INT( 11 ) UNSIGNED DEFAULT NULL ,
PRIMARY KEY ( `id` )
);
contents of models folder:
post.php
class Post extends AppModel {
var $name = 'Post';
var $hasAndBelongsToMany = array('Tag');
}
tag.php
class Tag extends AppModel {
var $name = 'Tag';
var $hasAndBelongsToMany = array('Post');
}
contents of controllers folder
posts_controller.php
class PostsController extends AppController {
var $name = 'Posts';
var $scaffold;
}
tags_controller.php
class TagsController extends AppController {
var $name = 'Tags';
var $scaffold;
}
In the app, I can create/edit/delete a post or a tag, but there is no way to link them.
edit: In my scaffolded views there are no multiple selects to associate tags to posts etc. I'm using v 1.2.4.8284.