Comparing version 1.0.237 to 1.0.238
@@ -45,3 +45,8 @@ "use strict"; | ||
const new_piece_indices = get_constraint_results(orma_schema, fk_index, constraint, entity, record); | ||
child_indices.push(...new_piece_indices); | ||
new_piece_indices.forEach(new_piece_index => { | ||
// ignore self referential records | ||
if (new_piece_index !== piece_index) { | ||
child_indices.push(new_piece_index); | ||
} | ||
}); | ||
}); | ||
@@ -48,0 +53,0 @@ acc[piece_index] = child_indices; |
@@ -408,3 +408,3 @@ "use strict"; | ||
}); | ||
(0, mocha_1.test)('handles updates with guids', () => { | ||
(0, mocha_1.test)('handles self referencing records', () => { | ||
// must first update to the new id, then create using the new updated id | ||
@@ -414,7 +414,7 @@ const mutation_pieces = [ | ||
record: { | ||
$operation: 'update', | ||
id: 1, | ||
billing_address_id: { $guid: 'a' }, | ||
$operation: 'create', | ||
id: { $guid: 'a' }, | ||
parent_category_id: { $guid: 'a' }, | ||
}, | ||
path: ['users', 1], | ||
path: ['categories', 0], | ||
}, | ||
@@ -424,6 +424,6 @@ { | ||
$operation: 'update', | ||
email: 'aa@a.com', | ||
id: { $guid: 'a' }, // update id by email, so this needs to happen first | ||
id: 2, | ||
parent_category_id: { $guid: 'a' }, | ||
}, | ||
path: ['addresses', 0], | ||
path: ['categories', 1], | ||
}, | ||
@@ -433,3 +433,3 @@ ]; | ||
const goal = { | ||
mutation_pieces: [mutation_pieces[1], mutation_pieces[0]], | ||
mutation_pieces: [mutation_pieces[0], mutation_pieces[1]], | ||
mutation_batches: [ | ||
@@ -436,0 +436,0 @@ { start_index: 0, end_index: 1 }, |
@@ -26,3 +26,5 @@ "use strict"; | ||
const record_values = [...fields].flatMap(field => { | ||
var _a; | ||
const resolved_value = get_resolved_mutation_value_if_field(mutation_pieces, guid_map, mutation_piece.record, field); | ||
const el = (_a = (0, schema_helpers_1.get_field_schema)(orma_schema, entity, field)) === null || _a === void 0 ? void 0 : _a.$default; | ||
const value_or_default = resolved_value === undefined | ||
@@ -29,0 +31,0 @@ ? // run it through the ast parser to handle function defaults like $current_timestamp |
@@ -218,2 +218,5 @@ import { OrmaMutation } from '../types/mutation/mutation_types'; | ||
}; | ||
readonly parent_category_id: { | ||
readonly $data_type: "int"; | ||
}; | ||
readonly resource_id: { | ||
@@ -239,2 +242,9 @@ readonly $data_type: "varchar"; | ||
}]; | ||
readonly $foreign_keys: readonly [{ | ||
readonly $fields: readonly ["parent_category_id"]; | ||
readonly $references: { | ||
readonly $entity: "categories"; | ||
readonly $fields: readonly ["id"]; | ||
}; | ||
}]; | ||
}; | ||
@@ -319,2 +329,6 @@ readonly post_has_categories: { | ||
readonly to_field: "category_id"; | ||
}, { | ||
readonly from_field: "id"; | ||
readonly to_entity: "categories"; | ||
readonly to_field: "parent_category_id"; | ||
}]; | ||
@@ -321,0 +335,0 @@ }; |
@@ -242,2 +242,3 @@ "use strict"; | ||
}, | ||
parent_category_id: { $data_type: 'int' }, | ||
resource_id: { | ||
@@ -266,2 +267,9 @@ $data_type: 'varchar', | ||
], | ||
$foreign_keys: [{ | ||
$fields: ['parent_category_id'], | ||
$references: { | ||
$entity: 'categories', | ||
$fields: ['id'] | ||
}, | ||
}] | ||
}, | ||
@@ -351,2 +359,7 @@ post_has_categories: { | ||
}, | ||
{ | ||
from_field: 'id', | ||
to_entity: 'categories', | ||
to_field: 'parent_category_id', | ||
}, | ||
], | ||
@@ -353,0 +366,0 @@ }, |
{ | ||
"name": "orma", | ||
"version": "1.0.237", | ||
"version": "1.0.238", | ||
"description": "A declarative relational syncronous orm", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -75,3 +75,8 @@ import { last } from '../../helpers/helpers' | ||
) | ||
child_indices.push(...new_piece_indices) | ||
new_piece_indices.forEach(new_piece_index => { | ||
// ignore self referential records | ||
if (new_piece_index !== piece_index) { | ||
child_indices.push(new_piece_index) | ||
} | ||
}) | ||
}) | ||
@@ -78,0 +83,0 @@ |
@@ -510,3 +510,3 @@ import { expect } from 'chai' | ||
}) | ||
test('handles updates with guids', () => { | ||
test('handles self referencing records', () => { | ||
// must first update to the new id, then create using the new updated id | ||
@@ -516,7 +516,7 @@ const mutation_pieces: MutationPiece[] = [ | ||
record: { | ||
$operation: 'update', | ||
id: 1, | ||
billing_address_id: { $guid: 'a' }, | ||
$operation: 'create', | ||
id: { $guid: 'a' }, | ||
parent_category_id: { $guid: 'a' }, | ||
}, | ||
path: ['users', 1], | ||
path: ['categories', 0], | ||
}, | ||
@@ -526,6 +526,6 @@ { | ||
$operation: 'update', | ||
email: 'aa@a.com', | ||
id: { $guid: 'a' }, // update id by email, so this needs to happen first | ||
id: 2, | ||
parent_category_id: { $guid: 'a' }, | ||
}, | ||
path: ['addresses', 0], | ||
path: ['categories', 1], | ||
}, | ||
@@ -540,3 +540,3 @@ ] | ||
const goal = { | ||
mutation_pieces: [mutation_pieces[1], mutation_pieces[0]], | ||
mutation_pieces: [mutation_pieces[0], mutation_pieces[1]], | ||
mutation_batches: [ | ||
@@ -604,2 +604,2 @@ { start_index: 0, end_index: 1 }, | ||
test.skip('handles duplicate foreign key values for different entities') | ||
}) | ||
}) |
@@ -51,2 +51,3 @@ import { OrmaError } from '../../helpers/error_handling' | ||
const el = get_field_schema(orma_schema, entity, field)?.$default | ||
const value_or_default = | ||
@@ -53,0 +54,0 @@ resolved_value === undefined |
@@ -243,2 +243,3 @@ import { OrmaMutation } from '../types/mutation/mutation_types' | ||
}, | ||
parent_category_id: { $data_type: 'int' }, | ||
resource_id: { | ||
@@ -267,2 +268,9 @@ $data_type: 'varchar', | ||
], | ||
$foreign_keys: [{ | ||
$fields: ['parent_category_id'], | ||
$references: { | ||
$entity: 'categories', | ||
$fields: ['id'] | ||
}, | ||
}] | ||
}, | ||
@@ -352,2 +360,7 @@ post_has_categories: { | ||
}, | ||
{ | ||
from_field: 'id', | ||
to_entity: 'categories', | ||
to_field: 'parent_category_id', | ||
}, | ||
], | ||
@@ -362,7 +375,6 @@ }, | ||
users: 'billing_address' | 'shipping_address' | ||
posts: 'total_views' | 'my_title' | 'my_comments', | ||
posts: 'total_views' | 'my_title' | 'my_comments' | ||
$root: 'my_posts' | ||
} | ||
export type GlobalTestQuery = OrmaQuery<GlobalTestSchema, GlobalTestAliases> | ||
export type GlobalTestMutation = OrmaMutation<GlobalTestSchema> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1652432
40366