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

@@ -14,10 +14,10 @@ main.o: ../../morm/src/queryresult.h ../../morm/src/flatconnector.h
main.o: ../../morm/src/dbexpression.h ../../morm/src/baseexpression.h
main.o: ../../morm/src/modelenv.h ../../morm/src/modeldata.h
main.o: ../../morm/src/cursorhelper.h ../../morm/src/finderhelper.h
main.o: ../../morm/src/fieldvaluehelper.h ../../morm/src/flatexpression.h
main.o: ../../morm/src/finder.h ../../pikotools/utf8/utf8.h
main.o: ../../morm/src/cursor.h ../../morm/src/jsonexpression.h
main.o: ../../morm/src/postgresqlexpression.h ../../morm/src/jsonconnector.h
main.o: ../../morm/src/postgresqlconnector.h
main.o: ../../morm/src/fieldvaluehelper.h ../../morm/src/ft.h
main.o: ../../morm/src/flatexpression.h ../../morm/src/finder.h
main.o: ../../pikotools/utf8/utf8.h ../../morm/src/cursor.h
main.o: ../../morm/src/jsonexpression.h ../../morm/src/postgresqlexpression.h
main.o: ../../morm/src/jsonconnector.h ../../morm/src/postgresqlconnector.h
main.o: ../../morm/src/postgresqlqueryresult.h person.h language.h
main.o: attachment.h type.h attachment2.h

View File

@@ -77,14 +77,14 @@ public:
void map_fields()
{
field(L"id", id, false, false, true);
field(L"id", id, FT::no_insertable | FT::no_updatable | FT::primary_key);
field(L"person_id", person_id);
field(L"name", name);
field(L"content", content);
field(L"attachment_id", L"types", types);
field(L"attachment_id", L"types", types, FT::foreign_key_in_child);
field(L"some_flags", some_flags);
field(L"created_date", created_date);
field(L"language_id", L"language", language);
field(L"language_id", L"language", language, FT::foreign_key);
}
void table_name(PT::TextStream & stream)

View File

@@ -77,14 +77,14 @@ public:
void map_fields()
{
field(L"id", id, false, false, true);
field(L"person_id", person_id);
field(L"id", id, FT::no_insertable | FT::no_updatable | FT::primary_key);
//field(L"person_id", person_id);
field(L"name", name);
field(L"content", content);
field(L"attachment_id", L"types", types);
field(L"attachment_id", L"types", types, FT::foreign_key_in_child);
field(L"some_flags", some_flags);
field(L"created_date", created_date);
field(L"language_id", L"language", language);
field(L"language_id", L"language", language, FT::foreign_key);
}
void table_name(PT::TextStream & stream)

View File

@@ -70,7 +70,7 @@ public:
void map_fields()
{
field(L"id", id, false, false, true);
field(L"id", id, FT::no_insertable | FT::no_updatable | FT::primary_key);
field(L"english_name", english_name);
field(L"local_name", local_name);
field(L"code_str", code_str);

View File

@@ -77,29 +77,23 @@ public:
void map_fields()
{
field(L"id", id, false, false, true);
field(L"language_id", L"language", language);
field(L"id", id, FT::no_insertable | FT::no_updatable | FT::primary_key);
field(L"language_id", L"language", language, FT::foreign_key);
field(L"first_name", first_name);
field(L"last_name", last_name);
field(L"email", email);
field(L"person_id", L"attachments", attachments);
field(L"person_id", L"attachment2", attachment2, true, true, false);
//field(L"id", id, f::no_insertable | f::no_updatable | f::primary_key);
//field(L"person_id", attachment, f::insertable | f::updatable | f::foreign_key);
//field(L"person_id", attachment, f::insertable, f::updatable, f::foreign_key);
field(L"person_id", L"attachments", attachments, FT::foreign_key_in_child);
field(L"person_id", L"attachment2", attachment2, FT::foreign_key_in_child | FT::no_insertable | FT::no_updatable);
}
void table_name(PT::TextStream & stream)
{
// schema.table_name or just table_name
stream << "public.person";
}
void after_select()
{
if( has_primary_key_set )

View File

@@ -75,7 +75,7 @@ void make()
morm::Finder<Person> finder(model_connector);
Person p = finder.select().where().eq(L"id", 191).get();
Person p = finder.select().where().eq(L"id", 207).get();
p.to_text(str, true, true);

View File

@@ -65,7 +65,7 @@ public:
void map_fields()
{
field(L"id", id, false, false, true);
field(L"id", id, FT::no_insertable | FT::no_updatable | FT::primary_key);
field(L"attachment_id", attachment_id);
field(L"name", name);
}