Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
[![Codecov Coverage](https://img.shields.io/codecov/c/github/cycle/active-record?style=flat-square&logo=codecov)](https://app.codecov.io/gh/cycle/active-record)
[![Type Coverage](https://shepherd.dev/github/cycle/active-record/coverage.svg)](https://shepherd.dev/github/cycle/active-record)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat-square&label=mutation%20score&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fcycle%2Factive-record%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/cycle/active-record/master)
[![MetaStorm plugin](https://img.shields.io/static/v1?label=Meta+Storm&message=annotated&color=008880&style=flat-square&logo=data:image/svg%2bxml;base64,PHN2ZyB3aWR0aD0iMTExIiBoZWlnaHQ9IjExMSIgdmlld0JveD0iMCAwIDExMSAxMTEiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTYwLjQ2MTcgOEwzMC4xNjU0IDguMjQ3OUMyNy4yNDYgOC4yNzE3OSAyNC42NDggMTAuMTA1IDIzLjY0NyAxMi44NDc1TDAuNDMwNTkgNzYuODMxNEMtMS4yNDQ1OSA4MS40MjA4IDIuMTc4MDUgODYuMjcxMyA3LjA2MzUzIDg2LjIzMTNMMzIuMTE5NyA4Ni4wMjYzTDM1LjQxNDcgNzYuOTk5TDkuODczOTEgNzcuMjA4TDMxLjYyNTkgMTcuMjM2Mkw1Ny4xNjY2IDE3LjAyNzNMNjAuNDYxNyA4WiIgZmlsbD0iI0FGQjFCMyIvPjxwYXRoIGQ9Ik00OS40MTQ5IDEwMi45OTlMNzkuNzEyMiAxMDIuOTk5QzgyLjYzMTcgMTAyLjk5OSA4NS4yNDQ2IDEwMS4xODcgODYuMjY4IDk4LjQ1MjlMMTEwLjAxMyAzNC40NTI0QzExMS43MjYgMjkuODc2OCAxMDguMzQzIDI0Ljk5ODUgMTAzLjQ1NyAyNC45OTg1TDc4LjQwMDQgMjQuOTk4NUw3NS4wMzE2IDMzLjk5ODVMMTAwLjU3MyAzMy45OTg1TDc4LjMyNTMgOTMuOTk5TDUyLjc4MzcgOTMuOTk5TDQ5LjQxNDkgMTAyLjk5OVoiIGZpbGw9IiNBRkIxQjMiLz48cGF0aCBkPSJNMjIgNjFMODYgOEw1NyA1MEw4OS45OTk3IDQ5Ljk5OTdMMjYgMTAzTDU1IDYxSDIyWiIgZmlsbD0iI0M3NTQ1MCIvPjwvc3ZnPg==)](https://github.com/xepozz/meta-storm-idea-plugin)

[![Discord](https://img.shields.io/discord/538114875570913290?style=flat-square&logo=discord&labelColor=7289d9&logoColor=white&color=39456d)](https://discord.gg/spiralphp)
[![Follow on Twitter (X)](https://img.shields.io/badge/-Follow-black?style=flat-square&logo=X)](https://x.com/intent/follow?screen_name=SpiralPHP)

Expand Down Expand Up @@ -154,6 +156,46 @@ $user = User::create(name: 'John');
$user->saveOrFail();
```

### → Advanced Usage Examples

#### Query Builder Integration

```php
// Find users with advanced Cycle ORM filtering
$user = User::query()
->where('name', 'John')
->where('active', true)
->fetchOne();

// Find by primary key
$user = User::findByPK(42);

// Find with conditions
$users = User::findAll(['status' => 'active']);
$user = User::findOne(['email' => '[email protected]']);
```

#### Batch Operations and Transactions

```php
$user1 = new User('Alice');
$user2 = new User('Bob');

// Group multiple operations in a single transaction
ActiveRecord::groupActions(function (EntityManagerInterface $em) use ($user1, $user2) {
$user1->save();
$user2->save();
// Both users saved in one transaction
}, TransactionMode::OpenNew);

// Advanced transaction handling
User::transact(function (DatabaseInterface $db, EntityManagerInterface $em) {
$user = User::query()->forUpdate()->fetchOne(['name' => 'Charlie']);
$user->name = 'Charles';
$user->save();
});
```

<br>

## 🙌 Want to Contribute?
Expand Down
37 changes: 37 additions & 0 deletions resources/ar.meta-storm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" ?>
<meta-storm xmlns="meta-storm">
<definitions>
<!-- AR::findAll -->
<classMethod class="\Cycle\ActiveRecord\ActiveRecord" method="findAll" argument="0" targetInArray="key" targetValue="false">
<properties xpath="$variable">
<filters>
<hasAttribute class="\Cycle\Annotated\Annotation\Column"/>
</filters>
</properties>
</classMethod>
<!-- AR::make -->
<classMethod class="\Cycle\ActiveRecord\ActiveRecord" method="make" argument="0" targetInArray="key" targetValue="false">
<properties xpath="$variable">
<filters>
<hasAttribute class="\Cycle\Annotated\Annotation\Column"/>
</filters>
</properties>
</classMethod>
<!-- AR::findByPK -->
<classMethod class="\Cycle\ActiveRecord\ActiveRecord" method="findByPK" argument="0" targetInArray="key" targetValue="false">
<properties xpath="$variable">
<filters>
<hasAttribute class="\Cycle\Annotated\Annotation\Column"/>
</filters>
</properties>
</classMethod>
<!-- AR::findOne -->
<classMethod class="\Cycle\ActiveRecord\ActiveRecord" method="findOne" argument="0" targetInArray="key" targetValue="false">
<properties xpath="$variable">
<filters>
<hasAttribute class="\Cycle\Annotated\Annotation\Column"/>
</filters>
</properties>
</classMethod>
</definitions>
</meta-storm>
Loading