'int', 'dayofweek' => 'string', 'recipe_id' => 'int', 'user_id' => 'int', 'created_at' => 'DateTime' ]; public static function init_table() { $result = db_query('CREATE TABLE ' . static::$table_name . ' ( id INT AUTO_INCREMENT PRIMARY KEY, dayofweek VARCHAR(150) NOT NULL, recipe_id INT NOT NULL, user_id INT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (recipe_id) REFERENCES recipes(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE );'); return $result; } public function valid() { require_once INCLUDES_PATH . '/Const/recipes.php'; if(!in_array($this->field_dayofweek, DAY_OF_WEEKS)) return ['Day of Week is not valid']; $recipe = RecipeModel::get(array( [ 'name' => 'obj.id', 'type' => '=', 'value' => $this->field_recipe_id ] )); if(!$recipe) return ['Recipe is not exists']; return true; } }