-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.php
More file actions
49 lines (39 loc) · 1.2 KB
/
User.php
File metadata and controls
49 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Cycle\App\Entity;
use Cycle\ActiveRecord\ActiveRecord;
use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use Cycle\Annotated\Annotation\Relation\BelongsTo;
use Cycle\App\Query\UserCollectionQuery;
use Cycle\App\Query\UserQuery;
#[Entity(table: 'user')]
class User extends ActiveRecord
{
#[Column(type: 'bigInteger', primary: true, typecast: 'int')]
public int $id;
#[Column(type: 'string', unique: true)]
public string $name;
#[BelongsTo(target: Identity::class, innerKey: 'id', outerKey: 'id', cascade: true, load: 'eager')]
public Identity $identity;
/**
* @return UserQuery<static>
*/
public static function query(): UserQuery
{
return new UserQuery(static::class);
}
public static function queryWithCollection(): UserCollectionQuery
{
return new UserCollectionQuery(static::class);
}
public function __construct(string $name, ?Identity $identity = null)
{
$this->name = $name;
$this->identity = $identity ?? new Identity();
}
public function getIdentity()
{
return self::query()->where('id', $this->id)->fetchOne();
}
}