Class: DbdocEngine::DbDesignDynamicColumnQueries
- Inherits:
-
Object
- Object
- DbdocEngine::DbDesignDynamicColumnQueries
- Defined in:
- app/queries/dbdoc_engine/db_design_dynamic_column_queries.rb
Class Method Summary collapse
- .all_foreign_keys_with_tables ⇒ Object
-
.column_referenced_as_foreign_key?(table_name, column_name) ⇒ Boolean
Checks if a column is referenced as a foreign key in any (non-deleted) table.
-
.count_columns_in_table(table) ⇒ Object
Counts the number of columns in the given table.
-
.model ⇒ Object
Returns the DbDesignDynamicColumn model (centralized reference).
Class Method Details
.all_foreign_keys_with_tables ⇒ Object
31 32 33 34 |
# File 'app/queries/dbdoc_engine/db_design_dynamic_column_queries.rb', line 31 def all_foreign_keys_with_tables model.joins(:db_design_dynamic_table) .where(is_foreign_key: true, db_design_dynamic_tables: { deleted_at: nil }) end |
.column_referenced_as_foreign_key?(table_name, column_name) ⇒ Boolean
Checks if a column is referenced as a foreign key in any (non-deleted) table
20 21 22 23 24 25 26 27 28 29 |
# File 'app/queries/dbdoc_engine/db_design_dynamic_column_queries.rb', line 20 def column_referenced_as_foreign_key?(table_name, column_name) # Joins with parent table, filters by foreign key reference and non-deleted tables model.joins(:db_design_dynamic_table) .where( foreign_table_name: table_name, foreign_column_name: column_name, db_design_dynamic_tables: { deleted_at: nil } ) .exists? end |
.count_columns_in_table(table) ⇒ Object
Counts the number of columns in the given table. Uses .size to leverage eager-loaded associations when available, avoiding N+1 COUNT queries in loops.
15 16 17 |
# File 'app/queries/dbdoc_engine/db_design_dynamic_column_queries.rb', line 15 def count_columns_in_table(table) table.db_design_dynamic_columns.size end |
.model ⇒ Object
Returns the DbDesignDynamicColumn model (centralized reference)
7 8 9 |
# File 'app/queries/dbdoc_engine/db_design_dynamic_column_queries.rb', line 7 def self.model DbDesignDynamicColumn end |