Skip to content

Commit 61babb8

Browse files
Fix #[foreign_key] / #[referenced_by] compile checks to be table-pair specific (#117)
* Initial plan * Fix foreign_key/referenced_by compile checks to include both table names The compile error check identifiers previously used `this_table` as a suffix, which meant that having ANY foreign_key or referenced_by attribute on a table would satisfy the check, even if it referenced a different table. Now the identifiers include both the referenced and referencing table names, ensuring compile errors are correctly raised when specific table pairs are missing their attributes. Co-authored-by: tamaro-skaljic <49238587+tamaro-skaljic@users.noreply.github.com> * Run cargo fmt on derive-input/src/internal/dsl/method.rs Co-authored-by: tamaro-skaljic <49238587+tamaro-skaljic@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tamaro-skaljic <49238587+tamaro-skaljic@users.noreply.github.com>
1 parent 3f1959f commit 61babb8

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

derive-input/src/internal/dsl/method.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,12 +2537,14 @@ fn for_referenced_by(
25372537

25382538
let referencing_table_path = &referencing_table.path;
25392539

2540-
let compile_error_check = get_referenced_table_compile_error_check(singular_table_name);
2540+
let compile_error_check =
2541+
get_referenced_table_compile_error_check(singular_table_name, referencing_table_name);
25412542
spacetimedsl_table
25422543
.compile_error_checks
25432544
.insert(compile_error_check.clone());
25442545

2545-
let compile_error_check = get_referencing_table_compile_error_check(referencing_table_name);
2546+
let compile_error_check =
2547+
get_referencing_table_compile_error_check(referencing_table_name, singular_table_name);
25462548
compile_error_check_usages.push(quote! {
25472549
use #referencing_table_path::#compile_error_check;
25482550
});
@@ -2839,13 +2841,15 @@ fn for_foreign_key(
28392841
})
28402842
.collect_vec();
28412843

2842-
let compile_error_check = get_referencing_table_compile_error_check(singular_table_name);
2844+
let compile_error_check =
2845+
get_referencing_table_compile_error_check(singular_table_name, &referenced_table_name);
28432846

28442847
spacetimedsl_table
28452848
.compile_error_checks
28462849
.insert(compile_error_check.clone());
28472850

2848-
let compile_error_check = get_referenced_table_compile_error_check(&referenced_table_name);
2851+
let compile_error_check =
2852+
get_referenced_table_compile_error_check(&referenced_table_name, singular_table_name);
28492853

28502854
let compile_error_check_usage = quote! {
28512855
use #referenced_table_path::#compile_error_check;
@@ -3285,15 +3289,21 @@ fn get_referenced_table_function_call_for_strategy_implementation(
32853289
}
32863290
}
32873291

3288-
fn get_referenced_table_compile_error_check(referenced_table_name: &Ident) -> Ident {
3292+
fn get_referenced_table_compile_error_check(
3293+
referenced_table_name: &Ident,
3294+
referencing_table_name: &Ident,
3295+
) -> Ident {
32893296
format_ident!(
3290-
"this_compilation_error_occurs_because_the_{referenced_table_name}_table_has_no_referenced_by_attribute_referencing_this_table"
3297+
"this_compilation_error_occurs_because_the_{referenced_table_name}_table_has_no_referenced_by_attribute_referencing_the_{referencing_table_name}_table"
32913298
)
32923299
}
32933300

3294-
fn get_referencing_table_compile_error_check(referencing_table_name: &Ident) -> Ident {
3301+
fn get_referencing_table_compile_error_check(
3302+
referencing_table_name: &Ident,
3303+
referenced_table_name: &Ident,
3304+
) -> Ident {
32953305
format_ident!(
3296-
"this_compilation_error_occurs_because_the_{referencing_table_name}_table_has_no_foreign_key_attribute_referencing_this_table"
3306+
"this_compilation_error_occurs_because_the_{referencing_table_name}_table_has_no_foreign_key_attribute_referencing_the_{referenced_table_name}_table"
32973307
)
32983308
}
32993309

0 commit comments

Comments
 (0)