From b38b11c38c068b784ed9b81d7bebf887ca6302db Mon Sep 17 00:00:00 2001 From: gammelalf Date: Sat, 1 Jun 2024 22:48:37 +0200 Subject: [PATCH] Check BackRef's annotations to be empty --- src/fields/const_fns.rs | 23 ++++++++++++++++++++--- src/fields/types/back_ref.rs | 4 ++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/fields/const_fns.rs b/src/fields/const_fns.rs index 875148d..b0fe5e3 100644 --- a/src/fields/const_fns.rs +++ b/src/fields/const_fns.rs @@ -45,9 +45,26 @@ const_fn! { } const_fn! { - /// [`FieldType::Check`] which does nothing. - pub fn no_check(_field: Annotations, _columns: [Annotations; N]) -> Result<(), ConstString<1024>> { - Ok(()) + /// [`FieldType::Check`] which checks the explicit annotations to be empty. + pub fn disallow_annotations_check(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"])), + } } } diff --git a/src/fields/types/back_ref.rs b/src/fields/types/back_ref.rs index 57220ff..34dfecf 100644 --- a/src/fields/types/back_ref.rs +++ b/src/fields/types/back_ref.rs @@ -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}; @@ -59,7 +59,7 @@ impl FieldType for BackRef { type GetAnnotations = forward_annotations<0>; - type Check = no_check<0>; + type Check = disallow_annotations_check<0>; type GetNames = no_columns_names; }