Skip to content

Commit

Permalink
add API links
Browse files Browse the repository at this point in the history
  • Loading branch information
vnikolova committed Jan 31, 2025
1 parent 72d7c21 commit 2fbdd28
Showing 1 changed file with 47 additions and 14 deletions.
61 changes: 47 additions & 14 deletions documentation-website/Writerside/topics/DAO-Relationships.topic
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@
</p>
<p>
You can implement this relationship by using a reference column in the child table
(<code>UserRatingsTable</code>) that links to the parent table (<code>UsersTable</code>):
(<code>UserRatingsTable</code>) that links to the parent table (<code>UsersTable</code>). To create a
reference column, use the
<a href="https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/-table/reference.html">
<code>reference()</code>
</a>
function:
</p>
<tabs>
<tab id="user-ratings-table" title="UserRatingsTable">
Expand Down Expand Up @@ -82,8 +87,11 @@
<chapter title="Reverse access" id="reverse-access">
<p>
If you wanted to get all the ratings for a film, you could do that by using the <code>.find()</code>
function of the entity class. However, it is much easier to add a <code>referrersOn</code> field to the
class representing the film, <code>StarWarsFilmEntity</code>:
function of the entity class. However, it is much easier to add a
<a href="https://jetbrains.github.io/Exposed/api/exposed-dao/org.jetbrains.exposed.dao/-entity-class/referrers-on.html">
<code>referrersOn</code>
</a>
field to the class representing the film, <code>StarWarsFilmEntity</code>:
</p>
<code-block lang="kotlin"
src="exposed-dao-relationships/src/main/kotlin/org/example/entities/StarWarsFilmEntity.kt"
Expand All @@ -99,7 +107,10 @@
</chapter>
<chapter title="Back reference" id="back-reference">
<p>
If each user rates only one film, you can define a <code>backReferencedOn</code>
If each user rates only one film, you can define a
<a href="https://jetbrains.github.io/Exposed/api/exposed-dao/org.jetbrains.exposed.dao/-entity-class/back-referenced-on.html">
<code>backReferencedOn</code>
</a>
field to the entity class to access the <code>UserRatingsTable</code> data:
</p>
<code-block lang="kotlin"
Expand All @@ -116,8 +127,15 @@
<p>In Exposed, you can also add an optional reference.</p>
<p>
For example, if you want to include anonymous user ratings to your table, you can do so by setting
the reference field as optional using <code>optReference()</code> in your table and
<code>optionalReferencedOn</code> in your entity definition:
the reference field as optional using
<a href="https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/-table/opt-reference.html">
<code>optReference()</code>
</a>
in your table and
<a href="https://jetbrains.github.io/Exposed/api/exposed-dao/org.jetbrains.exposed.dao/-entity-class/optional-referenced-on.html">
<code>optionalReferencedOn</code>
</a>
in your entity definition:
</p>
<tabs>
<tab id="user-ratings-table-with-optional-reference" title="UserRatingsWithOptionalUserTable">
Expand Down Expand Up @@ -150,8 +168,8 @@
src="exposed-dao-relationships/src/main/kotlin/org/example/entities/UserEntity.kt"
include-lines="23-27,37-41"
/>
<p>Without using the <a href="https://kotlinlang.org/docs/functions.html#infix-notation">infix notation</a>, the <code>orderBy</code> method is chained
after <code>referrersOn</code>:</p>
<p>Without using the <a href="https://kotlinlang.org/docs/functions.html#infix-notation">infix notation</a>,
the <code>orderBy</code> method is chained after <code>referrersOn</code>:</p>
<code-block lang="kotlin"
src="exposed-dao-relationships/src/main/kotlin/org/example/entities/UserEntity.kt"
include-lines="23-27,32-35,41"
Expand Down Expand Up @@ -190,8 +208,13 @@
src="exposed-dao-relationships/src/main/kotlin/org/example/tables/ActorsTable.kt"
include-symbol="StarWarsFilmActorsTable"
/>
<p>Add a reference to the <code>ActorEntity</code> in the <code>StarWarsFilmEntity</code> using the
<code>via</code> keyword:</p>
<p>
Add a reference to the <code>ActorEntity</code> in the <code>StarWarsFilmEntity</code> using the
<a href="https://jetbrains.github.io/Exposed/api/exposed-dao/org.jetbrains.exposed.dao/-entity/via.html">
<code>via</code>
</a>
function:
</p>
<code-block lang="kotlin"
src="exposed-dao-relationships/src/main/kotlin/org/example/entities/StarWarsFilmEntity.kt"
include-lines="26"
Expand Down Expand Up @@ -270,7 +293,11 @@
include-symbol="StarWarsFilmsWithCompositeRefTable"
/>
<p>
Then, add the field to the entity using the <code>referencedOn</code> function:
Then, add the field to the entity using the
<a href="https://jetbrains.github.io/Exposed/api/exposed-dao/org.jetbrains.exposed.dao/-entity-class/referenced-on.html">
<code>referencedOn</code>
</a>
function:
</p>
<code-block lang="kotlin"
src="exposed-dao-relationships/src/main/kotlin/org/example/entities/StarWarsFilmEntity.kt"
Expand Down Expand Up @@ -345,8 +372,11 @@
<chapter title="Loading collections" id="eager-loading-collections">
<p>
To eagerly load references on <code>Collections</code> of DAO's such as <code>List</code>
and <code>SizedIterable</code>, use the <code>.with()</code> function and pass
each reference as <code>KProperty</code>:
and <code>SizedIterable</code>, use the
<a href="https://jetbrains.github.io/Exposed/api/exposed-dao/org.jetbrains.exposed.dao/with.html">
<code>.with()</code>
</a>
function and pass each reference as <code>KProperty</code>:
</p>
<code-block lang="kotlin"
src="exposed-dao-relationships/src/main/kotlin/org/example/examples/EagerLoadingExamples.kt"
Expand All @@ -368,7 +398,10 @@
This means that you can obtain the column value only within the open transaction.
</p>
<p>
To make content available outside the transaction, use the <code>eagerLoading</code>
To make content available outside the transaction, use the
<a href="https://jetbrains.github.io/Exposed/api/exposed-core/org.jetbrains.exposed.sql/-text-column-type/eager-loading.html">
<code>eagerLoading</code>
</a>
parameter in your field definition:
</p>
<code-block lang="kotlin">
Expand Down

0 comments on commit 2fbdd28

Please sign in to comment.