File: //proc/self/cwd/finance/source/Models/Ecommerce/Type.php
<?php
namespace Source\Models\Ecommerce;
use Source\Core\Model;
/**
* Class Type
* @package Source\Models\Ecommerce
*/
class Type extends Model
{
/**
* Post constructor.
*/
public function __construct()
{
parent::__construct("types", ["id"], ["title", "uri", "description"]);
}
/**
* @return Post
*/
public function products(): Product
{
return (new Product())->find("type = :id", "id={$this->id}");
}
/**
* @return bool
*/
public function save(): bool
{
$checkUri = (new Type())->find("uri = :uri AND id != :id", "uri={$this->uri}&id={$this->id}");
if ($checkUri->count()) {
$this->uri = "{$this->uri}-{$this->lastId()}";
}
return parent::save();
}
}