From 73b3853706729e4124ddd73923bcd2d2e80a12dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Sol=C3=A1?= Date: Wed, 16 Jul 2025 13:43:28 -0600 Subject: [PATCH 1/3] Pass adapterResult to column consume function --- src/orm/base_model/index.ts | 2 +- src/types/model.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/orm/base_model/index.ts b/src/orm/base_model/index.ts index 7e415ad52..75fdf5112 100644 --- a/src/orm/base_model/index.ts +++ b/src/orm/base_model/index.ts @@ -1707,7 +1707,7 @@ class BaseModelImpl implements LucidRow { */ const value = typeof attribute.consume === 'function' - ? attribute.consume(adapterResult[key], attributeName, this) + ? attribute.consume(adapterResult[key], attributeName, this, adapterResult) : adapterResult[key] /** diff --git a/src/types/model.ts b/src/types/model.ts index 7fa21e488..9aafcc115 100644 --- a/src/types/model.ts +++ b/src/types/model.ts @@ -222,7 +222,7 @@ export type ColumnOptions = { /** * Invoked when row is fetched from the database */ - consume?: (value: any, attribute: string, model: LucidRow) => any + consume?: (value: any, attribute: string, model: LucidRow, adapterResult: ModelObject) => any } /** From 45367188f71ed80a0049318544e08bf6d2952214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Sol=C3=A1?= Date: Fri, 18 Jul 2025 12:18:51 -0600 Subject: [PATCH 2/3] Add test that covers all arguments passed to consume callback --- test/orm/base_model.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/orm/base_model.spec.ts b/test/orm/base_model.spec.ts index d0aeaf2fd..93c994adf 100644 --- a/test/orm/base_model.spec.ts +++ b/test/orm/base_model.spec.ts @@ -1817,18 +1817,18 @@ test.group('Base Model | create from adapter results', (group) => { declare username: string @column({ - consume: (value) => value.toUpperCase(), + consume: (value, attribute, instance, adapterResult) => `${value.toUpperCase()} ${attribute} ${instance.constructor.name.toString()} ${adapterResult.username}`, }) declare fullName: string } - const user = User.$createFromAdapterResult({ full_name: 'virk' }) + const user = User.$createFromAdapterResult({ full_name: 'Harminder Virk', username: 'virk' }) assert.isTrue(user!.$isPersisted) assert.isFalse(user!.$isDirty) assert.isFalse(user!.$isLocal) - assert.deepEqual(user!.$attributes, { fullName: 'VIRK' }) - assert.deepEqual(user!.$original, { fullName: 'VIRK' }) + assert.deepEqual(user!.$attributes, { fullName: "HARMINDER VIRK fullName User virk", username: 'virk' }) + assert.deepEqual(user!.$original, { fullName: "HARMINDER VIRK fullName User virk", username: 'virk' }) }) test('original and attributes should not be shared', async ({ fs, assert }) => { From 57df8fabaf65f00edcc1f3038bf58af05de1016b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Sol=C3=A1?= Date: Fri, 5 Sep 2025 09:36:51 -0600 Subject: [PATCH 3/3] Formatting --- test/orm/base_model.spec.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/orm/base_model.spec.ts b/test/orm/base_model.spec.ts index 93c994adf..cfe34fbae 100644 --- a/test/orm/base_model.spec.ts +++ b/test/orm/base_model.spec.ts @@ -1817,7 +1817,8 @@ test.group('Base Model | create from adapter results', (group) => { declare username: string @column({ - consume: (value, attribute, instance, adapterResult) => `${value.toUpperCase()} ${attribute} ${instance.constructor.name.toString()} ${adapterResult.username}`, + consume: (value, attribute, instance, adapterResult) => + `${value.toUpperCase()} ${attribute} ${instance.constructor.name.toString()} ${adapterResult.username}`, }) declare fullName: string } @@ -1827,8 +1828,14 @@ test.group('Base Model | create from adapter results', (group) => { assert.isTrue(user!.$isPersisted) assert.isFalse(user!.$isDirty) assert.isFalse(user!.$isLocal) - assert.deepEqual(user!.$attributes, { fullName: "HARMINDER VIRK fullName User virk", username: 'virk' }) - assert.deepEqual(user!.$original, { fullName: "HARMINDER VIRK fullName User virk", username: 'virk' }) + assert.deepEqual(user!.$attributes, { + fullName: 'HARMINDER VIRK fullName User virk', + username: 'virk', + }) + assert.deepEqual(user!.$original, { + fullName: 'HARMINDER VIRK fullName User virk', + username: 'virk', + }) }) test('original and attributes should not be shared', async ({ fs, assert }) => {