@@ -5198,8 +5198,6 @@ namespace sqlite_orm {
51985198}
51995199
52005200// #include "ast/cross_join.h"
5201- // #include "../functional/config.h"
5202-
52035201// #include "../functional/cxx_type_traits_polyfill.h"
52045202
52055203namespace sqlite_orm {
@@ -5213,9 +5211,6 @@ namespace sqlite_orm {
52135211 struct cross_join_t {
52145212 using type = T;
52155213 };
5216-
5217- template<class T>
5218- using is_cross_join = polyfill::is_specialization_of<T, cross_join_t>;
52195214 }
52205215}
52215216
@@ -5234,7 +5229,6 @@ SQLITE_ORM_EXPORT namespace sqlite_orm {
52345229namespace sqlite_orm {
52355230
52365231 namespace internal {
5237-
52385232 /**
52395233 * Collated something
52405234 */
@@ -5933,6 +5927,13 @@ namespace sqlite_orm {
59335927
59345928 template<class T>
59355929 using is_constrained_join = polyfill::is_detected<on_type_t, T>;
5930+
5931+ template<class T>
5932+ using is_any_join = mpl::invoke_t<mpl::disjunction<check_if<is_constrained_join>,
5933+ check_if_is_template<cross_join_t>,
5934+ check_if_is_template<natural_join_t>>,
5935+ T>;
5936+
59365937 }
59375938}
59385939
@@ -22366,21 +22367,23 @@ namespace sqlite_orm {
2236622367 using conditions_tuple = typename statement_type::conditions_type;
2236722368 constexpr bool hasExplicitFrom = tuple_has<conditions_tuple, is_from>::value;
2236822369 if constexpr (!hasExplicitFrom) {
22369- using joins_index_sequence = filter_tuple_sequence_t<conditions_tuple, is_constrained_join>;
22370- using cross_join_index_sequence = filter_tuple_sequence_t<conditions_tuple, is_cross_join>;
22370+ using joins_index_sequence = filter_tuple_sequence_t<conditions_tuple, is_any_join>;
2237122371
2237222372 auto tableNames = collect_table_names(sel, context);
22373- auto joinLambda = [&tableNames, &context](auto& join) {
22374- using original_join_type = typename std::remove_reference_t<decltype(join)>::type;
22375- using cross_join_type = mapped_type_proxy_t<original_join_type>;
22376- std::pair<const std::string&, std::string> tableNameWithAlias{
22377- lookup_table_name<cross_join_type>(context.db_objects),
22378- alias_extractor<original_join_type>::as_alias()};
22379- tableNames.erase(tableNameWithAlias);
22380- };
2238122373 // deduplicate table names of constrained join statements
22382- iterate_tuple(sel.conditions, joins_index_sequence{}, joinLambda);
22383- iterate_tuple(sel.conditions, cross_join_index_sequence{}, joinLambda);
22374+ iterate_tuple(sel.conditions, joins_index_sequence{}, [&tableNames, &context](auto& join) {
22375+ using original_join_type = typename std::remove_reference_t<decltype(join)>::type;
22376+ using join_type = mapped_type_proxy_t<original_join_type>;
22377+
22378+ const auto& tableName = lookup_table_name<join_type>(context.db_objects);
22379+ auto it = std::find_if(tableNames.begin(), tableNames.end(), [&tableName](const auto& pair) {
22380+ return pair.first == tableName;
22381+ });
22382+ if (it == tableNames.end()) {
22383+ return;
22384+ }
22385+ tableNames.erase(it);
22386+ });
2238422387
2238522388 if (!tableNames.empty() && !is_compound_operator<T>::value) {
2238622389 ss << " FROM " << streaming_identifiers(tableNames);
@@ -22715,17 +22718,19 @@ namespace sqlite_orm {
2271522718 using statement_type = Join;
2271622719
2271722720 template<class Ctx>
22718- SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& join,
22721+ SQLITE_ORM_STATIC_CALLOP std::string operator()(const statement_type& /* join*/ ,
2271922722 const Ctx& context) SQLITE_ORM_OR_CONST_CALLOP {
2272022723 std::stringstream ss;
22721- if constexpr (polyfill::is_specialization_of<Join , cross_join_t>::value) {
22724+ if constexpr (polyfill::is_specialization_of<statement_type , cross_join_t>::value) {
2272222725 ss << "CROSS JOIN";
22723- } else if constexpr (polyfill::is_specialization_of<Join , natural_join_t>::value) {
22726+ } else if constexpr (polyfill::is_specialization_of<statement_type , natural_join_t>::value) {
2272422727 ss << "NATURAL JOIN";
2272522728 } else {
2272622729 static_assert(polyfill::always_false_v<statement_type>);
2272722730 }
22728- ss << " " << streaming_identifier(lookup_table_name<type_t<Join>>(context.db_objects));
22731+ ss << " "
22732+ << streaming_identifier(
22733+ lookup_table_name<mapped_type_proxy_t<type_t<statement_type>>>(context.db_objects));
2272922734 return ss.str();
2273022735 }
2273122736 };
0 commit comments