I'm trying to bake a database, one of the tables is a messaging table, created with the following query:
CREATE TABLE `rally`.`privatemessages` (
`id` INT NOT NULL AUTO_INCREMENT,
`user_id_from` INT NULL,
`user_id_to` INT NULL,
`content` TEXT NULL,
`timestamp` INT NULL,
PRIMARY KEY (`id`));
But when I try to bake the whole project, bake shell tells me that it cannot find table user_froms
. How can I set table fields for bake to work?
There are two steps, the first one is not absolutely needed but will help you down the way.
Change your DB to follow Cake's Model conventions. So the table name needs to b private_messages
and the fields for the foreign keys from_user_id
, to_user_id
.
Bake automates almost all of the most common usage situations but not everything. This is when you as the developer need to jump in and help it understand. If after making the changes above you get asked "PrivateMessage BelongsTo FromUsers?" you say no (as you don't have a FromUsers
Model) and manually lead it to create a BelongsTo Users
with the field name from_user_id
being the foreign key).
Finally you can always skip bake and make the (associations)[http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html] yourself by creating/editing the respective Model file.