diff --git a/api/spec/unit/models/Host.spec.ts b/api/spec/unit/models/Host.spec.ts
index 6648798..c617d51 100644
--- a/api/spec/unit/models/Host.spec.ts
+++ b/api/spec/unit/models/Host.spec.ts
@@ -28,4 +28,13 @@ describe('Host', () => {
expect(localizedText.locale).toEqual('en-US')
})
})
+
+ it('has one currentLocalizedText', async () => {
+ let host = await createHost()
+ const esLocalizedText = await createLocalizedText({ localizable: host, locale: 'es-ES' })
+
+ host = await host.passthrough({ locale: 'es-ES' }).load('currentLocalizedText').execute()
+
+ expect(host.currentLocalizedText).toMatchDreamModel(esLocalizedText)
+ })
})
diff --git a/api/spec/unit/models/Place.spec.ts b/api/spec/unit/models/Place.spec.ts
index 6aa9bb6..41fa65d 100644
--- a/api/spec/unit/models/Place.spec.ts
+++ b/api/spec/unit/models/Place.spec.ts
@@ -29,4 +29,13 @@ describe('Place', () => {
expect(localizedText.title).toEqual('My cottage')
})
})
+
+ it('has one currentLocalizedText', async () => {
+ let place = await createPlace()
+ const esLocalizedText = await createLocalizedText({ localizable: place, locale: 'es-ES' })
+
+ place = await place.passthrough({ locale: 'es-ES' }).load('currentLocalizedText').execute()
+
+ expect(place.currentLocalizedText).toMatchDreamModel(esLocalizedText)
+ })
})
diff --git a/api/spec/unit/models/Room.spec.ts b/api/spec/unit/models/Room.spec.ts
index 021a823..cba31fa 100644
--- a/api/spec/unit/models/Room.spec.ts
+++ b/api/spec/unit/models/Room.spec.ts
@@ -18,4 +18,13 @@ describe('Room', () => {
expect(localizedText.locale).toEqual('en-US')
})
})
+
+ it('has one currentLocalizedText', async () => {
+ let room = await createDen()
+ const esLocalizedText = await createLocalizedText({ localizable: room, locale: 'es-ES' })
+
+ room = await room.passthrough({ locale: 'es-ES' }).load('currentLocalizedText').execute()
+
+ expect(room.currentLocalizedText).toMatchDreamModel(esLocalizedText)
+ })
})
diff --git a/api/src/app/models/Host.ts b/api/src/app/models/Host.ts
index 5cb2091..306f6bc 100644
--- a/api/src/app/models/Host.ts
+++ b/api/src/app/models/Host.ts
@@ -1,4 +1,4 @@
-import { Decorators, Dream, DreamTransaction, SoftDelete } from '@rvoh/dream'
+import { Decorators, Dream, DreamConst, DreamTransaction, SoftDelete } from '@rvoh/dream'
import { DreamColumn, DreamSerializers } from '@rvoh/dream/types'
import ApplicationModel from '#models/ApplicationModel.js'
import HostPlace from '#models/HostPlace.js'
@@ -43,4 +43,11 @@ export default class Host extends ApplicationModel {
public async createDefaultLocalizedText(this: Host, txn: DreamTransaction<Dream> | null) {
await this.txn(txn).createAssociation('localizedTexts', { locale: 'en-US' })
}
+
+ @deco.HasOne('LocalizedText', {
+ polymorphic: true,
+ on: 'localizableId',
+ and: { locale: DreamConst.passthrough },
+ })
+ public currentLocalizedText: LocalizedText
}
diff --git a/api/src/app/models/Place.ts b/api/src/app/models/Place.ts
index 20b369a..c063540 100644
--- a/api/src/app/models/Place.ts
+++ b/api/src/app/models/Place.ts
@@ -1,4 +1,4 @@
-import { Decorators, Dream, DreamTransaction, SoftDelete } from '@rvoh/dream'
+import { Decorators, Dream, DreamConst, DreamTransaction, SoftDelete } from '@rvoh/dream'
import { DreamColumn, DreamSerializers } from '@rvoh/dream/types'
import ApplicationModel from '#models/ApplicationModel.js'
import Host from '#models/Host.js'
@@ -45,4 +45,11 @@ export default class Place extends ApplicationModel {
public async createDefaultLocalizedText(this: Place, txn: DreamTransaction<Dream> | null) {
await this.txn(txn).createAssociation('localizedTexts', { locale: 'en-US', title: `My ${this.style}` })
}
+
+ @deco.HasOne('LocalizedText', {
+ polymorphic: true,
+ on: 'localizableId',
+ and: { locale: DreamConst.passthrough },
+ })
+ public currentLocalizedText: LocalizedText
}
diff --git a/api/src/app/models/Room.ts b/api/src/app/models/Room.ts
index b8565d9..4a48792 100644
--- a/api/src/app/models/Room.ts
+++ b/api/src/app/models/Room.ts
@@ -1,4 +1,4 @@
-import { Decorators, Dream, DreamTransaction, SoftDelete } from '@rvoh/dream'
+import { Decorators, Dream, DreamConst, DreamTransaction, SoftDelete } from '@rvoh/dream'
import { DreamColumn, DreamSerializers } from '@rvoh/dream/types'
import ApplicationModel from '#models/ApplicationModel.js'
import LocalizedText from '#models/LocalizedText.js'
@@ -37,4 +37,11 @@ export default class Room extends ApplicationModel {
public async createDefaultLocalizedText(this: Room, txn: DreamTransaction<Dream> | null) {
await this.txn(txn).createAssociation('localizedTexts', { locale: 'en-US' })
}
+
+ @deco.HasOne('LocalizedText', {
+ polymorphic: true,
+ on: 'localizableId',
+ and: { locale: DreamConst.passthrough },
+ })
+ public currentLocalizedText: LocalizedText
}
diff --git a/api/src/types/dream.ts b/api/src/types/dream.ts
index 188991c..d73f541 100644
--- a/api/src/types/dream.ts
+++ b/api/src/types/dream.ts
@@ -295,6 +295,15 @@ export const schema = {
},
virtualColumns: [],
associations: {
+ currentLocalizedText: {
+ type: 'HasOne',
+ foreignKey: 'localizableId',
+ foreignKeyTypeColumn: 'localizableType',
+ tables: ['localized_texts'],
+ optional: null,
+ requiredAndClauses: null,
+ passthroughAndClauses: ['locale'],
+ },
hostPlaces: {
type: 'HasMany',
foreignKey: 'hostId',
@@ -528,6 +537,15 @@ export const schema = {
},
virtualColumns: [],
associations: {
+ currentLocalizedText: {
+ type: 'HasOne',
+ foreignKey: 'localizableId',
+ foreignKeyTypeColumn: 'localizableType',
+ tables: ['localized_texts'],
+ optional: null,
+ requiredAndClauses: null,
+ passthroughAndClauses: ['locale'],
+ },
hostPlaces: {
type: 'HasMany',
foreignKey: 'placeId',
@@ -678,6 +696,15 @@ export const schema = {
},
virtualColumns: [],
associations: {
+ currentLocalizedText: {
+ type: 'HasOne',
+ foreignKey: 'localizableId',
+ foreignKeyTypeColumn: 'localizableType',
+ tables: ['localized_texts'],
+ optional: null,
+ requiredAndClauses: null,
+ passthroughAndClauses: ['locale'],
+ },
localizedTexts: {
type: 'HasMany',
foreignKey: 'localizableId',
@@ -793,7 +820,7 @@ export const schema = {
} as const
export const connectionTypeConfig = {
- passthroughColumns: [],
+ passthroughColumns: ['locale'],
allDefaultScopeNames: ['dream:STI', 'dream:SoftDelete'],
globalNames: {
models: {