Skip to content
Merged
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
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ final class UserMapper extends EntityRecordMapper
);
}
}

```

### Nullable Support
Expand All @@ -127,8 +126,8 @@ values in your database rows.

### Foreign keys and objects

The orm does not resolve foreign keys and objects automatically,
instead you have to inject the object repository and load as needed:
The ORM does not resolve foreign keys and objects automatically.
Instead, you must inject the object repository and load the object as needed:

```php
return new User(
Expand All @@ -142,7 +141,8 @@ return new User(

### Lazy loading

Records can be lazy loaded with `lazyOf` function, which receives an initializer and loads the entry only when any of its properties are called:
Records can be lazy-loaded with the `lazyOf` function, which receives an initializer and loads the entry only when any of its properties are accessed:

```php
/** lazy object */
$address = lazyOf(
Expand All @@ -158,24 +158,24 @@ $street = $address->street;

### Solving N+1 problems

N+1 can be solved with `lazyBufferOf` function, it manages buffered and loaded records,
all buffered records are loaded at once when any of the entries are loaded,
and all loaded records are returned right away without additional loader calls
N+1 can be solved with the `lazyBufferOf` function, which manages buffered and loaded records.
All buffered records are loaded at once when any of the entries are accessed,
and all previously loaded records are returned immediately without additional loader calls.

```php
$addressLoader = lazyBufferOf(
/** The class to be loaded */
Address::class,
/** The object list loader */
function (array $bufferedIds) {
listOf($this->addressRepository->loadAllByIds($ids))
listOf($this->addressRepository->loadAllByIds($bufferedIds))
->indexedBy(fn(Address $address) => $address->id)
->entries()
->entries();
},
);

/** lazy object */
$address = $addressLoader->lazyOf($addressId),
$address = $addressLoader->lazyOf($addressId);

/** loaded object */
$street = $address->street;
Expand Down Expand Up @@ -261,6 +261,7 @@ Contributions are welcome! If you have ideas, find a bug, or want to improve the
Please follow PSR-12 coding standards and ensure tests pass before submitting changes.

## 🚀 Next steps

- Query builder
- Extend where comparisons

Expand Down