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
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,17 +71,17 @@ Nette Database Explorer layer helps you to fetch database data more easily and i
71
71
72
72
Let's take a look at common use-case. You need to fetch books and their authors. It is common 1:N relationship. The often used implementation fetches data by one SQL query with table joins. The second possibility is to fetch data separately, run one query for getting books and then get an author for each book by another query (e.g. in your foreach cycle). This could be easily optimized to run only two queries, one for books, and another for the needed authors - and this is just the way how Nette Database Explorer does it.
73
73
74
-
Selecting data starts with the table, just call `$context->table()` on the `Nette\Database\Explorer` object. The easiest way to get it is [described here](https://doc.nette.org/database-core#toc-configuration), but if we use Nette Database Explorer alone, it can be [manually created](https://doc.nette.org/database-explorer#toc-manual-creating-nette-database-context).
74
+
Selecting data starts with the table, just call `$explorer->table()` on the `Nette\Database\Explorer` object. The easiest way to get it is [described here](https://doc.nette.org/database-core#toc-configuration), but if we use Nette Database Explorer alone, it can be [manually created](https://doc.nette.org/database-explorer#toc-manual-creating-nette-database-context).
75
75
76
76
77
77
```php
78
-
$selection = $context->table('book'); // db table name is "book"
78
+
$selection = $explorer->table('book'); // db table name is "book"
79
79
```
80
80
81
81
We can simply iterate over the selection and pass through all the books. The rows are fetched as ActiveRow instances; you can read row data from their properties.
82
82
83
83
```php
84
-
$books = $context->table('book');
84
+
$books = $explorer->table('book');
85
85
foreach ($books as $book) {
86
86
echo $book->title;
87
87
echo $book->author_id;
@@ -91,7 +91,7 @@ foreach ($books as $book) {
91
91
Getting just one specific row is done by `get()` method, which directly returns an ActiveRow instance.
92
92
93
93
```php
94
-
$book = $context->table('book')->get(2); // returns book with id 2
94
+
$book = $explorer->table('book')->get(2); // returns book with id 2
0 commit comments