Skip to content

Commit

Permalink
Check BackRef's annotations to be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
gammelalf committed Sep 8, 2024
1 parent c26cbc3 commit b38b11c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions src/fields/const_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,26 @@ const_fn! {
}

const_fn! {
/// [`FieldType::Check`] which does nothing.
pub fn no_check<const N: usize>(_field: Annotations, _columns: [Annotations; N]) -> Result<(), ConstString<1024>> {
Ok(())
/// [`FieldType::Check`] which checks the explicit annotations to be empty.
pub fn disallow_annotations_check<const N: usize>(field: Annotations, _columns: [Annotations; N]) -> Result<(), ConstString<1024>> {
match field {
Annotations {
auto_create_time: None,
auto_update_time: None,
auto_increment: None,
choices: None,
default: None,
index: None,
max_length: None,
on_delete: None,
on_update: None,
primary_key: None,
unique: None,
nullable: false,
foreign: None,
} => Ok(()),
_ => Err(ConstString::error(&["BackRef doesn't take any annotations"])),
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/fields/types/back_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rorm_declaration::imr;
use crate::conditions::collections::CollectionOperator::Or;
use crate::conditions::{Binary, BinaryOperator, Column, Condition, DynamicCollection, Value};
use crate::crud::decoder::NoopDecoder;
use crate::fields::const_fns::{forward_annotations, no_check, no_columns_names};
use crate::fields::const_fns::{disallow_annotations_check, forward_annotations, no_columns_names};
use crate::fields::traits::{Array, FieldColumns, FieldType};
use crate::internal::field::foreign_model::{ForeignModelField, ForeignModelTrait};
use crate::internal::field::{foreign_model, Field, FieldProxy, SingleColumnField};
Expand Down Expand Up @@ -59,7 +59,7 @@ impl<FMF: ForeignModelField> FieldType for BackRef<FMF> {

type GetAnnotations = forward_annotations<0>;

type Check = no_check<0>;
type Check = disallow_annotations_check<0>;

type GetNames = no_columns_names;
}
Expand Down

0 comments on commit b38b11c

Please sign in to comment.