|
|
|
|
@ -82,21 +82,12 @@ fun <T : RealmModel>Realm.updateUsageCount(clazz: Class<T>) { |
|
|
|
|
results.forEach { countableUsage -> |
|
|
|
|
|
|
|
|
|
val countable = (countableUsage as CountableUsage) |
|
|
|
|
when (clazz) { |
|
|
|
|
is TournamentFeature -> { |
|
|
|
|
countable.useCount = it.where<Session>().contains( |
|
|
|
|
"tournamentFeatures.id", |
|
|
|
|
countable.id |
|
|
|
|
).count().toInt() |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
countable.useCount = it.where<Session>().equalTo( |
|
|
|
|
"${clazz.simpleName.decapitalize()}.id", |
|
|
|
|
countable.id |
|
|
|
|
).count().toInt() |
|
|
|
|
} |
|
|
|
|
val fieldName = when (clazz) { |
|
|
|
|
is TournamentFeature -> "tournamentFeatures.id" |
|
|
|
|
else -> "${clazz.simpleName.decapitalize()}.id" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val count = it.where<Session>().contains(fieldName, countable.id).count().toInt() |
|
|
|
|
countable.useCount = count |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|