Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fykosak/nette-orm
Light ORM extension for nette
https://github.com/fykosak/nette-orm
nette-database orm package php
Last synced: 4 days ago
JSON representation
Light ORM extension for nette
- Host: GitHub
- URL: https://github.com/fykosak/nette-orm
- Owner: fykosak
- License: gpl-3.0
- Created: 2021-01-31T22:50:29.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-12-23T20:12:45.000Z (11 months ago)
- Last Synced: 2024-04-24T12:03:14.421Z (7 months ago)
- Topics: nette-database, orm, package, php
- Language: PHP
- Homepage:
- Size: 158 KB
- Stars: 3
- Watchers: 8
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nette ORM
![GitHub branch checks state](https://img.shields.io/github/checks-status/fykosak/nette-orm/master)
## install
### Create ORM model
```php
related('participant', 'event_id');
}
// you can define own metods
public function __toArray(): array {
return [
'eventId' => $this->event_id,
'begin' => $this->begin ? $this->begin->format('c') : null,
'end' => $this->end ? $this->end->format('c') : null,
'name' => $this->name,
];
}
}
```### Create ORM service
```php
getTable()->where('begin > NOW()');
}
}
```### Register extension
```neon
orm:
:
service: 'FQN of service'
model: 'FQN of model'
:
service: 'FQN of another service'
model: 'FQN of another model'```
```neon
extensions:
orm: Fykosak\NetteORM\ORMExtension
```---
## ExamplesTypedTableSelection is a regular selection you can use all methods like in nette DB Selection.
```php
$query= $sericeEvent->getNextEvent();
$query->where('name','My cool event');
```TypedTableSelection return ORM model instead of `ActiveRow`, but ORM model is a descendant of a `ActiveRow`.
```php
$query= $sericeEvent->getNextEvent();
foreach($query as $event){
$event // event is a ModelEvent
}$model = $sericeEvent->getNextEvent()->fetch(); // Model is a ModelEvent too.
```Take care `GroupedSelection` still return `ActiveRow`, you can use static method `createFromActiveRow`
```php
$query= $sericeEvent->getParticipants();
foreach($query as $row){
// $row is a ActiveRow
$participant = ModelParticipant::createFromActiveRow($row);
}
```
Define relations between Models by methods
```php
class ModelParticipant extends AbstractModel {
// use ActiveRow to resolve relations and next create a Model.
public function getEvent(): ModelEvent {
return ModelEvent::createFromActiveRow($this->event);
}
}
```Now you can use `ReferencedAccessor` to access Model
```php
$myModel // any model that has define single method returned ModelEvent
$modelEvent = ReferencedAccessor::accessModel($myModel,ModelEvent::class);```