Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/database",
"version": "5.56.0",
"version": "5.57.0",
"description": "The Athenna database handler for SQL/NoSQL.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
6 changes: 5 additions & 1 deletion src/models/BaseModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,11 @@ export class BaseModel {
Object.keys(copied).forEach(key => {
const value = this[key]

if (Is.Array(value) && value[0] && ORIGINAL_SYMBOL in value[0]) {
if (
Is.Array(value) &&
Is.Object(value[0]) &&
ORIGINAL_SYMBOL in value[0]
) {
return
}

Expand Down
5 changes: 1 addition & 4 deletions src/models/relations/HasOneThrough/HasOneThroughRelation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ export class HasOneThroughRelation {
models: BaseModel[],
relation: HasOneThroughOptions
): Promise<any[]> {
const result = await HasManyThroughRelation.loadAll(
models,
relation as any
)
const result = await HasManyThroughRelation.loadAll(models, relation as any)

return result.map(m => {
const arr = (m[relation.property] as any[]) || []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ export class ThroughTablesMigration extends BaseMigration {
await db.createTable('sale_items', table => {
table.increments('id')
table.integer('quantity').defaultTo(1)
table
.integer('appointmentId')
.unsigned()
.references('id')
.inTable('appointments')
table.integer('appointmentId').unsigned().references('id').inTable('appointments')
table.integer('saleId').unsigned().references('id').inTable('sales')
})
}
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/models/BaseModelTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,20 @@ export default class BaseModelTest {
assert.isTrue(user.isPersisted())
}

@Test()
public async shouldBeAbleToSetOriginalWhenModelHasAnArrayOfPrimitivesValue({ assert }: Context) {
const user = new User()

user.id = '1'
user.name = 'lenon'
user.metadata4 = { name: 'lenon', age: 30, address: { city: 'foo', state: 'bar' } } as any
;(user as any).images = ['https://example.com/a.png', 'https://example.com/b.png']

assert.doesNotThrow(() => user.setOriginal())
assert.isTrue(user.isPersisted())
assert.isFalse(user.isDirty())
}

@Test()
public async shouldBeAbleToValidateThatAModelIsDirty({ assert }: Context) {
const user = new User()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export default class HasOneThroughRelationTest {
{ id: 1, name: 'South' },
{ id: 2, name: 'North' }
])
await pg.table('members').createMany([
{ id: 1, name: 'lenon', regionId: 1 }
])
await pg.table('members').createMany([{ id: 1, name: 'lenon', regionId: 1 }])
await pg.table('articles').createMany([
{ id: 1, title: 'first', memberId: 1 },
{ id: 2, title: 'second', memberId: 1 }
Expand Down
Loading