@@ -6,4 +6,99 @@ Spiral ORM
6
6
[ ![ Scrutinizer Code Quality] ( https://scrutinizer-ci.com/g/spiral/orm/badges/quality-score.png?b=master )] ( https://scrutinizer-ci.com/g/spiral/orm/?branch=master )
7
7
[ ![ Coverage Status] ( https://coveralls.io/repos/github/spiral/orm/badge.svg?branch=master )] ( https://coveralls.io/github/spiral/orm?branch=master )
8
8
9
- <b >[ Documentation] ( http://spiral-framework.com/guide ) </b > | [ CHANGELOG] ( /CHANGELOG.md )
9
+ ORM engine with automatic database scaffolding, strict schemas, code discovery, modular database partitions and various relation loaders. Hackable!
10
+
11
+ <b >[ Full Documentation] ( http://spiral-framework.com/guide ) </b > | [ CHANGELOG] ( /CHANGELOG.md )
12
+
13
+ # Documentation
14
+ * [ Overview] ( https://spiral-framework.com/guide/orm/overview.md )
15
+ * [ Record and RecordEntity] ( https://spiral-framework.com/guide/orm/entities.md )
16
+ * [ Repositories and Selectors] ( https://spiral-framework.com/guide/orm/repositories.md )
17
+ * [ Accessors and Filters] ( https://spiral-framework.com/guide/orm/accessors.md )
18
+ * [ Column Objects] ( https://spiral-framework.com/guide/orm/columns.md )
19
+ * [ Scaffolding and Migrations] ( https://spiral-framework.com/guide/orm/scaffolding.md )
20
+ * [ Transactions] ( https://spiral-framework.com/guide/orm/transactions.md )
21
+ * [ Relations] ( https://spiral-framework.com/guide/orm/relations.md )
22
+ * [ Morphed Relations] ( https://spiral-framework.com/guide/orm/morphed-relations.md )
23
+ * [ Pre-compiled Relations] ( https://spiral-framework.com/guide/orm/late-binding.md )
24
+ * [ Query Models] ( https://spiral-framework.com/guide/orm/query.md )
25
+ * [ Eager loading] ( https://spiral-framework.com/guide/orm/loading.md )
26
+ * [ Recursive Relations] ( https://spiral-framework.com/guide/orm/recursive-relations.md )
27
+ * [ Hybrid Databases] ( https://spiral-framework.com/guide/orm/odm-bridge.md )
28
+ * [ Custom Relations] ( https://spiral-framework.com/guide/orm/custom-relations.md )
29
+
30
+ # Examples
31
+
32
+ ``` php
33
+ class Post extends RecordEntity
34
+ {
35
+ use TimestampsTrait;
36
+
37
+ //Database partitions, isolation and aliasing
38
+ const DATABASE = 'blog';
39
+
40
+ const SCHEMA = [
41
+ 'id' => 'bigPrimary',
42
+ 'title' => 'string(64)',
43
+ 'status' => 'enum(published,draft)',
44
+ 'body' => 'text',
45
+
46
+ //Simple relation definitions
47
+ 'comments' => [self::HAS_MANY => Comment::class],
48
+
49
+ //Not very simple relation definitions
50
+ 'collaborators' => [
51
+ self::MANY_TO_MANY => User::class,
52
+ self::PIVOT_TABLE => 'post_collaborators_map',
53
+ self::PIVOT_COLUMNS => [
54
+ 'time_assigned' => 'datetime',
55
+ 'type' => 'string, nullable',
56
+ ],
57
+ User::INVERSE => 'collaborated_posts'
58
+ ],
59
+
60
+ //Pre-compiled relations
61
+ 'author' => [
62
+ self::BELONGS_TO => AuthorInterface::class,
63
+ self::LATE_BINDING => true
64
+ ],
65
+
66
+ //Hybrid databases
67
+ 'metadata' => [
68
+ Document::ONE => Mongo\Metadata::class
69
+ ]
70
+ ];
71
+ }
72
+ ```
73
+
74
+ ``` php
75
+ $posts = $postSource->find()->distinct()
76
+ ->with('comments', ['where' => ['{@}.approved' => true]]) //Automatic joins
77
+ ->with('author')->where('author_name', 'LIKE', $authorName) //Fluent
78
+ ->load('comments.author') //Cascade eager-loading (joins or external query)
79
+ ->paginate(10) //Quick pagination using active request
80
+ ->getIterator();
81
+
82
+ foreach ($posts as $post) {
83
+ echo $post->author->getName();
84
+ }
85
+ ```
86
+
87
+ ``` php
88
+ $post = new Post();
89
+ $post->publish_at = 'tomorrow 8am';
90
+ $post->author = new User(['name' => 'Antony']);
91
+
92
+ $post->tags->link(new Tag(['name' => 'tag A']));
93
+ $post->tags->link($tags->findOne(['name' => 'tag B']));
94
+
95
+ $transaction = new Transaction();
96
+ $transaction->store($post);
97
+ $transaction->run();
98
+
99
+ //--or--: Active record (optional)
100
+ $post->save();
101
+
102
+ //--or--: request specific transaction
103
+ $this->transaction->store($post);
104
+ ```
0 commit comments