-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29: add AR::make() method
- Loading branch information
Showing
8 changed files
with
392 additions
and
288 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,36 @@ | |
use Cycle\ORM\RepositoryInterface; | ||
use Cycle\ORM\Transaction\StateInterface; | ||
|
||
/** | ||
* A base class for entities that are managed by the ORM. | ||
* Adds a set of ActiveRecord methods to the extending entity class. | ||
*/ | ||
abstract class ActiveRecord | ||
{ | ||
/** | ||
* Creates a new entity instance with the given data. | ||
* It is preferable to use this method instead of the constructor because | ||
* it uses ORM services to create the entity. | ||
* | ||
* @note Equals to calling {@see ORMInterface::make()}. | ||
* | ||
* Example: | ||
* | ||
* ```php | ||
* $user = User::make([ | ||
* 'name' => 'John Doe', | ||
* 'email' => '[email protected]', | ||
* ]); | ||
* ``` | ||
* | ||
* @param array<non-empty-string, mixed> $data An associative array where keys are property names | ||
* and values are property values. | ||
*/ | ||
public static function make(array $data): static | ||
{ | ||
return self::getOrm()->make(static::class, $data); | ||
} | ||
|
||
/** | ||
* Finds a single record based on the given primary key. | ||
*/ | ||
|
@@ -23,6 +51,8 @@ final public static function findByPK(mixed $primaryKey): ?static | |
|
||
/** | ||
* Finds the first single record based on the given scope. | ||
* | ||
* @note Limit of 1 will be added to the query. | ||
*/ | ||
final public static function findOne(array $scope = []): ?static | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters