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:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019, Tomasz Sowa
|
||||
* Copyright (c) 2019-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -38,7 +38,7 @@
|
||||
#include <string>
|
||||
#include "morm.h"
|
||||
#include "type.h"
|
||||
|
||||
#include "language.h"
|
||||
|
||||
|
||||
namespace morm
|
||||
@@ -54,7 +54,7 @@ CREATE TABLE public.attachment (
|
||||
content text,
|
||||
some_flags bool,
|
||||
created_date timestamp with time zone,
|
||||
bigint language_id,
|
||||
language_id bigint,
|
||||
|
||||
primary key(id)
|
||||
);
|
||||
@@ -82,7 +82,6 @@ public:
|
||||
field(L"name", name);
|
||||
field(L"content", content);
|
||||
field(L"attachment_id", L"types", types);
|
||||
//field(L"types", types);
|
||||
field(L"some_flags", some_flags);
|
||||
field(L"created_date", created_date);
|
||||
field(L"language_id", L"language", language);
|
||||
@@ -94,9 +93,18 @@ public:
|
||||
stream << "public.attachment";
|
||||
}
|
||||
|
||||
void after_select()
|
||||
{
|
||||
if( has_primary_key_set )
|
||||
{
|
||||
morm::Finder<Type> finder(model_connector);
|
||||
types = finder.select().where().eq(L"attachment_id", id).get_vector();
|
||||
}
|
||||
}
|
||||
|
||||
void after_insert()
|
||||
{
|
||||
get_last_sequence(L"public.attachment_id_seq", id);
|
||||
get_last_sequence_for_primary_key(L"public.attachment_id_seq", id);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user