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: doc/advanced.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -59,6 +59,6 @@ there is no way to know if it more likely that he wanted users from the birth co
59
59
60
60
This exception message is quite clear on the ambiguity.
61
61
62
-
Solving ambiguities is always possible by [manually specifying joins](quickstart.html#joins-ans-filters) in your queries.
62
+
Solving ambiguities is always possible by [manually specifying joins](quickstart.md#joins-ans-filters) in your queries.
63
63
64
64
<divclass="alert alert-warning">Note: If your data model has a lot of loops, you will likely face a lot of ambiguities. TDBM is very well suited for simple models. If your database model is complex enough to feature several of these loops, maybe TDBM is not the best tool for you. There are other great tools more suited for those use cases like <ahref="http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/">Doctrine ORM</a> for instance.</div>
Copy file name to clipboardExpand all lines: doc/generating_daos.md
+8-4
Original file line number
Diff line number
Diff line change
@@ -44,13 +44,13 @@ The way you generate DAOs and beans **depends on the framework you use**.
44
44
TDBM has a feature allowing you to access the database directly through the <code>TDBMService</code>, without generating DAOs or beans.
45
45
This is mostly for testing purpose and is not recommended. Should you need it, you can check the <code>tests/TDBMServiceTest.php</code> file for usage samples.</div>
46
46
47
-
The DAOs and beans structure
47
+
The DAOs, beans, resultIterators structure
48
48
----------------------------
49
49
50
-
For each table in your database, TDBM will generate a DAOand a bean. The DAO is the object you will use to
51
-
query the database. Each row of the database will be mapped to a bean object.
50
+
For each table in your database, TDBM will generate a DAO, a bean and a resultIterator. The DAO is the object you will use to
51
+
query the database and will return a bean or a resultIterator. Each row of the database will be mapped to a bean object.
52
52
53
-
Both DAOsand beans are divided in 2 parts. Let's assume you have a "users" table. TDBM will generate those classes for you:
53
+
DAOs, beans and resultIterators are divided in 2 parts. Let's assume you have a "users" table. TDBM will generate those classes for you:
54
54
55
55
56
56
-`AbstractUserDao`: the base class that contains methods to access the "users" table. It is generated by TDBM and you should
@@ -62,6 +62,10 @@ Both DAOs and beans are divided in 2 parts. Let's assume you have a "users" tabl
62
62
never modify this class.
63
63
-`User`: this class extends AbstractUser. If you have some custom getters and setters, you should implement them in this class. You can
64
64
edit it as TDBM will never overwrite it.
65
+
-`AbstractUserResultIterator`: the resultIterator representing a query on the "users" table. This class contains methods to specify you query.
66
+
It is generated by TDBM and you should never modify this class.
67
+
-`UserResultIterator`: this class extends `AbstractUserResultIterator`. If you have some custom function to narrow down your queries you should implement them in this class. You can
68
+
edit it as TDBM will never overwrite it.
65
69
66
70
Let's now have a closer look at the methods that are available in the "UserDao" class:
Copy file name to clipboardExpand all lines: doc/quickstart.md
+37-25
Original file line number
Diff line number
Diff line change
@@ -19,16 +19,28 @@ For this tutorial, let's assume a very classic database schema for handling user
19
19
20
20

21
21
22
-
DAOsand beans
22
+
DAOs, Beans and ResultIterators
23
23
--------------
24
24
25
-
When you [installed TDBM](install.md), you spent some time configuring a connection to your database and then, you generated the DAOsand beans.
25
+
When you [installed TDBM](install.md), you spent some time configuring a connection to your database and then, you generated the DAOs, beans and resultIterators.
26
26
27
-
DAOs are "Data Access Objects". DAOs are classes that will help you access
28
-
the objects in your database. There is roughly **one DAO per table in your database**. Each DAO will return "beans". Each row in your database
29
-
will be represented by one instance of a bean.
27
+
There will be roughly **one class (DAO, Bean, ResultIterator) per table**, in fact only ManyToMany link tables won't get their class.
30
28
31
-
Each time your database model changes (if you add a new table, a new column, an index or a foreign key...), you will need to regenerate those DAOs and beans.
29
+
Each time your database model changes (if you add a new table, a new column, an index or a foreign key...), you will need to regenerate those DAOs, beans and resultIterators.
30
+
31
+
### DAOs
32
+
33
+
DAOs are "Data Access Objects". DAOs are classes that will help you access the objects in your database.
34
+
Each DAO will return a Bean or a ResultIterator (collection of Beans).
35
+
36
+
### Beans
37
+
38
+
Each row in your database will be represented by one instance of a bean.
39
+
This instance will allow you to easily update your data using setters and getters strongly typed by TDBM or created by you.
40
+
41
+
### ResultIterators
42
+
43
+
A ResultIterator will represent the result of a query. It will allow you to specify it.
32
44
33
45
Usage sample
34
46
------------
@@ -45,7 +57,7 @@ $user = new User("myName");
45
57
// Fill the remaining (nullable) columns of the bean using the setters
a `UserDao` class and a `User` class. `UserDao` can be used to create/update/delete/search any
59
-
user.
69
+
Since we have a "users" table, TDBM generated a `UserDao` class, a `User` class and a `UserResultIterator` class.
70
+
`UserDao` can be used to create/update/delete/search any user.
60
71
61
72
You can also notice that the "save()" method is called on the `UserDao`, not on the `User`.
62
73
@@ -73,9 +84,6 @@ echo $user->getName();
73
84
TDBM will automatically detect the primary key of your table (of course, your table must have a primary key). There is
74
85
no name convention to respect, your primary key column can be named anything ('id', 'userid', 'iduser', ...)
75
86
76
-
To use this method, the primary key must be on a single column. If your primary key is on several columns, you can still use the
77
-
search method (see below).
78
-
79
87
###Querying the database
80
88
81
89
Now, what about getting the list of all users and displaying their name?
@@ -103,7 +111,7 @@ Bill Shakespeare
103
111
```
104
112
105
113
106
-
The `findAll` method will return the list of beans.
114
+
The `findAll` method will return the list of beans as a `UserResultIterator`.
107
115
Of course, most of the time, you don't want all the rows in a database.
108
116
You want to perform a query with filters.
109
117
@@ -177,6 +185,10 @@ generated 4 classes:
177
185
column of the "users" table. It is generated by TDBM and you should never modify this class.
178
186
-`User`: this class extends `AbstractUser`. If you have some custom getters and setters, you should implement them in this class. You can
179
187
edit it as TDBM will never overwrite it.
188
+
-`AbstractUserResultIterator`: the resultIterator representing a query on the "users" table. This class contains methods to specify you query.
189
+
It is generated by TDBM and you should never modify this class.
190
+
-`UserResultIterator`: this class extends `AbstractUserResultIterator`. If you have some custom function to narrow down your queries you should implement them in this class. You can
191
+
edit it as TDBM will never overwrite it.
180
192
181
193
182
194
In our example, we want to perform a query that retrieves any name starting with a "J". This is a new
@@ -191,7 +203,7 @@ class UserDao extends AbstractUserDao {
191
203
* Returns the list of users starting with $firstLetter
192
204
*
193
205
* @param string $firstLetter
194
-
* @return User[]
206
+
* @return UserResultIterator
195
207
*/
196
208
public function findUsersByLetter($firstLetter) {
197
209
// The find can be used to retrieve a list of User
@@ -246,7 +258,7 @@ class ProductDao extends AbstractProductDao {
246
258
*
247
259
* @param Category $category
248
260
* @param Store $store
249
-
* @return Country[]
261
+
* @return CountryResultIterator
250
262
*/
251
263
public function getProductsByCategoryAndStore(Category $category = null, Store $store = null) {
252
264
return $this->find("category = :category AND store = :store", [
@@ -403,7 +415,7 @@ class UserDao extends AbstractUserDao {
403
415
* Returns the list of users whose country name starts by "$countryName"
404
416
*
405
417
* @param string $countryName
406
-
* @return User[]
418
+
* @return UserResultIterator
407
419
*/
408
420
public function getUsersByCountryName($countryName) {
409
421
// Behold the magic!
@@ -433,7 +445,7 @@ class UserDao extends AbstractUserDao {
433
445
* Returns the list of users whose country is "$country"
434
446
*
435
447
* @param Country $country
436
-
* @return User[]
448
+
* @return UserResultIterator
437
449
*/
438
450
public function getUsersByCountry(Country $country) {
439
451
// You can pass a Country instance directly to the find method!
@@ -469,7 +481,7 @@ class CountryDao extends AbstractCountryDao {
469
481
* Returns the list of countries whose country name starts by "$countryName"
470
482
*
471
483
* @param string $countryName
472
-
* @return Country[]
484
+
* @return CountryResultIterator
473
485
*/
474
486
public function findByCountryName($countryName) {
475
487
return $this->find("name LIKE :country", [ 'country' => $countryName.'%' ] );
@@ -492,7 +504,7 @@ class UserDao extends AbstractUserDao {
492
504
* Returns the list of users whose country name starts by "$countryName"
493
505
*
494
506
* @param string $countryName
495
-
* @return User[]
507
+
* @return UserResultIterator
496
508
*/
497
509
public function getUsersByCountryName($countryName) {
Copy file name to clipboardExpand all lines: index.md
+4-2
Original file line number
Diff line number
Diff line change
@@ -38,12 +38,14 @@ TDBM is an opiniated ORM. It will not suit everybody and all needs. Here is what
38
38
39
39
TDBM is a "database first" ORM. Everything starts from your database. TDBM is very good at understanding your database model and the intent behind it. It will generate PHP objects mapping your model.
0 commit comments