Added flag has_primary_key_set to Model

Now we know whether the primary key is defined or not
and we do not allow to make update/remove if the key is not defined.

And when doing insert/update we can put NULL if child models don't have
the primary key set (fields with has_foreign_key set to true).

Now in after_select() we should also set has_primary_key_set flag
or just call get_last_sequence_for_primary_key instead of get_last_sequence.

fixed: added prefix +00 when serializing PT::Date to PostgreSQL (time zone)
(for a column with a time zone there was a wrong value saved)
This commit is contained in:
2021-03-09 18:10:34 +01:00
parent ff551a64b8
commit 133a45c84b
18 changed files with 474 additions and 110 deletions

View File

@@ -91,7 +91,7 @@ public:
else
if( work_mode == MORM_WORK_MODE_MODEL_VALUES )
{
put_field_value(field_value);
put_field_value_or_null(field_value, is_primary_key, 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(field_value);
put_field_value_or_null(field_value, is_primary_key, 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(field_value);
put_field_value_or_null(field_value, is_primary_key, model_env);
}
}
@@ -121,6 +121,22 @@ public:
}
template<typename FieldValue>
void put_field_value_or_null(const FieldValue & field_value, bool is_primary_key, ModelEnv * model_env)
{
if( is_primary_key )
{
if( model_env && model_env->has_primary_key_set )
put_field_value(field_value);
else
put_null_value();
}
else
{
put_field_value(field_value);
}
}
template<typename FieldValue>
void field_in(PT::TextStream & stream, const wchar_t * field_name, const std::set<FieldValue> & container, ModelEnv * model_env)
{
@@ -282,6 +298,12 @@ protected:
}
virtual void put_null_value()
{
(*out_stream) << "null";
}
virtual void before_field_value_list()
{
}