Group

If you need to link records with each other within one model, use Group type of data. For example products should have accompanying products, that are defined for each product individually, and their amount may vary for each product.

class Products extends Model
{
    protected $name = "Catalog products";
 
    protected $model_elements = array(
        array("Active", "bool", "active", array("on_create" => true)),
        array("Name", "char", "name", array("required" => true)),
        array("Price", "int", "price", array("required" => true)),
        array("Position", "order", "order"),
        array("Catalog section", "enum", "parent", array("foreign_key" => "Catalogs", 
                                                         "is_parent" => true)),
        array("Images", "multi_images", "images"),
        array("Description", "text", "desc", array("rich_text" => true)),
        array("Recommended products", "group", "additional")
    );
}

When retrieving data from "additional" field, it is convenient to set them into operators "field->in" or "field->not-in", as described in Query constructor section.

//Product search
$product = $mv -> products -> findRecordById(35);
 
//Take out additional products if exist
if($product -> additional)
{
    $rows = $mv -> products -> select(array("active" => 1, 
                                            "order->asc" => "order", 
                                            "id->in" => $product -> additional));
 
    foreach($rows as $row)
    {
        ...
    }
}

As an alternative way to group the products it is possible to add a field of "enum" type, when the name of the group for each product is selected from a drop-down list.