[ 'tb1.name AS ingredient_name', 'tb1.unit_name AS ingredient_unit' ], 'join_table' => 'ingredients tb1 ON tb1.id = obj.ingredient_id' ] ); static protected $table_name = 'recipe_ingredients'; static protected $table_fields = [ 'id' => 'int', 'ingredient_id' => 'int', 'recipe_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, recipe_id INT NOT NULL, amount INT NOT NULL, FOREIGN KEY (ingredient_id) REFERENCES ingredients(id) ON DELETE CASCADE, FOREIGN KEY (recipe_id) REFERENCES recipes(id) ON DELETE CASCADE );'); return $result; } public function get_count() { return $this->field_amount . ' ' . $this->ingredient_unit; } public function __toString() { return $this->ingredient_name; } }