mirror of
https://github.com/jlengrand/exposed-wiki.git
synced 2026-03-10 08:11:18 +00:00
11
DAO.md
11
DAO.md
@@ -264,6 +264,17 @@ Similarly you can eager load references on Collections of DAO's such as Lists an
|
||||
StarWarsFilm.all().with(StarWarsFilm::actors)
|
||||
```
|
||||
NOTE: References that are eagerly loaded are stored inside the Transaction Cache, this means that they are not available in other transactions and thus must be loaded and referenced inside the same transaction.
|
||||
|
||||
#### Eager loading for Text Fields
|
||||
Some database drivers do not load text content immediately (for performance and memory reasons) which means that you can obtain the column value only within the open transaction.
|
||||
|
||||
If you desire to make content available outside the transaction, you can use the eagerLoading param when defining the DB Table.
|
||||
```kotlin
|
||||
object StarWarsFilms : Table() {
|
||||
...
|
||||
val description = text("name", eagerLoading=true)
|
||||
}
|
||||
```
|
||||
## Advanced CRUD operations
|
||||
### Read entity with a join to another table
|
||||
Let's imagine that you want to find all users who rated second SW film with more than 5.
|
||||
|
||||
@@ -18,11 +18,22 @@ val jamesList = transaction {
|
||||
}
|
||||
// jamesList is now a List<ResultRow> containing Users data
|
||||
```
|
||||
*Note:* `Blob` and `text` fields wont be available without transaction if you don't load them directly like:
|
||||
*Note:* `Blob` and `text` fields won't be available outside of a transaction if you don't load them directly. For `text` fields you can also use the `eagerLoading` param when defining the Table to make the text fields available outside of the transaction.
|
||||
```kotlin
|
||||
val idsAndContent = transaction {
|
||||
Documents.selectAll().limit(10).map { it[Documents.id] to it[Documents.content] }
|
||||
}
|
||||
// without eagerLoading
|
||||
val idsAndContent = transaction {
|
||||
Documents.selectAll().limit(10).map { it[Documents.id] to it[Documents.content] }
|
||||
}
|
||||
|
||||
// with eagerLoading for text fields
|
||||
object Documents : Table() {
|
||||
...
|
||||
val content = text("content", eagerLoading = true)
|
||||
}
|
||||
|
||||
val documentsWithContent = transaction {
|
||||
Documents.selectAll().limit(10)
|
||||
}
|
||||
```
|
||||
|
||||
### Working with a multiple databases
|
||||
|
||||
Reference in New Issue
Block a user