diff --git a/src/finder.h b/src/finder.h index cb64c2c..41aafed 100644 --- a/src/finder.h +++ b/src/finder.h @@ -204,16 +204,24 @@ public: return *this; } - Finder & select(Model::ModelData * model_data) + Finder & select(Model::ModelData * model_data, bool call_prepare = true) { - prepare_to_select(); + if( call_prepare ) + { + prepare_to_select(); + } + this->model_data = model_data; return select(false); } - Finder & select(Model::ModelData & model_data) + Finder & select(Model::ModelData & model_data, bool call_prepare = true) { - prepare_to_select(); + if( call_prepare ) + { + prepare_to_select(); + } + this->model_data = &model_data; return select(false); } @@ -417,9 +425,17 @@ public: if( res ) { - result.set_save_mode(Model::DO_UPDATE_ON_SAVE); // IMPROVE ME check if there is a primary key - model_connector->map_values_from_query(result); - result.after_select(); + if( db_connector->last_select_size() == 1 ) + { + result.set_save_mode(Model::DO_UPDATE_ON_SAVE); // IMPROVE ME check if there is a primary key + model_connector->map_values_from_query(result); + result.after_select(); + } + else + { + res = false; + // log some error or throw an exception if there are more items than one? + } } else { @@ -428,6 +444,7 @@ public: } catch(...) { + res = false; // throw something? // if yes then make sure to call db_connector->clear_last_query_result(); } @@ -497,6 +514,7 @@ public: } catch(...) { + res = false; // throw or something? // make sure to call db_connector->clear_last_query_result() }