]> BookStack Code Mirror - bookstack/blob - app/Entities/Models/EntityContainerData.php
DB: Aligned entity structure to a common table
[bookstack] / app / Entities / Models / EntityContainerData.php
1 <?php
2
3 namespace BookStack\Entities\Models;
4
5 use Illuminate\Database\Eloquent\Builder;
6 use Illuminate\Database\Eloquent\Model;
7
8 /**
9  * @property int     $entity_id
10  * @property string  $entity_type
11  * @property string  $description
12  * @property string  $description_html
13  * @property ?int    $default_template_id
14  * @property ?int    $image_id
15  * @property ?int    $sort_rule_id
16  */
17 class EntityContainerData extends Model
18 {
19     public $timestamps = false;
20     protected $primaryKey = 'entity_id';
21     public $incrementing = false;
22
23     public static array $fields = [
24         'description',
25         'description_html',
26         'default_template_id',
27         'image_id',
28         'sort_rule_id',
29     ];
30
31     /**
32      * Override the default set keys for save query method to make it work with composite keys.
33      */
34     public function setKeysForSaveQuery($query): Builder
35     {
36         $query->where($this->getKeyName(), '=', $this->getKeyForSaveQuery())
37             ->where('entity_type', '=', $this->entity_type);
38
39         return $query;
40     }
41
42     /**
43      * Override the default set keys for a select query method to make it work with composite keys.
44      */
45     protected function setKeysForSelectQuery($query): Builder
46     {
47         $query->where($this->getKeyName(), '=', $this->getKeyForSelectQuery())
48             ->where('entity_type', '=', $this->entity_type);
49
50         return $query;
51     }
52 }