This commit is contained in:
2020-11-10 11:36:39 +08:00
parent d07c39007d
commit f814fc32ba
2 changed files with 8 additions and 1 deletions
+7 -1
View File
@@ -24,7 +24,7 @@ abstract class HasBase
protected $data;
/**
* @var string
* @var string
*/
protected string $model;
@@ -48,6 +48,12 @@ abstract class HasBase
*/
public function __construct($model, $primaryId, $value, Relation $relation)
{
if (!class_exists($model)) {
throw new Exception('Model must implement ' . ActiveRecord::class);
}
if (!in_array(ActiveRecord::class, class_implements($model))) {
throw new Exception('Model must implement ' . ActiveRecord::class);
}
if (is_array($value)) {
if (empty($value)) $value = [];
$_model = $model::find()->in($primaryId, $value);