0
votes

I have several tables: ingredients, customers, recipes, menus and restaurants.

The conditions are: ingredients HABTM customers, recipes HABTM ingredients, menus hasmany recipes and restaurants hasmany menus.

However, when I try to cake bake all using the cmd console, the relationship that is created automatically is like ingredients hasmany customers_ingredients, customers hasmany customers_ingredients and customer_ingredients belongsto customer and ingredients, instead of giving ingredients hasandbelongtomany customers. What is wrong? The table definition or the console?

Here I list my create table statement:

CREATE TABLE customers (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    cust_gname VARCHAR(20) NOT NULL,
    cust_fname VARCHAR(30) NOT NULL,
    cust_street VARCHAR(30) NOT NULL,
    cust_suburb VARCHAR(30) NOT NULL,
    cust_state VARCHAR(6) NOT NULL,
    cust_postcode VARCHAR(4) NOT NULL,
    cust_email VARCHAR(50) NOT NULL,
    cust_phone VARCHAR(12),
    cust_mobile VARCHAR(12)
);

CREATE TABLE restaurants (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(30),
    address1 VARCHAR(30),
    address2 VARCHAR(30),
    suburb VARCHAR(30),
    state VARCHAR(10),
    postcode VARCHAR(4)
);

CREATE TABLE ingredients (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(30)
);

CREATE TABLE menus (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    description VARCHAR(30),
    restaurant_id INT UNSIGNED,
    CONSTRAINT fk_restID FOREIGN KEY (restaurant_id) REFERENCES restaurants(id)
);

CREATE TABLE recipes (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(30),
    menu_id INT UNSIGNED,
    image VARCHAR(30),
    CONSTRAINT fk_menuID FOREIGN KEY (menu_id) REFERENCES menus(id)
);

CREATE TABLE ingredient_recipes (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    ingredient_id INT UNSIGNED,
    recipe_id INT UNSIGNED,
    CONSTRAINT fk_ingID FOREIGN KEY (ingredient_id) REFERENCES ingredients(id),
    CONSTRAINT fk_recID FOREIGN KEY (recipe_id) REFERENCES recipes(id)
);

CREATE TABLE customer_ingredients (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    customer_id INT UNSIGNED,
    ingredient_id INT UNSIGNED,
    CONSTRAINT fk_ingrID FOREIGN KEY (ingredient_id) REFERENCES ingredients(id),
    CONSTRAINT fk_cusID FOREIGN KEY (customer_id) REFERENCES customers(id)
);
1

1 Answers

1
votes

for HABTM relationships the names convention wants both names to be plural: customers_ingredients and ingredients_recipes