You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-23Lines changed: 37 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,18 @@
1
1
Lean Mapper Query
2
2
=================
3
3
4
-
Lean Mapper Query is a concept of a *query object* for [Lean Mapper library](https://github.com/Tharos/LeanMapper) which helps to build complex queries using automatic joins (*idea taken from [NotORM library](http://www.notorm.com/)*). Look at the [suggested base classes](https://gist.github.com/mibk/9410266). For Czech documentation have a look at the [wiki](https://github.com/mibk/LeanMapperQuery/wiki).
4
+
Lean Mapper Query is a concept of a *query object* for
5
+
[Lean Mapper library](https://github.com/Tharos/LeanMapper) which helps to build complex
6
+
queries using automatic joins (*idea taken from [NotORM library](http://www.notorm.com/)*).
7
+
Look at the [suggested base classes](https://gist.github.com/mibk/9410266). For Czech
8
+
documentation have a look at the [wiki](https://github.com/mibk/LeanMapperQuery/wiki).
5
9
6
10
Features
7
11
--------
8
12
9
-
-it behaves as an`SQL` preprocessor, hence most SQL expressions are available
10
-
- automatic joins using *dot notation* (`@book.tags.name`)
11
-
- ability to query both repositories or entities
13
+
- behaves as a`SQL` preprocessor, hence most SQL expressions are available
14
+
- automatic joins using the *dot notation* (`@book.tags.name`)
It is also possible to query an entity property (*currently only those properties with `BelongsToMany` or `HasMany` relationships*). Let's build `BaseEntity`:
152
+
It is also possible to query an entity property (*currently only those properties with
153
+
`BelongsToMany` or `HasMany` relationships*). Let's make the `BaseEntity` class:
145
154
146
155
```php
147
156
class BaseEntity extends LeanMapperQuery\Entity
@@ -163,9 +172,10 @@ class Book extends BaseEntity
163
172
}
164
173
```
165
174
166
-
*Note that `BaseEntity`extends`LeanMapperQuery\Entity` to make the following possible.*
175
+
*Note that `BaseEntity`must extend`LeanMapperQuery\Entity` to make the following possible.*
167
176
168
-
We have defined the `find` method as `protected` because with specifying the method name in `$magicMethodsPrefixes` property you can query entities like this:
177
+
We have defined the `find` method as `protected` because by specifying the method name in the
178
+
`$magicMethodsPrefixes` property, you can query entities like this:
169
179
170
180
```php
171
181
$book; // previously fetched instance of an entity from a repository
*The magic method `findTags` will eventually call your protected method `find` with 'tags' as the 1 argument.*
187
+
*The magic method `findTags` will eventually call your protected method `find` with 'tags' as
188
+
the 1st argument.*
178
189
179
190
The resulting database query looks like this:
180
191
@@ -184,13 +195,16 @@ FROM [tag]
184
195
WHERE [tag].[id] IN (1, 2) AND ([tag].[name] !='ebook')
185
196
```
186
197
187
-
The first condition in where clause `[tag].[id] IN (1, 2)` is taken from the entity traversing (*tags are queried against this particular book entity's own tags*).
198
+
The first condition in the `where` clause, `[tag].[id] IN (1, 2)`, is taken from the entity
199
+
traversing (*tags are queried against this particular book entity's own tags*).
188
200
189
201
190
202
What else you can do?
191
203
---------------------
192
204
193
-
If we slightly modify our `BaseRepository` and `BaseEntity` we can simplify working with query objects. *To achieve this look at the [suggested base classes](https://gist.github.com/mbohuslavek/9410266)*. It makes the following possible.
205
+
If we slightly modify `BaseRepository` and `BaseEntity`, we can simplify working with query objects.
206
+
*To achieve this look at the [suggested base classes](https://gist.github.com/mibk/9410266)*. It makes
0 commit comments