From 9e959397af3ce569db8e155fb2cdf295c57221c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Bugajewski?= Date: Wed, 10 Jun 2020 17:55:03 +0200 Subject: [PATCH] Fixed Model Generation for PostgreSQL Primary Keys (#471) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As per definition Drogon should return the last ID after an insert when “a table contains an auto-increasing primary key”, but the current detection mechanism isn’t enough to catch all cases. PostgreSQL has the concept of generated identity columns that act as primary key columns, but this information is held in the "is_identity" column that wasn’t checked before. This commit fixes #410, and also detects generated identity columns as auto incrementing columns, so that the model generation correctly appends " returning " statements. --- drogon_ctl/create_model.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drogon_ctl/create_model.cc b/drogon_ctl/create_model.cc index 97e9f2c4..231a6f18 100644 --- a/drogon_ctl/create_model.cc +++ b/drogon_ctl/create_model.cc @@ -194,6 +194,10 @@ void create_model::createModelClassFromPG( info.isAutoVal_ = true; } } + auto isIdentity = row["is_identity"].as(); + if (isIdentity == "YES") { + info.isAutoVal_ = true; + } cols.push_back(std::move(info)); } } >>