sequel 5.29.0 → 5.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +70 -1922
- data/README.rdoc +1 -1
- data/doc/advanced_associations.rdoc +4 -4
- data/doc/association_basics.rdoc +3 -3
- data/doc/code_order.rdoc +12 -2
- data/doc/model_dataset_method_design.rdoc +1 -1
- data/doc/postgresql.rdoc +71 -0
- data/doc/release_notes/5.30.0.txt +20 -0
- data/doc/release_notes/5.31.0.txt +148 -0
- data/doc/release_notes/5.32.0.txt +46 -0
- data/doc/release_notes/5.33.0.txt +24 -0
- data/doc/release_notes/5.34.0.txt +40 -0
- data/doc/testing.rdoc +1 -1
- data/lib/sequel/adapters/shared/access.rb +6 -6
- data/lib/sequel/adapters/shared/mssql.rb +5 -5
- data/lib/sequel/adapters/shared/mysql.rb +9 -9
- data/lib/sequel/adapters/shared/oracle.rb +16 -16
- data/lib/sequel/adapters/shared/postgres.rb +169 -14
- data/lib/sequel/adapters/shared/sqlanywhere.rb +9 -9
- data/lib/sequel/adapters/shared/sqlite.rb +32 -5
- data/lib/sequel/connection_pool/sharded_single.rb +4 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +12 -12
- data/lib/sequel/connection_pool/single.rb +1 -1
- data/lib/sequel/connection_pool/threaded.rb +2 -2
- data/lib/sequel/core.rb +318 -314
- data/lib/sequel/database/connecting.rb +1 -1
- data/lib/sequel/database/misc.rb +16 -10
- data/lib/sequel/database/query.rb +3 -1
- data/lib/sequel/database/schema_generator.rb +0 -1
- data/lib/sequel/database/schema_methods.rb +15 -16
- data/lib/sequel/database/transactions.rb +12 -13
- data/lib/sequel/dataset/placeholder_literalizer.rb +3 -7
- data/lib/sequel/dataset/query.rb +4 -3
- data/lib/sequel/deprecated.rb +2 -0
- data/lib/sequel/exceptions.rb +2 -0
- data/lib/sequel/extensions/connection_expiration.rb +2 -2
- data/lib/sequel/extensions/connection_validator.rb +2 -2
- data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
- data/lib/sequel/extensions/index_caching.rb +9 -7
- data/lib/sequel/extensions/integer64.rb +2 -0
- data/lib/sequel/extensions/migration.rb +1 -1
- data/lib/sequel/extensions/pg_enum.rb +5 -2
- data/lib/sequel/extensions/pg_hstore.rb +6 -0
- data/lib/sequel/extensions/pg_inet.rb +13 -5
- data/lib/sequel/extensions/pg_interval.rb +2 -0
- data/lib/sequel/extensions/pg_range.rb +2 -0
- data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
- data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
- data/lib/sequel/extensions/schema_dumper.rb +10 -4
- data/lib/sequel/extensions/server_block.rb +3 -3
- data/lib/sequel/model.rb +2 -0
- data/lib/sequel/model/associations.rb +30 -18
- data/lib/sequel/model/base.rb +64 -55
- data/lib/sequel/model/plugins.rb +3 -3
- data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
- data/lib/sequel/plugins/association_multi_add_remove.rb +2 -0
- data/lib/sequel/plugins/association_pks.rb +57 -16
- data/lib/sequel/plugins/association_proxies.rb +2 -0
- data/lib/sequel/plugins/boolean_subsets.rb +4 -1
- data/lib/sequel/plugins/class_table_inheritance.rb +26 -26
- data/lib/sequel/plugins/dirty.rb +13 -13
- data/lib/sequel/plugins/forbid_lazy_load.rb +214 -0
- data/lib/sequel/plugins/json_serializer.rb +3 -7
- data/lib/sequel/plugins/rcte_tree.rb +2 -2
- data/lib/sequel/plugins/single_table_inheritance.rb +15 -15
- data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
- data/lib/sequel/plugins/subclasses.rb +2 -0
- data/lib/sequel/timezones.rb +6 -4
- data/lib/sequel/version.rb +1 -1
- metadata +17 -368
- data/Rakefile +0 -151
- data/doc/release_notes/4.0.0.txt +0 -262
- data/doc/release_notes/4.1.0.txt +0 -85
- data/doc/release_notes/4.10.0.txt +0 -226
- data/doc/release_notes/4.11.0.txt +0 -147
- data/doc/release_notes/4.12.0.txt +0 -105
- data/doc/release_notes/4.13.0.txt +0 -169
- data/doc/release_notes/4.14.0.txt +0 -68
- data/doc/release_notes/4.15.0.txt +0 -56
- data/doc/release_notes/4.16.0.txt +0 -36
- data/doc/release_notes/4.17.0.txt +0 -38
- data/doc/release_notes/4.18.0.txt +0 -36
- data/doc/release_notes/4.19.0.txt +0 -45
- data/doc/release_notes/4.2.0.txt +0 -129
- data/doc/release_notes/4.20.0.txt +0 -79
- data/doc/release_notes/4.21.0.txt +0 -94
- data/doc/release_notes/4.22.0.txt +0 -72
- data/doc/release_notes/4.23.0.txt +0 -65
- data/doc/release_notes/4.24.0.txt +0 -99
- data/doc/release_notes/4.25.0.txt +0 -181
- data/doc/release_notes/4.26.0.txt +0 -44
- data/doc/release_notes/4.27.0.txt +0 -78
- data/doc/release_notes/4.28.0.txt +0 -57
- data/doc/release_notes/4.29.0.txt +0 -41
- data/doc/release_notes/4.3.0.txt +0 -40
- data/doc/release_notes/4.30.0.txt +0 -37
- data/doc/release_notes/4.31.0.txt +0 -57
- data/doc/release_notes/4.32.0.txt +0 -132
- data/doc/release_notes/4.33.0.txt +0 -88
- data/doc/release_notes/4.34.0.txt +0 -86
- data/doc/release_notes/4.35.0.txt +0 -130
- data/doc/release_notes/4.36.0.txt +0 -116
- data/doc/release_notes/4.37.0.txt +0 -50
- data/doc/release_notes/4.38.0.txt +0 -67
- data/doc/release_notes/4.39.0.txt +0 -127
- data/doc/release_notes/4.4.0.txt +0 -92
- data/doc/release_notes/4.40.0.txt +0 -179
- data/doc/release_notes/4.41.0.txt +0 -77
- data/doc/release_notes/4.42.0.txt +0 -221
- data/doc/release_notes/4.43.0.txt +0 -87
- data/doc/release_notes/4.44.0.txt +0 -125
- data/doc/release_notes/4.45.0.txt +0 -370
- data/doc/release_notes/4.46.0.txt +0 -404
- data/doc/release_notes/4.47.0.txt +0 -56
- data/doc/release_notes/4.48.0.txt +0 -293
- data/doc/release_notes/4.49.0.txt +0 -222
- data/doc/release_notes/4.5.0.txt +0 -34
- data/doc/release_notes/4.6.0.txt +0 -30
- data/doc/release_notes/4.7.0.txt +0 -103
- data/doc/release_notes/4.8.0.txt +0 -175
- data/doc/release_notes/4.9.0.txt +0 -190
- data/spec/adapter_spec.rb +0 -4
- data/spec/adapters/db2_spec.rb +0 -170
- data/spec/adapters/mssql_spec.rb +0 -828
- data/spec/adapters/mysql_spec.rb +0 -1060
- data/spec/adapters/oracle_spec.rb +0 -371
- data/spec/adapters/postgres_spec.rb +0 -4476
- data/spec/adapters/spec_helper.rb +0 -44
- data/spec/adapters/sqlanywhere_spec.rb +0 -97
- data/spec/adapters/sqlite_spec.rb +0 -652
- data/spec/bin_spec.rb +0 -278
- data/spec/core/connection_pool_spec.rb +0 -1250
- data/spec/core/database_spec.rb +0 -2915
- data/spec/core/dataset_spec.rb +0 -5544
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1498
- data/spec/core/mock_adapter_spec.rb +0 -722
- data/spec/core/object_graph_spec.rb +0 -336
- data/spec/core/placeholder_literalizer_spec.rb +0 -166
- data/spec/core/schema_generator_spec.rb +0 -214
- data/spec/core/schema_spec.rb +0 -1844
- data/spec/core/spec_helper.rb +0 -24
- data/spec/core/version_spec.rb +0 -14
- data/spec/core_extensions_spec.rb +0 -763
- data/spec/core_model_spec.rb +0 -2
- data/spec/core_spec.rb +0 -1
- data/spec/deprecation_helper.rb +0 -30
- data/spec/extensions/accessed_columns_spec.rb +0 -51
- data/spec/extensions/active_model_spec.rb +0 -99
- data/spec/extensions/after_initialize_spec.rb +0 -28
- data/spec/extensions/any_not_empty_spec.rb +0 -23
- data/spec/extensions/arbitrary_servers_spec.rb +0 -109
- data/spec/extensions/association_dependencies_spec.rb +0 -125
- data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
- data/spec/extensions/association_pks_spec.rb +0 -423
- data/spec/extensions/association_proxies_spec.rb +0 -100
- data/spec/extensions/auto_literal_strings_spec.rb +0 -205
- data/spec/extensions/auto_validations_spec.rb +0 -229
- data/spec/extensions/blacklist_security_spec.rb +0 -95
- data/spec/extensions/blank_spec.rb +0 -69
- data/spec/extensions/boolean_readers_spec.rb +0 -93
- data/spec/extensions/boolean_subsets_spec.rb +0 -47
- data/spec/extensions/caching_spec.rb +0 -273
- data/spec/extensions/caller_logging_spec.rb +0 -52
- data/spec/extensions/class_table_inheritance_spec.rb +0 -750
- data/spec/extensions/column_conflicts_spec.rb +0 -75
- data/spec/extensions/column_select_spec.rb +0 -129
- data/spec/extensions/columns_introspection_spec.rb +0 -90
- data/spec/extensions/columns_updated_spec.rb +0 -35
- data/spec/extensions/composition_spec.rb +0 -248
- data/spec/extensions/connection_expiration_spec.rb +0 -151
- data/spec/extensions/connection_validator_spec.rb +0 -144
- data/spec/extensions/constant_sql_override_spec.rb +0 -24
- data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
- data/spec/extensions/constraint_validations_spec.rb +0 -439
- data/spec/extensions/core_refinements_spec.rb +0 -528
- data/spec/extensions/csv_serializer_spec.rb +0 -183
- data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
- data/spec/extensions/dataset_associations_spec.rb +0 -365
- data/spec/extensions/dataset_source_alias_spec.rb +0 -51
- data/spec/extensions/date_arithmetic_spec.rb +0 -181
- data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
- data/spec/extensions/def_dataset_method_spec.rb +0 -100
- data/spec/extensions/defaults_setter_spec.rb +0 -150
- data/spec/extensions/delay_add_association_spec.rb +0 -73
- data/spec/extensions/dirty_spec.rb +0 -222
- data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
- data/spec/extensions/eager_each_spec.rb +0 -62
- data/spec/extensions/eager_graph_eager_spec.rb +0 -100
- data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
- data/spec/extensions/empty_failure_backtraces_spec.rb +0 -60
- data/spec/extensions/error_splitter_spec.rb +0 -18
- data/spec/extensions/error_sql_spec.rb +0 -20
- data/spec/extensions/escaped_like_spec.rb +0 -40
- data/spec/extensions/eval_inspect_spec.rb +0 -81
- data/spec/extensions/exclude_or_null_spec.rb +0 -15
- data/spec/extensions/finder_spec.rb +0 -260
- data/spec/extensions/force_encoding_spec.rb +0 -126
- data/spec/extensions/freeze_datasets_spec.rb +0 -31
- data/spec/extensions/graph_each_spec.rb +0 -113
- data/spec/extensions/hook_class_methods_spec.rb +0 -402
- data/spec/extensions/identifier_mangling_spec.rb +0 -201
- data/spec/extensions/implicit_subquery_spec.rb +0 -58
- data/spec/extensions/index_caching_spec.rb +0 -66
- data/spec/extensions/inflector_spec.rb +0 -183
- data/spec/extensions/input_transformer_spec.rb +0 -69
- data/spec/extensions/insert_conflict_spec.rb +0 -103
- data/spec/extensions/insert_returning_select_spec.rb +0 -72
- data/spec/extensions/instance_filters_spec.rb +0 -79
- data/spec/extensions/instance_hooks_spec.rb +0 -246
- data/spec/extensions/integer64_spec.rb +0 -22
- data/spec/extensions/inverted_subsets_spec.rb +0 -33
- data/spec/extensions/json_serializer_spec.rb +0 -346
- data/spec/extensions/lazy_attributes_spec.rb +0 -183
- data/spec/extensions/list_spec.rb +0 -291
- data/spec/extensions/looser_typecasting_spec.rb +0 -43
- data/spec/extensions/many_through_many_spec.rb +0 -2177
- data/spec/extensions/migration_spec.rb +0 -864
- data/spec/extensions/modification_detection_spec.rb +0 -93
- data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
- data/spec/extensions/named_timezones_spec.rb +0 -218
- data/spec/extensions/nested_attributes_spec.rb +0 -815
- data/spec/extensions/null_dataset_spec.rb +0 -85
- data/spec/extensions/optimistic_locking_spec.rb +0 -127
- data/spec/extensions/pagination_spec.rb +0 -116
- data/spec/extensions/pg_array_associations_spec.rb +0 -802
- data/spec/extensions/pg_array_ops_spec.rb +0 -144
- data/spec/extensions/pg_array_spec.rb +0 -398
- data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -209
- data/spec/extensions/pg_enum_spec.rb +0 -118
- data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
- data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
- data/spec/extensions/pg_hstore_spec.rb +0 -219
- data/spec/extensions/pg_inet_ops_spec.rb +0 -102
- data/spec/extensions/pg_inet_spec.rb +0 -72
- data/spec/extensions/pg_interval_spec.rb +0 -103
- data/spec/extensions/pg_json_ops_spec.rb +0 -356
- data/spec/extensions/pg_json_spec.rb +0 -451
- data/spec/extensions/pg_loose_count_spec.rb +0 -23
- data/spec/extensions/pg_range_ops_spec.rb +0 -60
- data/spec/extensions/pg_range_spec.rb +0 -600
- data/spec/extensions/pg_row_ops_spec.rb +0 -61
- data/spec/extensions/pg_row_plugin_spec.rb +0 -60
- data/spec/extensions/pg_row_spec.rb +0 -363
- data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
- data/spec/extensions/pg_timestamptz_spec.rb +0 -17
- data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
- data/spec/extensions/prepared_statements_spec.rb +0 -177
- data/spec/extensions/pretty_table_spec.rb +0 -123
- data/spec/extensions/query_spec.rb +0 -94
- data/spec/extensions/rcte_tree_spec.rb +0 -387
- data/spec/extensions/round_timestamps_spec.rb +0 -39
- data/spec/extensions/s_spec.rb +0 -60
- data/spec/extensions/schema_caching_spec.rb +0 -64
- data/spec/extensions/schema_dumper_spec.rb +0 -870
- data/spec/extensions/select_remove_spec.rb +0 -38
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
- data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
- data/spec/extensions/serialization_spec.rb +0 -365
- data/spec/extensions/server_block_spec.rb +0 -135
- data/spec/extensions/server_logging_spec.rb +0 -45
- data/spec/extensions/sharding_spec.rb +0 -197
- data/spec/extensions/shared_caching_spec.rb +0 -151
- data/spec/extensions/single_table_inheritance_spec.rb +0 -347
- data/spec/extensions/singular_table_names_spec.rb +0 -22
- data/spec/extensions/skip_create_refresh_spec.rb +0 -18
- data/spec/extensions/spec_helper.rb +0 -70
- data/spec/extensions/split_array_nil_spec.rb +0 -24
- data/spec/extensions/split_values_spec.rb +0 -57
- data/spec/extensions/sql_comments_spec.rb +0 -33
- data/spec/extensions/sql_expr_spec.rb +0 -59
- data/spec/extensions/static_cache_cache_spec.rb +0 -35
- data/spec/extensions/static_cache_spec.rb +0 -471
- data/spec/extensions/string_agg_spec.rb +0 -90
- data/spec/extensions/string_date_time_spec.rb +0 -95
- data/spec/extensions/string_stripper_spec.rb +0 -68
- data/spec/extensions/subclasses_spec.rb +0 -79
- data/spec/extensions/subset_conditions_spec.rb +0 -38
- data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
- data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
- data/spec/extensions/synchronize_sql_spec.rb +0 -124
- data/spec/extensions/table_select_spec.rb +0 -83
- data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
- data/spec/extensions/thread_local_timezones_spec.rb +0 -67
- data/spec/extensions/throw_failures_spec.rb +0 -74
- data/spec/extensions/timestamps_spec.rb +0 -209
- data/spec/extensions/to_dot_spec.rb +0 -153
- data/spec/extensions/touch_spec.rb +0 -226
- data/spec/extensions/tree_spec.rb +0 -334
- data/spec/extensions/typecast_on_load_spec.rb +0 -86
- data/spec/extensions/unlimited_update_spec.rb +0 -21
- data/spec/extensions/update_or_create_spec.rb +0 -83
- data/spec/extensions/update_primary_key_spec.rb +0 -105
- data/spec/extensions/update_refresh_spec.rb +0 -59
- data/spec/extensions/uuid_spec.rb +0 -101
- data/spec/extensions/validate_associated_spec.rb +0 -52
- data/spec/extensions/validation_class_methods_spec.rb +0 -1040
- data/spec/extensions/validation_contexts_spec.rb +0 -31
- data/spec/extensions/validation_helpers_spec.rb +0 -525
- data/spec/extensions/whitelist_security_spec.rb +0 -157
- data/spec/extensions/xml_serializer_spec.rb +0 -213
- data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
- data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
- data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
- data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
- data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/double_migration/001_create_sessions.rb +0 -9
- data/spec/files/double_migration/002_create_nodes.rb +0 -19
- data/spec/files/double_migration/003_3_create_users.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
- data/spec/files/empty_migration/001_create_sessions.rb +0 -9
- data/spec/files/empty_migration/002_create_nodes.rb +0 -0
- data/spec/files/empty_migration/003_3_create_users.rb +0 -4
- data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
- data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
- data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
- data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
- data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/reversible_migrations/001_reversible.rb +0 -5
- data/spec/files/reversible_migrations/002_reversible.rb +0 -5
- data/spec/files/reversible_migrations/003_reversible.rb +0 -5
- data/spec/files/reversible_migrations/004_reversible.rb +0 -5
- data/spec/files/reversible_migrations/005_reversible.rb +0 -10
- data/spec/files/reversible_migrations/006_reversible.rb +0 -10
- data/spec/files/reversible_migrations/007_reversible.rb +0 -10
- data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
- data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
- data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
- data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
- data/spec/guards_helper.rb +0 -59
- data/spec/integration/associations_test.rb +0 -2597
- data/spec/integration/database_test.rb +0 -113
- data/spec/integration/dataset_test.rb +0 -2037
- data/spec/integration/eager_loader_test.rb +0 -687
- data/spec/integration/migrator_test.rb +0 -262
- data/spec/integration/model_test.rb +0 -203
- data/spec/integration/plugin_test.rb +0 -2423
- data/spec/integration/prepared_statement_test.rb +0 -405
- data/spec/integration/schema_test.rb +0 -903
- data/spec/integration/spec_helper.rb +0 -71
- data/spec/integration/timezone_test.rb +0 -86
- data/spec/integration/transaction_test.rb +0 -603
- data/spec/integration/type_test.rb +0 -127
- data/spec/model/association_reflection_spec.rb +0 -803
- data/spec/model/associations_spec.rb +0 -4738
- data/spec/model/base_spec.rb +0 -875
- data/spec/model/class_dataset_methods_spec.rb +0 -146
- data/spec/model/dataset_methods_spec.rb +0 -198
- data/spec/model/eager_loading_spec.rb +0 -2377
- data/spec/model/hooks_spec.rb +0 -370
- data/spec/model/inflector_spec.rb +0 -26
- data/spec/model/model_spec.rb +0 -956
- data/spec/model/plugins_spec.rb +0 -429
- data/spec/model/record_spec.rb +0 -2118
- data/spec/model/spec_helper.rb +0 -46
- data/spec/model/validations_spec.rb +0 -220
- data/spec/model_no_assoc_spec.rb +0 -1
- data/spec/model_spec.rb +0 -1
- data/spec/plugin_spec.rb +0 -1
- data/spec/sequel_coverage.rb +0 -15
- data/spec/sequel_warning.rb +0 -5
- data/spec/spec_config.rb +0 -12
|
@@ -199,12 +199,18 @@ END_MIG
|
|
|
199
199
|
end
|
|
200
200
|
type = col_opts.delete(:type)
|
|
201
201
|
col_opts.delete(:size) if col_opts[:size].nil?
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
if schema[:generated]
|
|
203
|
+
if options[:same_db] && database_type == :postgres
|
|
204
|
+
col_opts[:generated_always_as] = column_schema_to_ruby_default_fallback(schema[:default], options)
|
|
205
|
+
end
|
|
204
206
|
else
|
|
205
|
-
schema[:ruby_default]
|
|
207
|
+
col_opts[:default] = if schema[:ruby_default].nil?
|
|
208
|
+
column_schema_to_ruby_default_fallback(schema[:default], options)
|
|
209
|
+
else
|
|
210
|
+
schema[:ruby_default]
|
|
211
|
+
end
|
|
212
|
+
col_opts.delete(:default) if col_opts[:default].nil?
|
|
206
213
|
end
|
|
207
|
-
col_opts.delete(:default) if col_opts[:default].nil?
|
|
208
214
|
col_opts[:null] = false if schema[:allow_null] == false
|
|
209
215
|
if table = schema[:table]
|
|
210
216
|
[:key, :on_delete, :on_update, :deferrable].each{|f| col_opts[f] = schema[f] if schema[f]}
|
|
@@ -143,13 +143,13 @@ module Sequel
|
|
|
143
143
|
|
|
144
144
|
# Make the given server the new default server for the current thread.
|
|
145
145
|
def set_default_server(default_server, read_only_server=default_server)
|
|
146
|
-
sync{(@default_servers[
|
|
146
|
+
sync{(@default_servers[Sequel.current] ||= [])} << [default_server, read_only_server]
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
# Remove the current default server for the current thread, restoring the
|
|
150
150
|
# previous default server.
|
|
151
151
|
def clear_default_server
|
|
152
|
-
t =
|
|
152
|
+
t = Sequel.current
|
|
153
153
|
a = sync{@default_servers[t]}
|
|
154
154
|
a.pop
|
|
155
155
|
sync{@default_servers.delete(t)} if a.empty?
|
|
@@ -157,7 +157,7 @@ module Sequel
|
|
|
157
157
|
|
|
158
158
|
# Use the server given to with_server for the given thread, if appropriate.
|
|
159
159
|
def pick_server(server)
|
|
160
|
-
a = sync{@default_servers[
|
|
160
|
+
a = sync{@default_servers[Sequel.current]}
|
|
161
161
|
if !a || a.empty?
|
|
162
162
|
super
|
|
163
163
|
else
|
data/lib/sequel/model.rb
CHANGED
|
@@ -69,7 +69,9 @@ module Sequel
|
|
|
69
69
|
require_relative "model/base"
|
|
70
70
|
require_relative "model/exceptions"
|
|
71
71
|
require_relative "model/errors"
|
|
72
|
+
# :nocov:
|
|
72
73
|
if !defined?(::SEQUEL_NO_ASSOCIATIONS) && !ENV.has_key?('SEQUEL_NO_ASSOCIATIONS')
|
|
74
|
+
# :nocov:
|
|
73
75
|
require_relative 'model/associations'
|
|
74
76
|
plugin Model::Associations
|
|
75
77
|
end
|
|
@@ -164,11 +164,11 @@ module Sequel
|
|
|
164
164
|
# range to return the object(s) at the correct offset/limit.
|
|
165
165
|
def apply_ruby_eager_limit_strategy(rows, limit_and_offset = limit_and_offset())
|
|
166
166
|
name = self[:name]
|
|
167
|
+
return unless range = slice_range(limit_and_offset)
|
|
167
168
|
if returns_array?
|
|
168
|
-
range = slice_range(limit_and_offset)
|
|
169
169
|
rows.each{|o| o.associations[name] = o.associations[name][range] || []}
|
|
170
|
-
|
|
171
|
-
offset =
|
|
170
|
+
else
|
|
171
|
+
offset = range.begin
|
|
172
172
|
rows.each{|o| o.associations[name] = o.associations[name][offset]}
|
|
173
173
|
end
|
|
174
174
|
end
|
|
@@ -1244,7 +1244,9 @@ module Sequel
|
|
|
1244
1244
|
else
|
|
1245
1245
|
assoc_record.values.delete(left_key_alias)
|
|
1246
1246
|
end
|
|
1247
|
-
|
|
1247
|
+
|
|
1248
|
+
objects = h[hash_key]
|
|
1249
|
+
|
|
1248
1250
|
if assign_singular
|
|
1249
1251
|
objects.each do |object|
|
|
1250
1252
|
object.associations[name] ||= assoc_record
|
|
@@ -1948,10 +1950,8 @@ module Sequel
|
|
|
1948
1950
|
if opts[:block]
|
|
1949
1951
|
opts[:block_method] = Plugins.def_sequel_method(association_module(opts), "#{opts[:name]}_block", 1, &opts[:block])
|
|
1950
1952
|
end
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
opts[:dataset_opt_method] = Plugins.def_sequel_method(association_module(opts), "#{opts[:name]}_dataset_opt", opts[:dataset_opt_arity], &opts[:dataset])
|
|
1954
|
-
end
|
|
1953
|
+
opts[:dataset_opt_arity] = opts[:dataset].arity == 0 ? 0 : 1
|
|
1954
|
+
opts[:dataset_opt_method] = Plugins.def_sequel_method(association_module(opts), "#{opts[:name]}_dataset_opt", opts[:dataset_opt_arity], &opts[:dataset])
|
|
1955
1955
|
def_association_method(opts)
|
|
1956
1956
|
|
|
1957
1957
|
return if opts[:read_only]
|
|
@@ -2122,9 +2122,7 @@ module Sequel
|
|
|
2122
2122
|
|
|
2123
2123
|
eager_load_results(opts, eo) do |assoc_record|
|
|
2124
2124
|
hash_key = uses_cks ? pk_meths.map{|k| assoc_record.get_column_value(k)} : assoc_record.get_column_value(opts.primary_key_method)
|
|
2125
|
-
|
|
2126
|
-
objects.each{|object| object.associations[name] = assoc_record}
|
|
2127
|
-
end
|
|
2125
|
+
h[hash_key].each{|object| object.associations[name] = assoc_record}
|
|
2128
2126
|
end
|
|
2129
2127
|
end
|
|
2130
2128
|
|
|
@@ -2171,7 +2169,7 @@ module Sequel
|
|
|
2171
2169
|
eager_load_results(opts, eo) do |assoc_record|
|
|
2172
2170
|
assoc_record.values.delete(delete_rn) if delete_rn
|
|
2173
2171
|
hash_key = uses_cks ? km.map{|k| assoc_record.get_column_value(k)} : assoc_record.get_column_value(km)
|
|
2174
|
-
|
|
2172
|
+
objects = h[hash_key]
|
|
2175
2173
|
if assign_singular
|
|
2176
2174
|
objects.each do |object|
|
|
2177
2175
|
unless object.associations[name]
|
|
@@ -2966,8 +2964,8 @@ module Sequel
|
|
|
2966
2964
|
# dataset. If that association also has dependent associations, instead of a callable object,
|
|
2967
2965
|
# use a hash with the callable object being the key, and the dependent association(s) as the value.
|
|
2968
2966
|
#
|
|
2969
|
-
# You can specify an alias
|
|
2970
|
-
# an a Symbol for the
|
|
2967
|
+
# You can specify an custom alias and/or join type on a per-association basis by providing an
|
|
2968
|
+
# Sequel::SQL::AliasedExpression object instead of an a Symbol for the association name.
|
|
2971
2969
|
#
|
|
2972
2970
|
# Examples:
|
|
2973
2971
|
#
|
|
@@ -2983,6 +2981,14 @@ module Sequel
|
|
|
2983
2981
|
# # FROM albums
|
|
2984
2982
|
# # LEFT OUTER JOIN artists AS a ON (a.id = albums.artist_id)
|
|
2985
2983
|
#
|
|
2984
|
+
# # For each album, eager_graph load the artist, using a specified alias
|
|
2985
|
+
# # and custom join type
|
|
2986
|
+
#
|
|
2987
|
+
# Album.eager_graph(Sequel[:artist].as(:a, join_type: :inner)).all
|
|
2988
|
+
# # SELECT ...
|
|
2989
|
+
# # FROM albums
|
|
2990
|
+
# # INNER JOIN artists AS a ON (a.id = albums.artist_id)
|
|
2991
|
+
#
|
|
2986
2992
|
# # For each album, eager_graph load the artist and genre
|
|
2987
2993
|
# Album.eager_graph(:artist, :genre).all
|
|
2988
2994
|
# Album.eager_graph(:artist).eager_graph(:genre).all
|
|
@@ -3056,6 +3062,8 @@ module Sequel
|
|
|
3056
3062
|
# significantly slower in some cases (perhaps even the majority of cases), so you should
|
|
3057
3063
|
# only use this if you have benchmarked that it is faster for your use cases.
|
|
3058
3064
|
def eager_graph_with_options(associations, opts=OPTS)
|
|
3065
|
+
return self if associations.empty?
|
|
3066
|
+
|
|
3059
3067
|
opts = opts.dup unless opts.frozen?
|
|
3060
3068
|
associations = [associations] unless associations.is_a?(Array)
|
|
3061
3069
|
ds = if eg = @opts[:eager_graph]
|
|
@@ -3125,11 +3133,16 @@ module Sequel
|
|
|
3125
3133
|
# ta :: table_alias used for the parent association
|
|
3126
3134
|
# requirements :: an array, used as a stack for requirements
|
|
3127
3135
|
# r :: association reflection for the current association, or an SQL::AliasedExpression
|
|
3128
|
-
# with the reflection as the expression
|
|
3136
|
+
# with the reflection as the expression, the alias base as the alias (or nil to
|
|
3137
|
+
# use the default alias), and an optional hash with a :join_type entry as the columns
|
|
3138
|
+
# to use a custom join type.
|
|
3129
3139
|
# *associations :: any associations dependent on this one
|
|
3130
3140
|
def eager_graph_association(ds, model, ta, requirements, r, *associations)
|
|
3131
3141
|
if r.is_a?(SQL::AliasedExpression)
|
|
3132
3142
|
alias_base = r.alias
|
|
3143
|
+
if r.columns.is_a?(Hash)
|
|
3144
|
+
join_type = r.columns[:join_type]
|
|
3145
|
+
end
|
|
3133
3146
|
r = r.expression
|
|
3134
3147
|
else
|
|
3135
3148
|
alias_base = r[:graph_alias_base]
|
|
@@ -3152,7 +3165,7 @@ module Sequel
|
|
|
3152
3165
|
raise Error, "Cannot eager_graph association when :conditions specified and not a hash or an array of pairs. Specify :graph_conditions, :graph_only_conditions, or :graph_block for the association. Model: #{r[:model]}, association: #{r[:name]}"
|
|
3153
3166
|
end
|
|
3154
3167
|
|
|
3155
|
-
ds = loader.call(:self=>ds, :table_alias=>assoc_table_alias, :implicit_qualifier=>(ta == ds.opts[:eager_graph][:master]) ? first_source : qualifier_from_alias_symbol(ta, first_source), :callback=>callback, :join_type=>local_opts[:join_type], :join_only=>local_opts[:join_only], :limit_strategy=>limit_strategy, :from_self_alias=>ds.opts[:eager_graph][:master])
|
|
3168
|
+
ds = loader.call(:self=>ds, :table_alias=>assoc_table_alias, :implicit_qualifier=>(ta == ds.opts[:eager_graph][:master]) ? first_source : qualifier_from_alias_symbol(ta, first_source), :callback=>callback, :join_type=>join_type || local_opts[:join_type], :join_only=>local_opts[:join_only], :limit_strategy=>limit_strategy, :from_self_alias=>ds.opts[:eager_graph][:master])
|
|
3156
3169
|
if r[:order_eager_graph] && (order = r.fetch(:graph_order, r[:order]))
|
|
3157
3170
|
ds = ds.order_append(*qualified_expression(order, assoc_table_alias))
|
|
3158
3171
|
end
|
|
@@ -3177,7 +3190,6 @@ module Sequel
|
|
|
3177
3190
|
# requirements :: an array, used as a stack for requirements
|
|
3178
3191
|
# *associations :: the associations to add to the graph
|
|
3179
3192
|
def eager_graph_associations(ds, model, ta, requirements, *associations)
|
|
3180
|
-
return ds if associations.empty?
|
|
3181
3193
|
associations.flatten.each do |association|
|
|
3182
3194
|
ds = case association
|
|
3183
3195
|
when Symbol, SQL::AliasedExpression
|
|
@@ -3307,7 +3319,7 @@ module Sequel
|
|
|
3307
3319
|
end
|
|
3308
3320
|
end
|
|
3309
3321
|
|
|
3310
|
-
SQL::AliasedExpression.new(check_association(model, expr), association.alias)
|
|
3322
|
+
SQL::AliasedExpression.new(check_association(model, expr), association.alias || expr, association.columns)
|
|
3311
3323
|
else
|
|
3312
3324
|
check_association(model, association)
|
|
3313
3325
|
end
|
data/lib/sequel/model/base.rb
CHANGED
|
@@ -460,47 +460,6 @@ module Sequel
|
|
|
460
460
|
super
|
|
461
461
|
end
|
|
462
462
|
|
|
463
|
-
# If possible, set the dataset for the model subclass as soon as it
|
|
464
|
-
# is created. Also, make sure the inherited class instance variables
|
|
465
|
-
# are copied into the subclass.
|
|
466
|
-
#
|
|
467
|
-
# Sequel queries the database to get schema information as soon as
|
|
468
|
-
# a model class is created:
|
|
469
|
-
#
|
|
470
|
-
# class Artist < Sequel::Model # Causes schema query
|
|
471
|
-
# end
|
|
472
|
-
def inherited(subclass)
|
|
473
|
-
super
|
|
474
|
-
ivs = subclass.instance_variables
|
|
475
|
-
inherited_instance_variables.each do |iv, dup|
|
|
476
|
-
next if ivs.include?(iv)
|
|
477
|
-
if (sup_class_value = instance_variable_get(iv)) && dup
|
|
478
|
-
sup_class_value = case dup
|
|
479
|
-
when :dup
|
|
480
|
-
sup_class_value.dup
|
|
481
|
-
when :hash_dup
|
|
482
|
-
h = {}
|
|
483
|
-
sup_class_value.each{|k,v| h[k] = v.dup}
|
|
484
|
-
h
|
|
485
|
-
when Proc
|
|
486
|
-
dup.call(sup_class_value)
|
|
487
|
-
else
|
|
488
|
-
raise Error, "bad inherited instance variable type: #{dup.inspect}"
|
|
489
|
-
end
|
|
490
|
-
end
|
|
491
|
-
subclass.instance_variable_set(iv, sup_class_value)
|
|
492
|
-
end
|
|
493
|
-
|
|
494
|
-
unless ivs.include?(:@dataset)
|
|
495
|
-
if @dataset && self != Model
|
|
496
|
-
subclass.set_dataset(@dataset.clone, :inherited=>true)
|
|
497
|
-
elsif (n = subclass.name) && !n.to_s.empty?
|
|
498
|
-
db
|
|
499
|
-
subclass.set_dataset(subclass.implicit_table_name)
|
|
500
|
-
end
|
|
501
|
-
end
|
|
502
|
-
end
|
|
503
|
-
|
|
504
463
|
# Returns the implicit table name for the model class, which is the demodulized,
|
|
505
464
|
# underscored, pluralized name of the class.
|
|
506
465
|
#
|
|
@@ -515,12 +474,6 @@ module Sequel
|
|
|
515
474
|
call(values)
|
|
516
475
|
end
|
|
517
476
|
|
|
518
|
-
# Clear the setter_methods cache when a setter method is added.
|
|
519
|
-
def method_added(meth)
|
|
520
|
-
clear_setter_methods_cache if meth.to_s.end_with?('=')
|
|
521
|
-
super
|
|
522
|
-
end
|
|
523
|
-
|
|
524
477
|
# Mark the model as not having a primary key. Not having a primary key
|
|
525
478
|
# can cause issues, among which is that you won't be able to update records.
|
|
526
479
|
#
|
|
@@ -640,7 +593,7 @@ module Sequel
|
|
|
640
593
|
@columns = superclass.instance_variable_get(:@columns)
|
|
641
594
|
@db_schema = superclass.instance_variable_get(:@db_schema)
|
|
642
595
|
else
|
|
643
|
-
@dataset = @dataset.with_extend(*@dataset_method_modules.reverse)
|
|
596
|
+
@dataset = @dataset.with_extend(*@dataset_method_modules.reverse)
|
|
644
597
|
@db_schema = get_db_schema
|
|
645
598
|
end
|
|
646
599
|
|
|
@@ -854,6 +807,46 @@ module Sequel
|
|
|
854
807
|
meths
|
|
855
808
|
end
|
|
856
809
|
|
|
810
|
+
# If possible, set the dataset for the model subclass as soon as it
|
|
811
|
+
# is created. Also, make sure the inherited class instance variables
|
|
812
|
+
# are copied into the subclass.
|
|
813
|
+
#
|
|
814
|
+
# Sequel queries the database to get schema information as soon as
|
|
815
|
+
# a model class is created:
|
|
816
|
+
#
|
|
817
|
+
# class Artist < Sequel::Model # Causes schema query
|
|
818
|
+
# end
|
|
819
|
+
def inherited(subclass)
|
|
820
|
+
super
|
|
821
|
+
ivs = subclass.instance_variables
|
|
822
|
+
inherited_instance_variables.each do |iv, dup|
|
|
823
|
+
if (sup_class_value = instance_variable_get(iv)) && dup
|
|
824
|
+
sup_class_value = case dup
|
|
825
|
+
when :dup
|
|
826
|
+
sup_class_value.dup
|
|
827
|
+
when :hash_dup
|
|
828
|
+
h = {}
|
|
829
|
+
sup_class_value.each{|k,v| h[k] = v.dup}
|
|
830
|
+
h
|
|
831
|
+
when Proc
|
|
832
|
+
dup.call(sup_class_value)
|
|
833
|
+
else
|
|
834
|
+
raise Error, "bad inherited instance variable type: #{dup.inspect}"
|
|
835
|
+
end
|
|
836
|
+
end
|
|
837
|
+
subclass.instance_variable_set(iv, sup_class_value)
|
|
838
|
+
end
|
|
839
|
+
|
|
840
|
+
unless ivs.include?(:@dataset)
|
|
841
|
+
if @dataset && self != Model
|
|
842
|
+
subclass.set_dataset(@dataset.clone, :inherited=>true)
|
|
843
|
+
elsif (n = subclass.name) && !n.to_s.empty?
|
|
844
|
+
db
|
|
845
|
+
subclass.set_dataset(subclass.implicit_table_name)
|
|
846
|
+
end
|
|
847
|
+
end
|
|
848
|
+
end
|
|
849
|
+
|
|
857
850
|
# A hash of instance variables to automatically set up in subclasses.
|
|
858
851
|
# Keys are instance variable symbols, values should be:
|
|
859
852
|
# nil :: Assign directly from superclass to subclass (frozen objects)
|
|
@@ -908,6 +901,12 @@ module Sequel
|
|
|
908
901
|
opts[:class_name] ||= '::' + ((name || '').split("::")[0..-2] + [camelize(default)]).join('::')
|
|
909
902
|
end
|
|
910
903
|
|
|
904
|
+
# Clear the setter_methods cache when a setter method is added.
|
|
905
|
+
def method_added(meth)
|
|
906
|
+
clear_setter_methods_cache if meth.to_s.end_with?('=')
|
|
907
|
+
super
|
|
908
|
+
end
|
|
909
|
+
|
|
911
910
|
# Module that the class includes that holds methods the class adds for column accessors and
|
|
912
911
|
# associations so that the methods can be overridden with +super+.
|
|
913
912
|
def overridable_methods_module
|
|
@@ -1116,7 +1115,7 @@ module Sequel
|
|
|
1116
1115
|
when nil
|
|
1117
1116
|
return false
|
|
1118
1117
|
when Array
|
|
1119
|
-
return false if
|
|
1118
|
+
return false if pkv.any?(&:nil?)
|
|
1120
1119
|
end
|
|
1121
1120
|
|
|
1122
1121
|
(obj.class == model) && (obj.pk == pkv)
|
|
@@ -1718,6 +1717,7 @@ module Sequel
|
|
|
1718
1717
|
|
|
1719
1718
|
# The values hash to use when inserting a new record.
|
|
1720
1719
|
alias _insert_values values
|
|
1720
|
+
private :_insert_values
|
|
1721
1721
|
|
|
1722
1722
|
# Refresh using a particular dataset, used inside save to make sure the same server
|
|
1723
1723
|
# is used for reading newly inserted values from the database
|
|
@@ -1772,14 +1772,12 @@ module Sequel
|
|
|
1772
1772
|
before_update
|
|
1773
1773
|
columns = opts[:columns]
|
|
1774
1774
|
if columns.nil?
|
|
1775
|
-
if opts[:changed]
|
|
1776
|
-
|
|
1777
|
-
columns_updated = @values.reject{|k,v| !cc.include?(k)}
|
|
1778
|
-
cc.clear
|
|
1775
|
+
columns_updated = if opts[:changed]
|
|
1776
|
+
_save_update_changed_colums_hash
|
|
1779
1777
|
else
|
|
1780
|
-
|
|
1781
|
-
_clear_changed_columns(:update)
|
|
1778
|
+
_save_update_all_columns_hash
|
|
1782
1779
|
end
|
|
1780
|
+
_clear_changed_columns(:update)
|
|
1783
1781
|
else # update only the specified columns
|
|
1784
1782
|
columns = Array(columns)
|
|
1785
1783
|
columns_updated = @values.reject{|k, v| !columns.include?(k)}
|
|
@@ -1827,6 +1825,14 @@ module Sequel
|
|
|
1827
1825
|
v
|
|
1828
1826
|
end
|
|
1829
1827
|
|
|
1828
|
+
# Return a hash of values used when saving changed columns of an
|
|
1829
|
+
# existing object. Defaults to all of the objects current values
|
|
1830
|
+
# that are recorded as modified.
|
|
1831
|
+
def _save_update_changed_colums_hash
|
|
1832
|
+
cc = changed_columns
|
|
1833
|
+
@values.reject{|k,v| !cc.include?(k)}
|
|
1834
|
+
end
|
|
1835
|
+
|
|
1830
1836
|
# Validate the object if validating on save. Skips validation
|
|
1831
1837
|
# completely (including validation hooks) if
|
|
1832
1838
|
# skip_validation_on_save! has been called on the object,
|
|
@@ -1982,6 +1988,7 @@ module Sequel
|
|
|
1982
1988
|
|
|
1983
1989
|
# Get the ruby class or classes related to the given column's type.
|
|
1984
1990
|
def schema_type_class(column)
|
|
1991
|
+
# SEQUEL6: Remove
|
|
1985
1992
|
if (sch = db_schema[column]) && (type = sch[:type])
|
|
1986
1993
|
db.schema_type_class(type)
|
|
1987
1994
|
end
|
|
@@ -2225,7 +2232,9 @@ module Sequel
|
|
|
2225
2232
|
plugin self
|
|
2226
2233
|
|
|
2227
2234
|
singleton_class.send(:undef_method, :dup, :clone, :initialize_copy)
|
|
2235
|
+
# :nocov:
|
|
2228
2236
|
if RUBY_VERSION >= '1.9.3'
|
|
2237
|
+
# :nocov:
|
|
2229
2238
|
singleton_class.send(:undef_method, :initialize_clone, :initialize_dup)
|
|
2230
2239
|
end
|
|
2231
2240
|
end
|
data/lib/sequel/model/plugins.rb
CHANGED
|
@@ -40,6 +40,7 @@ module Sequel
|
|
|
40
40
|
mod.send(:define_method, :inherited_instance_variables) do ||
|
|
41
41
|
super().merge!(hash)
|
|
42
42
|
end
|
|
43
|
+
mod.send(:private, :inherited_instance_variables)
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
# Add method to +mod+ that overrides set_dataset to call the method afterward.
|
|
@@ -148,9 +149,8 @@ module Sequel
|
|
|
148
149
|
required_args = arity
|
|
149
150
|
arity -= 1 if keyword == :required
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
end
|
|
152
|
+
# callable currently is always a non-lambda Proc
|
|
153
|
+
optional_args -= arity
|
|
154
154
|
|
|
155
155
|
[required_args, optional_args, rest, keyword]
|
|
156
156
|
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen-string-literal: true
|
|
2
|
+
|
|
3
|
+
module Sequel
|
|
4
|
+
module Plugins
|
|
5
|
+
# The association_lazy_eager_option plugin supports passing
|
|
6
|
+
# an +:eager+ option to an association method. If the related
|
|
7
|
+
# association is already cached, the cached version will be
|
|
8
|
+
# returned. If the association is not already cached, it will
|
|
9
|
+
# be loaded, and the value of the +:eager+ option will be used
|
|
10
|
+
# to perform an eager load of the given associations.
|
|
11
|
+
# the plural versions.
|
|
12
|
+
#
|
|
13
|
+
# With Sequel's default behavior, you can already perform an
|
|
14
|
+
# eager load when lazy loading using a block:
|
|
15
|
+
#
|
|
16
|
+
# obj.association{|ds| ds.eager(:nested_association)}
|
|
17
|
+
#
|
|
18
|
+
# However, this will ignore any cached version. In more
|
|
19
|
+
# complex software, the association may already be cached
|
|
20
|
+
# and have the nested association cached inside of it, and
|
|
21
|
+
# using this callback approach then requires 2 unnecessary
|
|
22
|
+
# queries. This plugin will not perform any queries if the
|
|
23
|
+
# association is already cached, preventing duplicate work.
|
|
24
|
+
# However, you should make sure that an already loaded
|
|
25
|
+
# association has the nested association already eagerly
|
|
26
|
+
# loaded.
|
|
27
|
+
#
|
|
28
|
+
# Usage:
|
|
29
|
+
#
|
|
30
|
+
# # Make all model subclasses support the :eager association
|
|
31
|
+
# # method option (called before loading subclasses)
|
|
32
|
+
# Sequel::Model.plugin :association_lazy_eager_option
|
|
33
|
+
#
|
|
34
|
+
# # Make the Album class support the :eager association
|
|
35
|
+
# # method option
|
|
36
|
+
# Album.plugin :association_lazy_eager_option
|
|
37
|
+
module AssociationLazyEagerOption
|
|
38
|
+
module InstanceMethods
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
# Return a dataset for the association after applying any dynamic callback.
|
|
42
|
+
def _associated_dataset(opts, dynamic_opts)
|
|
43
|
+
ds = super
|
|
44
|
+
|
|
45
|
+
if eager = dynamic_opts[:eager]
|
|
46
|
+
ds = ds.eager(eager)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
ds
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# A placeholder literalizer that can be used to load the association, or nil to not use one.
|
|
53
|
+
def _associated_object_loader(opts, dynamic_opts)
|
|
54
|
+
return if dynamic_opts[:eager]
|
|
55
|
+
super
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Whether to use a simple primary key lookup on the associated class when loading.
|
|
59
|
+
def load_with_primary_key_lookup?(opts, dynamic_opts)
|
|
60
|
+
return false if dynamic_opts[:eager]
|
|
61
|
+
super
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|