fridge_bites/apps/Recipes/Models/IngredientInRecipeModel.php

33 lines
950 B
PHP

<?php
namespace Lycoreco\Apps\Recipes\Models;
use Lycoreco\Includes\Model\BaseModel;
class IngredientInRecipeModel extends BaseModel
{
public $field_ingredient_id;
public $field_receipt_id;
public $field_amount;
static protected $table_name = 'recipe_ingredients';
static protected $table_fields = [
'id' => 'int',
'ingredient_id' => 'int',
'receipt_id' => 'int',
'amount' => 'int'
];
public static function init_table()
{
$result = db_query('CREATE TABLE ' . static::$table_name . ' (
id INT AUTO_INCREMENT PRIMARY KEY,
ingredient_id INT NOT NULL,
receipt_id INT NOT NULL,
amount INT NOT NULL,
FOREIGN KEY (ingredient_id) REFERENCES ingredients(id) ON DELETE CASCADE,
FOREIGN KEY (receipt_id) REFERENCES recipes(id) ON DELETE CASCADE
);');
return $result;
}
}