From b529cbe758e99368d3edb9d0fe2d368392e3ed86 Mon Sep 17 00:00:00 2001 From: Jumpei Matsuda Date: Sat, 4 Sep 2021 07:01:45 +0900 Subject: [PATCH] Update optional relation's examples using optionalReferrersOn (#14) Update optional relation's examples using optionalReferrersOn --- DAO.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/DAO.md b/DAO.md index 801a1ee..a47e968 100644 --- a/DAO.md +++ b/DAO.md @@ -152,8 +152,17 @@ class UserRating(id: EntityID): IntEntity(id) { ... } ``` -Now `secondUser` will be a nullable field. -Of course, you can still use `referrersOn`. +Now `secondUser` will be a nullable field, and you should use `optionalReferrersOn` instead of `referrersOn` to get all the ratings for a `secondUser`. + +```kotlin +class User(id: EntityID): IntEntity(id) { + companion object : IntEntityClass(Users) + ... + val secondRatings by UserRating optionalReferrersOn UserRatings.secondUser // make sure to use val and optionalReferrersOn + ... +} +``` + ### many-to-many reference In some cases, a many-to-many reference may be required. Let's assume you want to add a reference to the following Actors table to the StarWarsFilm class: