added FT class which is used in Model::field() methods

FT class has following types:
   enum FieldType
   {
	default_type = 0,
        primary_key = 1,
	foreign_key = 2,
	foreign_key_in_child = 4,
	no_insertable = 8,
	no_updatable = 16,
	no_fetchable = 32, /* not supported yet */
   };
an object of FT class are now used in Model::field() methods instead of insertable/updatable/is_primary_key/... boolean flags

changed the semantic of has_foreign_key (which was a bool) flag in child Models:
now on Models and list/vector of Models you should use either FT::foreign_key or FT::foreign_key_in_child
1. FT::foreign_key means that field with this flag is a foreign key and is pointing to the child object
   (it was the case when has_foreign_key was equal to true beforehand)
2. FT::foreign_key_in child means that the foreign key is in the child object and is pointing to the parent object
This commit is contained in:
2021-03-10 16:20:11 +01:00
parent 133a45c84b
commit fcf1d28b18
17 changed files with 571 additions and 391 deletions

View File

@@ -41,7 +41,7 @@
#include "date/date.h"
#include "morm_types.h"
#include "modelenv.h"
#include "ft.h"
namespace morm
@@ -73,9 +73,9 @@ public:
template<typename FieldValue>
void field(const wchar_t * field_name, const FieldValue & field_value, bool insertable, bool updatable, bool is_primary_key, ModelEnv * model_env)
void field(const wchar_t * field_name, const FieldValue & field_value, FT field_type, ModelEnv * model_env)
{
if( out_stream && can_field_be_generated(insertable, updatable, is_primary_key) )
if( out_stream && can_field_be_generated(field_type) )
{
field_before();
@@ -91,7 +91,7 @@ public:
else
if( work_mode == MORM_WORK_MODE_MODEL_VALUES )
{
put_field_value_or_null(field_value, is_primary_key, model_env);
put_field_value_or_null(field_value, field_type, model_env);
}
else
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS_VALUES )
@@ -102,7 +102,7 @@ public:
{
put_field_name((*model_env->set_field_name_helper)[model_env->field_index], model_env);
put_name_value_separator();
put_field_value_or_null(field_value, is_primary_key, model_env);
put_field_value_or_null(field_value, field_type, model_env);
}
model_env->field_index += 1;
@@ -111,7 +111,7 @@ public:
{
put_field_name(field_name, model_env);
put_name_value_separator();
put_field_value_or_null(field_value, is_primary_key, model_env);
put_field_value_or_null(field_value, field_type, model_env);
}
}
@@ -122,9 +122,9 @@ public:
template<typename FieldValue>
void put_field_value_or_null(const FieldValue & field_value, bool is_primary_key, ModelEnv * model_env)
void put_field_value_or_null(const FieldValue & field_value, FT field_type, ModelEnv * model_env)
{
if( is_primary_key )
if( field_type.is_primary_key() )
{
if( model_env && model_env->has_primary_key_set )
put_field_value(field_value);
@@ -159,10 +159,9 @@ public:
template<typename ModelContainer>
void field_list(const wchar_t * field_name, ModelContainer & field_value, bool insertable, bool updatable, bool is_primary_key,
ModelConnector * model_connector, ModelEnv * model_env)
void field_list(const wchar_t * field_name, ModelContainer & field_value, FT field_type, ModelConnector * model_connector, ModelEnv * model_env)
{
if( out_stream && can_field_be_generated(insertable, updatable, is_primary_key) )
if( out_stream && can_field_be_generated(field_type) )
{
field_before();
@@ -183,9 +182,9 @@ public:
}
template<typename ModelClass>
void field_model(const wchar_t * field_name, ModelClass & field_model, bool insertable, bool updatable, bool is_primary_key, ModelEnv * model_env)
void field_model(const wchar_t * field_name, ModelClass & field_model, FT field_type, ModelEnv * model_env)
{
if( out_stream && can_field_be_generated(insertable, updatable, is_primary_key) )
if( out_stream && can_field_be_generated(field_type) )
{
field_before();
@@ -211,11 +210,10 @@ public:
}
template<typename FieldValue>
void field_to_stream(PT::TextStream & stream, const wchar_t * field_name, const FieldValue & field_value, bool insertable, bool updatable, bool is_primary_key,
ModelEnv * model_env)
void field_to_stream(PT::TextStream & stream, const wchar_t * field_name, const FieldValue & field_value, FT field_type, ModelEnv * model_env)
{
this->out_stream = &stream;
field(field_name, field_value, insertable, updatable, is_primary_key, model_env);
field(field_name, field_value, field_type, model_env);
this->out_stream = nullptr;
}
@@ -274,12 +272,10 @@ protected:
virtual void before_generate_from_model();
virtual void after_generate_from_model();
virtual bool can_field_be_generated(bool insertable, bool updatable, bool is_primary_key);
virtual bool can_field_be_generated(FT);
virtual void field_before();
virtual void field_after();
//void field(const wchar_t * field_name, Model & field, bool insertable = true, bool updatable = true);
virtual void put_field_name(const wchar_t * field_name, ModelEnv * model_env);
virtual void save_foreign_key(const wchar_t * field_name, ModelEnv * model_env);