cakephp bake 2 tables with a join table
I have two tables. First table 开发者_Go百科is a table of categories called categories
, the second is a table of documents called documents
. I'm trying to create a join table that will allow multiple categories to be applied to multiple documents and bake it all in seconds with CakePHP (to which I am a noob).
I've used mysql like this for the DB:
CREATE TABLE `categories` (
`id` int(10) unsigned NOT NULL auto_increment,
`cat_name` varchar(100) default NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `documents` (
`id` int(10) unsigned NOT NULL auto_increment,
`title` varchar(50) default NULL,
`size` varchar(10) default NULL,
`file` varchar(50) default NULL,
`date` date default NULL,
`created` datetime default NULL,
`modified` datetime default NULL,
`status` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `categories_documents` (
`category_id` int(10) unsigned NOT NULL default '0',
`document_id` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`category_id`,`document_id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8;
...for the tables and was under the impression I got from what I read in the documentation that it would bake auto-magically. However I get lots of unknown column errors. I am wondering if I messed up on the naming conventions and if someone could put me right before I spent too long digging too deep?
The categories_documents will need an "id" field that needs to be the primary key. That should fix it. For more information, read the HABTM documentation.
If I understand you correctly, I think this link might help explain things to you better than I can: http://book.cakephp.org/view/872/Joining-tables
My experience have been manually writing all model codes, never used bake.
精彩评论