added support for UPDATE, INSERT and REMOVE for lists childs
(need some testing) git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1214 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
126
src/model.h
126
src/model.h
@@ -607,6 +607,11 @@ protected:
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IMPROVE ME there can be more rows in the result set when there are more items on the left hand side of the join
|
||||
* this is only in a case when has_foreign_key is false, may it can be ignored? we can use unique index in such a case
|
||||
*
|
||||
*/
|
||||
void field_model_left_join(const wchar_t * db_field_name, const wchar_t * flat_field_name, Model & field_model, bool insertable, bool updatable, bool has_foreign_key, DbExpression * db_expression)
|
||||
{
|
||||
if( model_env && field_model.model_env && model_env->finder_helper )
|
||||
@@ -960,61 +965,94 @@ protected:
|
||||
}
|
||||
|
||||
|
||||
template<typename ModelContainer, typename ModelContainerType>
|
||||
void field_list_iterate_through_childs(const wchar_t * db_field_name, ModelContainer & field_container, ModelContainerType * model_container_type)
|
||||
{
|
||||
if( !is_empty_field(db_field_name) )
|
||||
{
|
||||
for(ModelContainerType & child_model : field_container)
|
||||
{
|
||||
ModelEnv model_env_local;
|
||||
model_env_local.copy_global_objects(*model_env);
|
||||
|
||||
child_model.model_env = &model_env_local;
|
||||
child_model.set_connector(model_connector);
|
||||
|
||||
if( model_env->model_work_submode == MORM_MODEL_WORK_SUBMODE_INSERT )
|
||||
{
|
||||
child_model.insert_tree(true);
|
||||
}
|
||||
|
||||
if( model_env->model_work_submode == MORM_MODEL_WORK_SUBMODE_UPDATE )
|
||||
{
|
||||
child_model.update_tree(true);
|
||||
}
|
||||
|
||||
if( model_env->model_work_submode == MORM_MODEL_WORK_SUBMODE_REMOVE )
|
||||
{
|
||||
child_model.remove_tree(true);
|
||||
}
|
||||
|
||||
if( model_env->model_work_submode == MORM_MODEL_WORK_SUBMODE_SAVE )
|
||||
{
|
||||
child_model.save_tree(true);
|
||||
}
|
||||
|
||||
child_model.model_env = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<typename ModelContainer>
|
||||
void field_list_generate_flat_string(const wchar_t * flat_field_name, ModelContainer & field_container, bool insertable, bool updatable)
|
||||
{
|
||||
FlatConnector * flat_connector = model_connector->get_flat_connector();
|
||||
|
||||
if( flat_connector )
|
||||
{
|
||||
FlatExpression * flat_expression = flat_connector->get_expression();
|
||||
|
||||
if( flat_expression && !is_empty_field(flat_field_name) )
|
||||
{
|
||||
// insertable and updatable will be ignored there
|
||||
flat_expression->field_list(flat_field_name, field_container, insertable, updatable, false, model_connector, model_env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename ModelContainer>
|
||||
void field_list_clearing_values(ModelContainer & field_container)
|
||||
{
|
||||
Clearer * clearer = model_connector->get_clearer();
|
||||
|
||||
if( clearer )
|
||||
{
|
||||
clearer->clear_container(field_container);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename ModelContainer, typename ModelContainerType>
|
||||
void field_list(const wchar_t * db_field_name, const wchar_t * flat_field_name, ModelContainer & field_container, ModelContainerType * model_container_type, bool insertable, bool updatable)
|
||||
{
|
||||
if( model_connector && model_env )
|
||||
{
|
||||
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_ITERATE_THROUGH_CHILDS_WITHOUT_FOREIGN_KEY )
|
||||
{
|
||||
field_list_iterate_through_childs(db_field_name, field_container, model_container_type);
|
||||
}
|
||||
|
||||
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GENERATING_FLAT_STRING )
|
||||
{
|
||||
FlatConnector * flat_connector = model_connector->get_flat_connector();
|
||||
|
||||
if( flat_connector )
|
||||
{
|
||||
FlatExpression * flat_expression = flat_connector->get_expression();
|
||||
|
||||
if( flat_expression && !is_empty_field(flat_field_name) )
|
||||
{
|
||||
// IMPROVE ME
|
||||
// what about model_data and save_mode?
|
||||
// may it should be placed inside some structure?
|
||||
flat_expression->field_list(flat_field_name, field_container, insertable, updatable, false, model_connector, model_env);
|
||||
}
|
||||
}
|
||||
field_list_generate_flat_string(flat_field_name, field_container, insertable, updatable);
|
||||
}
|
||||
|
||||
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GENERATING_DB_SQL )
|
||||
{
|
||||
DbConnector * db_connector = model_connector->get_db_connector();
|
||||
|
||||
if( db_connector )
|
||||
{
|
||||
DbExpression * db_expression = db_connector->get_expression();
|
||||
|
||||
if( db_expression && !is_empty_field(db_field_name) &&
|
||||
db_expression->get_output_type() != MORM_OUTPUT_TYPE_JOIN_TABLES &&
|
||||
db_expression->get_output_type() != MORM_OUTPUT_TYPE_DB_INSERT &&
|
||||
db_expression->get_output_type() != MORM_OUTPUT_TYPE_DB_UPDATE )
|
||||
{
|
||||
// another select will be used (from another Finder)
|
||||
// we need only columns name
|
||||
// but columns are defined in the other model
|
||||
|
||||
// FIX ME
|
||||
// UPDATE, INSERT, REMOVE for lists
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_CLEARING_VALUE )
|
||||
{
|
||||
Clearer * clearer = model_connector->get_clearer();
|
||||
|
||||
if( clearer )
|
||||
{
|
||||
clearer->clear_container(field_container);
|
||||
}
|
||||
field_list_clearing_values(field_container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user