sequel 4.49.0 → 5.3.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.
Files changed (484) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +130 -0
  3. data/README.rdoc +195 -136
  4. data/Rakefile +26 -42
  5. data/bin/sequel +6 -9
  6. data/doc/advanced_associations.rdoc +91 -168
  7. data/doc/association_basics.rdoc +197 -274
  8. data/doc/bin_sequel.rdoc +5 -3
  9. data/doc/cheat_sheet.rdoc +66 -43
  10. data/doc/code_order.rdoc +1 -8
  11. data/doc/core_extensions.rdoc +81 -56
  12. data/doc/dataset_basics.rdoc +8 -17
  13. data/doc/dataset_filtering.rdoc +81 -86
  14. data/doc/extensions.rdoc +3 -10
  15. data/doc/mass_assignment.rdoc +73 -30
  16. data/doc/migration.rdoc +19 -36
  17. data/doc/model_dataset_method_design.rdoc +14 -17
  18. data/doc/model_hooks.rdoc +15 -25
  19. data/doc/model_plugins.rdoc +10 -10
  20. data/doc/mssql_stored_procedures.rdoc +3 -3
  21. data/doc/object_model.rdoc +52 -70
  22. data/doc/opening_databases.rdoc +39 -32
  23. data/doc/postgresql.rdoc +48 -38
  24. data/doc/prepared_statements.rdoc +27 -22
  25. data/doc/querying.rdoc +173 -150
  26. data/doc/reflection.rdoc +5 -6
  27. data/doc/release_notes/5.0.0.txt +159 -0
  28. data/doc/release_notes/5.1.0.txt +31 -0
  29. data/doc/release_notes/5.2.0.txt +33 -0
  30. data/doc/release_notes/5.3.0.txt +121 -0
  31. data/doc/schema_modification.rdoc +78 -64
  32. data/doc/security.rdoc +97 -88
  33. data/doc/sharding.rdoc +43 -30
  34. data/doc/sql.rdoc +53 -65
  35. data/doc/testing.rdoc +4 -5
  36. data/doc/thread_safety.rdoc +2 -4
  37. data/doc/transactions.rdoc +18 -17
  38. data/doc/validations.rdoc +48 -45
  39. data/doc/virtual_rows.rdoc +87 -115
  40. data/lib/sequel/adapters/ado/access.rb +7 -13
  41. data/lib/sequel/adapters/ado/mssql.rb +2 -9
  42. data/lib/sequel/adapters/ado.rb +9 -25
  43. data/lib/sequel/adapters/amalgalite.rb +3 -18
  44. data/lib/sequel/adapters/ibmdb.rb +9 -45
  45. data/lib/sequel/adapters/jdbc/db2.rb +8 -37
  46. data/lib/sequel/adapters/jdbc/derby.rb +4 -50
  47. data/lib/sequel/adapters/jdbc/h2.rb +6 -26
  48. data/lib/sequel/adapters/jdbc/hsqldb.rb +2 -27
  49. data/lib/sequel/adapters/jdbc/jtds.rb +2 -9
  50. data/lib/sequel/adapters/jdbc/mssql.rb +1 -11
  51. data/lib/sequel/adapters/jdbc/mysql.rb +11 -15
  52. data/lib/sequel/adapters/jdbc/oracle.rb +4 -26
  53. data/lib/sequel/adapters/jdbc/postgresql.rb +23 -33
  54. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +4 -17
  55. data/lib/sequel/adapters/jdbc/sqlite.rb +1 -7
  56. data/lib/sequel/adapters/jdbc/sqlserver.rb +1 -13
  57. data/lib/sequel/adapters/jdbc/transactions.rb +1 -14
  58. data/lib/sequel/adapters/jdbc.rb +18 -74
  59. data/lib/sequel/adapters/mock.rb +4 -30
  60. data/lib/sequel/adapters/mysql.rb +7 -44
  61. data/lib/sequel/adapters/mysql2.rb +5 -23
  62. data/lib/sequel/adapters/odbc/db2.rb +1 -1
  63. data/lib/sequel/adapters/odbc/mssql.rb +4 -12
  64. data/lib/sequel/adapters/odbc/oracle.rb +1 -1
  65. data/lib/sequel/adapters/odbc.rb +0 -19
  66. data/lib/sequel/adapters/oracle.rb +8 -13
  67. data/lib/sequel/adapters/postgres.rb +28 -150
  68. data/lib/sequel/adapters/postgresql.rb +1 -1
  69. data/lib/sequel/adapters/shared/access.rb +11 -51
  70. data/lib/sequel/adapters/shared/db2.rb +3 -61
  71. data/lib/sequel/adapters/shared/mssql.rb +21 -157
  72. data/lib/sequel/adapters/shared/mysql.rb +61 -227
  73. data/lib/sequel/adapters/shared/oracle.rb +13 -41
  74. data/lib/sequel/adapters/shared/postgres.rb +58 -264
  75. data/lib/sequel/adapters/shared/sqlanywhere.rb +4 -96
  76. data/lib/sequel/adapters/shared/sqlite.rb +22 -101
  77. data/lib/sequel/adapters/sqlanywhere.rb +4 -23
  78. data/lib/sequel/adapters/sqlite.rb +2 -19
  79. data/lib/sequel/adapters/tinytds.rb +5 -15
  80. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +1 -1
  81. data/lib/sequel/adapters/utils/mysql_mysql2.rb +4 -4
  82. data/lib/sequel/adapters/utils/mysql_prepared_statements.rb +3 -6
  83. data/lib/sequel/adapters/utils/replace.rb +0 -5
  84. data/lib/sequel/adapters/utils/stored_procedures.rb +0 -2
  85. data/lib/sequel/adapters/utils/unmodified_identifiers.rb +2 -0
  86. data/lib/sequel/ast_transformer.rb +3 -94
  87. data/lib/sequel/connection_pool/sharded_single.rb +1 -4
  88. data/lib/sequel/connection_pool/sharded_threaded.rb +97 -95
  89. data/lib/sequel/connection_pool/single.rb +0 -2
  90. data/lib/sequel/connection_pool/threaded.rb +94 -110
  91. data/lib/sequel/connection_pool.rb +38 -28
  92. data/lib/sequel/core.rb +42 -101
  93. data/lib/sequel/database/connecting.rb +23 -60
  94. data/lib/sequel/database/dataset.rb +6 -9
  95. data/lib/sequel/database/dataset_defaults.rb +4 -48
  96. data/lib/sequel/database/features.rb +5 -4
  97. data/lib/sequel/database/logging.rb +2 -9
  98. data/lib/sequel/database/misc.rb +36 -55
  99. data/lib/sequel/database/query.rb +8 -13
  100. data/lib/sequel/database/schema_generator.rb +93 -64
  101. data/lib/sequel/database/schema_methods.rb +61 -79
  102. data/lib/sequel/database/transactions.rb +4 -24
  103. data/lib/sequel/database.rb +12 -2
  104. data/lib/sequel/dataset/actions.rb +57 -107
  105. data/lib/sequel/dataset/dataset_module.rb +4 -16
  106. data/lib/sequel/dataset/features.rb +35 -30
  107. data/lib/sequel/dataset/graph.rb +40 -49
  108. data/lib/sequel/dataset/misc.rb +12 -37
  109. data/lib/sequel/dataset/placeholder_literalizer.rb +4 -4
  110. data/lib/sequel/dataset/prepared_statements.rb +23 -51
  111. data/lib/sequel/dataset/query.rb +91 -161
  112. data/lib/sequel/dataset/sql.rb +33 -225
  113. data/lib/sequel/dataset.rb +18 -10
  114. data/lib/sequel/deprecated.rb +18 -27
  115. data/lib/sequel/exceptions.rb +1 -17
  116. data/lib/sequel/extensions/_model_pg_row.rb +0 -7
  117. data/lib/sequel/extensions/_pretty_table.rb +1 -3
  118. data/lib/sequel/extensions/arbitrary_servers.rb +10 -10
  119. data/lib/sequel/extensions/connection_expiration.rb +1 -1
  120. data/lib/sequel/extensions/connection_validator.rb +1 -1
  121. data/lib/sequel/extensions/constraint_validations.rb +11 -11
  122. data/lib/sequel/extensions/core_extensions.rb +39 -49
  123. data/lib/sequel/extensions/core_refinements.rb +39 -45
  124. data/lib/sequel/extensions/current_datetime_timestamp.rb +0 -4
  125. data/lib/sequel/extensions/date_arithmetic.rb +7 -7
  126. data/lib/sequel/extensions/duplicate_columns_handler.rb +12 -9
  127. data/lib/sequel/extensions/empty_array_consider_nulls.rb +2 -2
  128. data/lib/sequel/extensions/eval_inspect.rb +4 -11
  129. data/lib/sequel/extensions/freeze_datasets.rb +1 -69
  130. data/lib/sequel/extensions/from_block.rb +1 -35
  131. data/lib/sequel/extensions/graph_each.rb +2 -2
  132. data/lib/sequel/extensions/identifier_mangling.rb +9 -19
  133. data/lib/sequel/extensions/implicit_subquery.rb +2 -2
  134. data/lib/sequel/extensions/inflector.rb +4 -4
  135. data/lib/sequel/extensions/migration.rb +27 -43
  136. data/lib/sequel/extensions/no_auto_literal_strings.rb +2 -84
  137. data/lib/sequel/extensions/null_dataset.rb +2 -8
  138. data/lib/sequel/extensions/pagination.rb +1 -17
  139. data/lib/sequel/extensions/pg_array.rb +20 -189
  140. data/lib/sequel/extensions/pg_extended_date_support.rb +230 -0
  141. data/lib/sequel/extensions/pg_hstore.rb +11 -50
  142. data/lib/sequel/extensions/pg_hstore_ops.rb +2 -2
  143. data/lib/sequel/extensions/pg_inet.rb +3 -16
  144. data/lib/sequel/extensions/pg_interval.rb +1 -20
  145. data/lib/sequel/extensions/pg_json.rb +7 -27
  146. data/lib/sequel/extensions/pg_loose_count.rb +1 -1
  147. data/lib/sequel/extensions/pg_range.rb +6 -121
  148. data/lib/sequel/extensions/pg_range_ops.rb +1 -3
  149. data/lib/sequel/extensions/pg_row.rb +5 -77
  150. data/lib/sequel/extensions/pg_row_ops.rb +2 -13
  151. data/lib/sequel/extensions/query.rb +3 -4
  152. data/lib/sequel/extensions/round_timestamps.rb +0 -6
  153. data/lib/sequel/extensions/schema_dumper.rb +13 -13
  154. data/lib/sequel/extensions/select_remove.rb +3 -3
  155. data/lib/sequel/extensions/split_array_nil.rb +2 -2
  156. data/lib/sequel/extensions/sql_comments.rb +2 -2
  157. data/lib/sequel/extensions/string_agg.rb +11 -8
  158. data/lib/sequel/extensions/symbol_aref.rb +6 -20
  159. data/lib/sequel/extensions/synchronize_sql.rb +45 -0
  160. data/lib/sequel/model/associations.rb +129 -131
  161. data/lib/sequel/model/base.rb +133 -731
  162. data/lib/sequel/model/default_inflections.rb +1 -1
  163. data/lib/sequel/model/errors.rb +0 -3
  164. data/lib/sequel/model/exceptions.rb +2 -6
  165. data/lib/sequel/model/inflections.rb +1 -26
  166. data/lib/sequel/model/plugins.rb +1 -0
  167. data/lib/sequel/model.rb +27 -62
  168. data/lib/sequel/plugins/active_model.rb +2 -5
  169. data/lib/sequel/plugins/association_dependencies.rb +15 -15
  170. data/lib/sequel/plugins/association_pks.rb +14 -28
  171. data/lib/sequel/plugins/association_proxies.rb +6 -7
  172. data/lib/sequel/plugins/auto_validations.rb +4 -4
  173. data/lib/sequel/plugins/before_after_save.rb +0 -43
  174. data/lib/sequel/plugins/blacklist_security.rb +9 -8
  175. data/lib/sequel/plugins/boolean_readers.rb +3 -3
  176. data/lib/sequel/plugins/boolean_subsets.rb +2 -2
  177. data/lib/sequel/plugins/caching.rb +5 -5
  178. data/lib/sequel/plugins/class_table_inheritance.rb +71 -102
  179. data/lib/sequel/plugins/column_conflicts.rb +2 -2
  180. data/lib/sequel/plugins/column_select.rb +2 -2
  181. data/lib/sequel/plugins/composition.rb +15 -24
  182. data/lib/sequel/plugins/constraint_validations.rb +4 -3
  183. data/lib/sequel/plugins/csv_serializer.rb +13 -20
  184. data/lib/sequel/plugins/dataset_associations.rb +2 -2
  185. data/lib/sequel/plugins/def_dataset_method.rb +5 -5
  186. data/lib/sequel/plugins/defaults_setter.rb +1 -1
  187. data/lib/sequel/plugins/delay_add_association.rb +1 -1
  188. data/lib/sequel/plugins/finder.rb +16 -10
  189. data/lib/sequel/plugins/force_encoding.rb +1 -7
  190. data/lib/sequel/plugins/hook_class_methods.rb +4 -106
  191. data/lib/sequel/plugins/input_transformer.rb +10 -11
  192. data/lib/sequel/plugins/insert_returning_select.rb +1 -9
  193. data/lib/sequel/plugins/instance_filters.rb +5 -5
  194. data/lib/sequel/plugins/instance_hooks.rb +7 -52
  195. data/lib/sequel/plugins/inverted_subsets.rb +3 -1
  196. data/lib/sequel/plugins/json_serializer.rb +19 -19
  197. data/lib/sequel/plugins/lazy_attributes.rb +1 -10
  198. data/lib/sequel/plugins/list.rb +6 -6
  199. data/lib/sequel/plugins/many_through_many.rb +11 -8
  200. data/lib/sequel/plugins/mssql_optimistic_locking.rb +3 -3
  201. data/lib/sequel/plugins/nested_attributes.rb +18 -31
  202. data/lib/sequel/plugins/optimistic_locking.rb +3 -3
  203. data/lib/sequel/plugins/pg_array_associations.rb +8 -2
  204. data/lib/sequel/plugins/pg_row.rb +2 -11
  205. data/lib/sequel/plugins/prepared_statements.rb +13 -66
  206. data/lib/sequel/plugins/prepared_statements_safe.rb +1 -1
  207. data/lib/sequel/plugins/rcte_tree.rb +7 -7
  208. data/lib/sequel/plugins/serialization.rb +15 -33
  209. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  210. data/lib/sequel/plugins/sharding.rb +2 -8
  211. data/lib/sequel/plugins/single_table_inheritance.rb +10 -13
  212. data/lib/sequel/plugins/skip_create_refresh.rb +3 -3
  213. data/lib/sequel/plugins/static_cache.rb +8 -9
  214. data/lib/sequel/plugins/string_stripper.rb +3 -3
  215. data/lib/sequel/plugins/subclasses.rb +1 -1
  216. data/lib/sequel/plugins/subset_conditions.rb +2 -2
  217. data/lib/sequel/plugins/table_select.rb +2 -2
  218. data/lib/sequel/plugins/tactical_eager_loading.rb +4 -4
  219. data/lib/sequel/plugins/timestamps.rb +6 -7
  220. data/lib/sequel/plugins/touch.rb +4 -8
  221. data/lib/sequel/plugins/tree.rb +3 -3
  222. data/lib/sequel/plugins/typecast_on_load.rb +2 -2
  223. data/lib/sequel/plugins/unlimited_update.rb +1 -7
  224. data/lib/sequel/plugins/update_or_create.rb +3 -3
  225. data/lib/sequel/plugins/update_refresh.rb +3 -3
  226. data/lib/sequel/plugins/uuid.rb +7 -11
  227. data/lib/sequel/plugins/validation_class_methods.rb +10 -9
  228. data/lib/sequel/plugins/validation_contexts.rb +4 -4
  229. data/lib/sequel/plugins/validation_helpers.rb +26 -25
  230. data/lib/sequel/plugins/whitelist_security.rb +13 -9
  231. data/lib/sequel/plugins/xml_serializer.rb +24 -25
  232. data/lib/sequel/sql.rb +145 -276
  233. data/lib/sequel/timezones.rb +8 -23
  234. data/lib/sequel/version.rb +2 -2
  235. data/lib/sequel.rb +1 -1
  236. data/spec/adapter_spec.rb +1 -1
  237. data/spec/adapters/db2_spec.rb +2 -103
  238. data/spec/adapters/mssql_spec.rb +89 -68
  239. data/spec/adapters/mysql_spec.rb +111 -478
  240. data/spec/adapters/oracle_spec.rb +1 -9
  241. data/spec/adapters/postgres_spec.rb +459 -664
  242. data/spec/adapters/spec_helper.rb +12 -31
  243. data/spec/adapters/sqlanywhere_spec.rb +2 -77
  244. data/spec/adapters/sqlite_spec.rb +8 -146
  245. data/spec/bin_spec.rb +11 -16
  246. data/spec/core/connection_pool_spec.rb +173 -74
  247. data/spec/core/database_spec.rb +96 -244
  248. data/spec/core/dataset_spec.rb +99 -414
  249. data/spec/core/deprecated_spec.rb +3 -3
  250. data/spec/core/expression_filters_spec.rb +37 -144
  251. data/spec/core/mock_adapter_spec.rb +241 -4
  252. data/spec/core/object_graph_spec.rb +11 -60
  253. data/spec/core/placeholder_literalizer_spec.rb +1 -14
  254. data/spec/core/schema_generator_spec.rb +51 -40
  255. data/spec/core/schema_spec.rb +88 -77
  256. data/spec/core/spec_helper.rb +6 -24
  257. data/spec/core/version_spec.rb +1 -1
  258. data/spec/core_extensions_spec.rb +7 -83
  259. data/spec/core_model_spec.rb +2 -2
  260. data/spec/deprecation_helper.rb +2 -14
  261. data/spec/extensions/accessed_columns_spec.rb +1 -1
  262. data/spec/extensions/active_model_spec.rb +3 -3
  263. data/spec/extensions/after_initialize_spec.rb +1 -1
  264. data/spec/extensions/arbitrary_servers_spec.rb +2 -2
  265. data/spec/extensions/association_dependencies_spec.rb +1 -1
  266. data/spec/extensions/association_pks_spec.rb +30 -92
  267. data/spec/extensions/association_proxies_spec.rb +1 -1
  268. data/spec/extensions/auto_literal_strings_spec.rb +1 -12
  269. data/spec/extensions/auto_validations_spec.rb +1 -1
  270. data/spec/extensions/blacklist_security_spec.rb +1 -1
  271. data/spec/extensions/blank_spec.rb +1 -1
  272. data/spec/extensions/boolean_readers_spec.rb +1 -1
  273. data/spec/extensions/boolean_subsets_spec.rb +1 -1
  274. data/spec/extensions/caching_spec.rb +1 -1
  275. data/spec/extensions/class_table_inheritance_spec.rb +53 -1118
  276. data/spec/extensions/column_conflicts_spec.rb +1 -1
  277. data/spec/extensions/column_select_spec.rb +4 -4
  278. data/spec/extensions/columns_introspection_spec.rb +1 -1
  279. data/spec/extensions/columns_updated_spec.rb +1 -1
  280. data/spec/extensions/composition_spec.rb +8 -30
  281. data/spec/extensions/connection_expiration_spec.rb +3 -3
  282. data/spec/extensions/connection_validator_spec.rb +3 -3
  283. data/spec/extensions/constraint_validations_plugin_spec.rb +1 -1
  284. data/spec/extensions/constraint_validations_spec.rb +1 -1
  285. data/spec/extensions/core_refinements_spec.rb +1 -3
  286. data/spec/extensions/csv_serializer_spec.rb +4 -9
  287. data/spec/extensions/current_datetime_timestamp_spec.rb +1 -1
  288. data/spec/extensions/dataset_associations_spec.rb +2 -1
  289. data/spec/extensions/dataset_source_alias_spec.rb +1 -1
  290. data/spec/extensions/date_arithmetic_spec.rb +3 -3
  291. data/spec/extensions/def_dataset_method_spec.rb +1 -1
  292. data/spec/extensions/defaults_setter_spec.rb +2 -2
  293. data/spec/extensions/delay_add_association_spec.rb +8 -9
  294. data/spec/extensions/dirty_spec.rb +1 -1
  295. data/spec/extensions/duplicate_columns_handler_spec.rb +1 -1
  296. data/spec/extensions/eager_each_spec.rb +2 -2
  297. data/spec/extensions/empty_array_consider_nulls_spec.rb +1 -1
  298. data/spec/extensions/error_splitter_spec.rb +1 -1
  299. data/spec/extensions/error_sql_spec.rb +1 -1
  300. data/spec/extensions/eval_inspect_spec.rb +1 -1
  301. data/spec/extensions/finder_spec.rb +1 -1
  302. data/spec/extensions/force_encoding_spec.rb +2 -5
  303. data/spec/extensions/freeze_datasets_spec.rb +1 -1
  304. data/spec/extensions/graph_each_spec.rb +5 -5
  305. data/spec/extensions/hook_class_methods_spec.rb +1 -194
  306. data/spec/extensions/identifier_mangling_spec.rb +17 -170
  307. data/spec/extensions/implicit_subquery_spec.rb +1 -5
  308. data/spec/extensions/inflector_spec.rb +1 -1
  309. data/spec/extensions/input_transformer_spec.rb +7 -2
  310. data/spec/extensions/insert_returning_select_spec.rb +1 -1
  311. data/spec/extensions/instance_filters_spec.rb +1 -1
  312. data/spec/extensions/instance_hooks_spec.rb +1 -95
  313. data/spec/extensions/inverted_subsets_spec.rb +1 -1
  314. data/spec/extensions/json_serializer_spec.rb +1 -1
  315. data/spec/extensions/lazy_attributes_spec.rb +1 -7
  316. data/spec/extensions/list_spec.rb +5 -6
  317. data/spec/extensions/looser_typecasting_spec.rb +1 -1
  318. data/spec/extensions/many_through_many_spec.rb +25 -33
  319. data/spec/extensions/migration_spec.rb +12 -2
  320. data/spec/extensions/modification_detection_spec.rb +1 -1
  321. data/spec/extensions/mssql_optimistic_locking_spec.rb +1 -1
  322. data/spec/extensions/named_timezones_spec.rb +3 -3
  323. data/spec/extensions/nested_attributes_spec.rb +1 -29
  324. data/spec/extensions/null_dataset_spec.rb +1 -11
  325. data/spec/extensions/optimistic_locking_spec.rb +2 -2
  326. data/spec/extensions/pagination_spec.rb +1 -1
  327. data/spec/extensions/pg_array_associations_spec.rb +22 -26
  328. data/spec/extensions/pg_array_ops_spec.rb +1 -1
  329. data/spec/extensions/pg_array_spec.rb +3 -48
  330. data/spec/extensions/pg_enum_spec.rb +1 -1
  331. data/spec/extensions/pg_extended_date_support_spec.rb +122 -0
  332. data/spec/extensions/pg_hstore_ops_spec.rb +1 -1
  333. data/spec/extensions/pg_hstore_spec.rb +22 -31
  334. data/spec/extensions/pg_inet_ops_spec.rb +1 -1
  335. data/spec/extensions/pg_inet_spec.rb +1 -14
  336. data/spec/extensions/pg_interval_spec.rb +3 -13
  337. data/spec/extensions/pg_json_ops_spec.rb +1 -1
  338. data/spec/extensions/pg_json_spec.rb +1 -13
  339. data/spec/extensions/pg_loose_count_spec.rb +1 -1
  340. data/spec/extensions/pg_range_ops_spec.rb +1 -1
  341. data/spec/extensions/pg_range_spec.rb +3 -88
  342. data/spec/extensions/pg_row_ops_spec.rb +1 -1
  343. data/spec/extensions/pg_row_plugin_spec.rb +1 -1
  344. data/spec/extensions/pg_row_spec.rb +1 -44
  345. data/spec/extensions/pg_static_cache_updater_spec.rb +1 -1
  346. data/spec/extensions/prepared_statements_safe_spec.rb +7 -7
  347. data/spec/extensions/prepared_statements_spec.rb +13 -48
  348. data/spec/extensions/pretty_table_spec.rb +40 -9
  349. data/spec/extensions/query_spec.rb +1 -12
  350. data/spec/extensions/rcte_tree_spec.rb +23 -34
  351. data/spec/extensions/round_timestamps_spec.rb +1 -5
  352. data/spec/extensions/s_spec.rb +1 -1
  353. data/spec/extensions/schema_caching_spec.rb +1 -1
  354. data/spec/extensions/schema_dumper_spec.rb +43 -32
  355. data/spec/extensions/select_remove_spec.rb +1 -1
  356. data/spec/extensions/sequel_4_dataset_methods_spec.rb +1 -1
  357. data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
  358. data/spec/extensions/serialization_spec.rb +5 -17
  359. data/spec/extensions/server_block_spec.rb +1 -1
  360. data/spec/extensions/server_logging_spec.rb +2 -2
  361. data/spec/extensions/sharding_spec.rb +1 -1
  362. data/spec/extensions/shared_caching_spec.rb +1 -28
  363. data/spec/extensions/single_table_inheritance_spec.rb +2 -5
  364. data/spec/extensions/singular_table_names_spec.rb +1 -1
  365. data/spec/extensions/skip_create_refresh_spec.rb +1 -1
  366. data/spec/extensions/spec_helper.rb +5 -27
  367. data/spec/extensions/split_array_nil_spec.rb +1 -1
  368. data/spec/extensions/split_values_spec.rb +1 -1
  369. data/spec/extensions/sql_comments_spec.rb +1 -1
  370. data/spec/extensions/sql_expr_spec.rb +1 -1
  371. data/spec/extensions/static_cache_spec.rb +1 -1
  372. data/spec/extensions/string_agg_spec.rb +2 -2
  373. data/spec/extensions/string_date_time_spec.rb +1 -1
  374. data/spec/extensions/string_stripper_spec.rb +1 -1
  375. data/spec/extensions/subclasses_spec.rb +1 -1
  376. data/spec/extensions/subset_conditions_spec.rb +1 -1
  377. data/spec/extensions/symbol_aref_refinement_spec.rb +1 -1
  378. data/spec/extensions/symbol_as_refinement_spec.rb +1 -1
  379. data/spec/extensions/synchronize_sql_spec.rb +124 -0
  380. data/spec/extensions/table_select_spec.rb +4 -4
  381. data/spec/extensions/tactical_eager_loading_spec.rb +1 -6
  382. data/spec/extensions/thread_local_timezones_spec.rb +1 -1
  383. data/spec/extensions/timestamps_spec.rb +5 -7
  384. data/spec/extensions/to_dot_spec.rb +1 -1
  385. data/spec/extensions/touch_spec.rb +1 -1
  386. data/spec/extensions/tree_spec.rb +1 -1
  387. data/spec/extensions/typecast_on_load_spec.rb +1 -1
  388. data/spec/extensions/unlimited_update_spec.rb +1 -1
  389. data/spec/extensions/update_or_create_spec.rb +12 -16
  390. data/spec/extensions/update_primary_key_spec.rb +4 -3
  391. data/spec/extensions/update_refresh_spec.rb +1 -1
  392. data/spec/extensions/uuid_spec.rb +10 -13
  393. data/spec/extensions/validate_associated_spec.rb +1 -1
  394. data/spec/extensions/validation_class_methods_spec.rb +3 -3
  395. data/spec/extensions/validation_contexts_spec.rb +1 -1
  396. data/spec/extensions/validation_helpers_spec.rb +10 -44
  397. data/spec/extensions/whitelist_security_spec.rb +5 -5
  398. data/spec/extensions/xml_serializer_spec.rb +8 -13
  399. data/spec/guards_helper.rb +2 -1
  400. data/spec/integration/associations_test.rb +1 -23
  401. data/spec/integration/database_test.rb +7 -7
  402. data/spec/integration/dataset_test.rb +12 -47
  403. data/spec/integration/eager_loader_test.rb +1 -1
  404. data/spec/integration/migrator_test.rb +1 -1
  405. data/spec/integration/model_test.rb +4 -82
  406. data/spec/integration/plugin_test.rb +7 -23
  407. data/spec/integration/prepared_statement_test.rb +8 -88
  408. data/spec/integration/schema_test.rb +10 -10
  409. data/spec/integration/spec_helper.rb +17 -21
  410. data/spec/integration/timezone_test.rb +5 -5
  411. data/spec/integration/transaction_test.rb +3 -55
  412. data/spec/integration/type_test.rb +9 -9
  413. data/spec/model/association_reflection_spec.rb +24 -9
  414. data/spec/model/associations_spec.rb +124 -303
  415. data/spec/model/base_spec.rb +43 -137
  416. data/spec/model/class_dataset_methods_spec.rb +2 -20
  417. data/spec/model/dataset_methods_spec.rb +1 -20
  418. data/spec/model/eager_loading_spec.rb +48 -17
  419. data/spec/model/hooks_spec.rb +5 -300
  420. data/spec/model/inflector_spec.rb +1 -1
  421. data/spec/model/model_spec.rb +29 -339
  422. data/spec/model/plugins_spec.rb +2 -16
  423. data/spec/model/record_spec.rb +33 -129
  424. data/spec/model/spec_helper.rb +5 -15
  425. data/spec/model/validations_spec.rb +1 -1
  426. data/spec/sequel_warning.rb +1 -12
  427. metadata +19 -65
  428. data/doc/active_record.rdoc +0 -927
  429. data/lib/sequel/adapters/cubrid.rb +0 -160
  430. data/lib/sequel/adapters/do/mysql.rb +0 -69
  431. data/lib/sequel/adapters/do/postgres.rb +0 -46
  432. data/lib/sequel/adapters/do/sqlite3.rb +0 -41
  433. data/lib/sequel/adapters/do.rb +0 -166
  434. data/lib/sequel/adapters/jdbc/as400.rb +0 -92
  435. data/lib/sequel/adapters/jdbc/cubrid.rb +0 -65
  436. data/lib/sequel/adapters/jdbc/firebirdsql.rb +0 -37
  437. data/lib/sequel/adapters/jdbc/informix-sqli.rb +0 -34
  438. data/lib/sequel/adapters/jdbc/jdbcprogress.rb +0 -34
  439. data/lib/sequel/adapters/odbc/progress.rb +0 -12
  440. data/lib/sequel/adapters/shared/cubrid.rb +0 -245
  441. data/lib/sequel/adapters/shared/firebird.rb +0 -261
  442. data/lib/sequel/adapters/shared/informix.rb +0 -63
  443. data/lib/sequel/adapters/shared/progress.rb +0 -40
  444. data/lib/sequel/adapters/swift/mysql.rb +0 -50
  445. data/lib/sequel/adapters/swift/postgres.rb +0 -49
  446. data/lib/sequel/adapters/swift/sqlite.rb +0 -48
  447. data/lib/sequel/adapters/swift.rb +0 -169
  448. data/lib/sequel/adapters/utils/pg_types.rb +0 -4
  449. data/lib/sequel/dataset/mutation.rb +0 -98
  450. data/lib/sequel/extensions/_deprecated_identifier_mangling.rb +0 -117
  451. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +0 -8
  452. data/lib/sequel/extensions/filter_having.rb +0 -65
  453. data/lib/sequel/extensions/hash_aliases.rb +0 -51
  454. data/lib/sequel/extensions/meta_def.rb +0 -37
  455. data/lib/sequel/extensions/query_literals.rb +0 -86
  456. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +0 -26
  457. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +0 -133
  458. data/lib/sequel/extensions/set_overrides.rb +0 -82
  459. data/lib/sequel/no_core_ext.rb +0 -4
  460. data/lib/sequel/plugins/association_autoreloading.rb +0 -11
  461. data/lib/sequel/plugins/identifier_columns.rb +0 -49
  462. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +0 -11
  463. data/lib/sequel/plugins/pg_typecast_on_load.rb +0 -90
  464. data/lib/sequel/plugins/prepared_statements_associations.rb +0 -137
  465. data/lib/sequel/plugins/prepared_statements_with_pk.rb +0 -71
  466. data/lib/sequel/plugins/schema.rb +0 -84
  467. data/lib/sequel/plugins/scissors.rb +0 -37
  468. data/spec/core/dataset_mutation_spec.rb +0 -253
  469. data/spec/extensions/_deprecated_identifier_mangling_spec.rb +0 -314
  470. data/spec/extensions/before_after_save_spec.rb +0 -40
  471. data/spec/extensions/filter_having_spec.rb +0 -42
  472. data/spec/extensions/from_block_spec.rb +0 -21
  473. data/spec/extensions/hash_aliases_spec.rb +0 -26
  474. data/spec/extensions/identifier_columns_spec.rb +0 -19
  475. data/spec/extensions/meta_def_spec.rb +0 -35
  476. data/spec/extensions/no_auto_literal_strings_spec.rb +0 -69
  477. data/spec/extensions/pg_typecast_on_load_spec.rb +0 -70
  478. data/spec/extensions/prepared_statements_associations_spec.rb +0 -212
  479. data/spec/extensions/prepared_statements_with_pk_spec.rb +0 -40
  480. data/spec/extensions/query_literals_spec.rb +0 -185
  481. data/spec/extensions/schema_spec.rb +0 -123
  482. data/spec/extensions/scissors_spec.rb +0 -27
  483. data/spec/extensions/sequel_3_dataset_methods_spec.rb +0 -118
  484. data/spec/extensions/set_overrides_spec.rb +0 -75
@@ -22,10 +22,6 @@ module Sequel
22
22
  # truncate, unfiltered, ungraphed, ungrouped, union, unlimited, unordered, where, where_all,
23
23
  # where_each, where_single_value, with, with_recursive, with_sql
24
24
  module ClassMethods
25
- # Which columns should be the only columns allowed in a call to a mass assignment method (e.g. set)
26
- # (default: not set, so all columns not otherwise restricted are allowed).
27
- attr_reader :allowed_columns # SEQUEL5: Deprecate after release
28
-
29
25
  # Whether to cache the anonymous models created by Sequel::Model(), true by default. This is
30
26
  # required for reloading them correctly (avoiding the superclass mismatch).
31
27
  attr_accessor :cache_anonymous_models
@@ -80,24 +76,10 @@ module Sequel
80
76
  # Sequel will not check the number of rows modified (default: true).
81
77
  attr_accessor :require_modification
82
78
 
83
- # Requires that all models have valid tables, raising exceptions if creating a model
84
- # without a valid table backing it. Enabling this will break code like:
85
- #
86
- # class Foo < Sequel::Model
87
- # set_dataset :my_foo
88
- # end
89
- #
90
- # As when Sequel::Model is subclassed, before set_dataset is executed, it will try to
91
- # get the schema for the foos table, which will raise an exception. You would need to
92
- # switch to using:
93
- #
94
- # class Foo < Sequel::Model(:my_foo)
95
- # end
96
- #
97
- # or:
98
- #
99
- # Foo = Class.new(Sequel::Model)
100
- # Foo.set_dataset :my_foo
79
+ # If true (the default), requires that all models have valid tables,
80
+ # raising exceptions if creating a model without a valid table backing it.
81
+ # Setting this to false will allow the creation of model classes where the
82
+ # underlying table doesn't exist.
101
83
  attr_accessor :require_valid_table
102
84
 
103
85
  # Should be the literal primary key column name if this Model's table has a simple primary key, or
@@ -108,7 +90,7 @@ module Sequel
108
90
  # or nil otherwise. This and simple_pk are used for an optimization in Model.[].
109
91
  attr_reader :simple_table
110
92
 
111
- # Whether new/set/update and their variants should raise an error
93
+ # Whether mass assigning via .create/.new/#set/#update should raise an error
112
94
  # if an invalid key is used. A key is invalid if no setter method exists
113
95
  # for that key or the access to the setter method is restricted (e.g. due to it
114
96
  # being a primary key field). If set to false, silently skip
@@ -127,11 +109,6 @@ module Sequel
127
109
  # database to typecast the value correctly.
128
110
  attr_accessor :typecast_on_assignment
129
111
 
130
- # Whether to enable the after_commit and after_rollback hooks when saving/destroying
131
- # instances. On by default, can be turned off for performance reasons or when using
132
- # prepared transactions (which aren't compatible with after commit/rollback).
133
- attr_accessor :use_after_commit_rollback # SEQUEL5: Deprecate after release
134
-
135
112
  # Whether to use a transaction by default when saving/deleting records (default: true).
136
113
  # If you are sending database queries in before_* or after_* hooks, you shouldn't change
137
114
  # the default setting without a good reason.
@@ -159,7 +136,7 @@ module Sequel
159
136
  # end
160
137
  def def_Model(mod)
161
138
  model = self
162
- (class << mod; self; end).send(:define_method, :Model) do |source|
139
+ mod.define_singleton_method(:Model) do |source|
163
140
  model.Model(source)
164
141
  end
165
142
  end
@@ -179,11 +156,8 @@ module Sequel
179
156
  # classes in order to create the dataset.
180
157
  #
181
158
  # The purpose of this method is to set the dataset/database automatically
182
- # for a model class, if the table name doesn't match the implicit
183
- # name. This is neater than using set_dataset inside the class,
184
- # doesn't require a bogus query for the schema, and works when using
185
- # +require_valid_table+, or with plugins that assume a model's dataset
186
- # is valid.
159
+ # for a model class, if the table name doesn't match the default table
160
+ # name that Sequel would use.
187
161
  #
188
162
  # When creating subclasses of Sequel::Model itself, this method is usually
189
163
  # called on Sequel itself, using <tt>Sequel::Model(:something)</tt>.
@@ -225,22 +199,6 @@ module Sequel
225
199
  klass
226
200
  end
227
201
 
228
- def initialize_copy(_)
229
- Sequel::Deprecation.deprecate("Model.clone", "Create a subclass of the model instead of cloning it")
230
- # raise(Error, "cannot dup/clone a Sequel::Model class") # SEQUEL5
231
- super
232
- end
233
- def dup
234
- Sequel::Deprecation.deprecate("Model.dup", "Create a subclass of the model instead of duping it")
235
- # raise(Error, "cannot dup/clone a Sequel::Model class") # SEQUEL5
236
- super
237
- end
238
-
239
- def <<(arg)
240
- Sequel::Deprecation.deprecate("Sequel::Model.<<", "Switch to using #insert")
241
- dataset << (arg)
242
- end
243
-
244
202
  # Returns the first record from the database matching the conditions.
245
203
  # If a hash is given, it is used as the conditions. If another
246
204
  # object is given, it finds the first record whose primary key(s) match
@@ -249,7 +207,7 @@ module Sequel
249
207
  # Artist[1] # SELECT * FROM artists WHERE id = 1
250
208
  # # => #<Artist {:id=>1, ...}>
251
209
  #
252
- # Artist[:name=>'Bob'] # SELECT * FROM artists WHERE (name = 'Bob') LIMIT 1
210
+ # Artist[name: 'Bob'] # SELECT * FROM artists WHERE (name = 'Bob') LIMIT 1
253
211
  # # => #<Artist {:name=>'Bob', ...}>
254
212
  def [](*args)
255
213
  args = args.first if args.size <= 1
@@ -286,7 +244,7 @@ module Sequel
286
244
 
287
245
  # Creates instance using new with the given values and block, and saves it.
288
246
  #
289
- # Artist.create(:name=>'Bob')
247
+ # Artist.create(name: 'Bob')
290
248
  # # INSERT INTO artists (name) VALUES ('Bob')
291
249
  #
292
250
  # Artist.create do |a|
@@ -315,7 +273,7 @@ module Sequel
315
273
  # a plugin with the methods defined in DatasetMethods.
316
274
  # This is the recommended way to add methods to model datasets.
317
275
  #
318
- # If an argument, it should be a module, and is used to extend
276
+ # If given an argument, it should be a module, and is used to extend
319
277
  # the underlying dataset. Otherwise an anonymous module is created, and
320
278
  # if a block is given, it is module_evaled, allowing you do define
321
279
  # dataset methods directly using the standard ruby def syntax.
@@ -342,7 +300,7 @@ module Sequel
342
300
  # named dataset methods:
343
301
  #
344
302
  # Album.dataset_module do
345
- # subset :released, Sequel.identifier(release_date) <= Sequel::CURRENT_DATE
303
+ # where(:released, Sequel[:release_date] <= Sequel::CURRENT_DATE)
346
304
  # order :by_release_date, :release_date
347
305
  # select :for_select_options, :id, :name, :release_date
348
306
  # end
@@ -359,6 +317,10 @@ module Sequel
359
317
  # group_append, having, limit, offset, order, order_append, order_prepend, select, select_all,
360
318
  # select_append, select_group, where, and server.
361
319
  #
320
+ # The advantage of using these DatasetModule methods to define your dataset
321
+ # methods is that they can take advantage of dataset caching to improve
322
+ # performance.
323
+ #
362
324
  # Any public methods in the dataset module will have class methods created that
363
325
  # call the method on the dataset, assuming that the class method is not already
364
326
  # defined.
@@ -382,7 +344,7 @@ module Sequel
382
344
  # been created, raises an error.
383
345
  #
384
346
  # Artist.db.transaction do # BEGIN
385
- # Artist.create(:name=>'Bob')
347
+ # Artist.create(name: 'Bob')
386
348
  # # INSERT INTO artists (name) VALUES ('Bob')
387
349
  # end # COMMIT
388
350
  def db
@@ -392,26 +354,23 @@ module Sequel
392
354
  @db
393
355
  end
394
356
 
395
- # Sets the database associated with the Model class. If the
396
- # model has an associated dataset, sets the model's dataset
397
- # to a dataset on the new database with the same options
398
- # used by the current dataset. This can be used directly on
399
- # Sequel::Model to set the default database to be used
400
- # by subclasses, or to override the database used for specific
401
- # models:
357
+ # Sets the database associated with the Model class.
358
+ # Should only be used if the Model class currently does not
359
+ # have a dataset defined.
360
+ #
361
+ # This can be used directly on Sequel::Model to set the default database to be used
362
+ # by subclasses, or to override the database used for specific models:
402
363
  #
403
364
  # Sequel::Model.db = DB1
365
+ # Artist = Class.new(Sequel::Model)
404
366
  # Artist.db = DB2
405
367
  #
406
368
  # Note that you should not use this to change the model's database
407
369
  # at runtime. If you have that need, you should look into Sequel's
408
- # sharding support.
370
+ # sharding support, or consider using separate model classes per Database.
409
371
  def db=(db)
372
+ raise Error, "Cannot use Sequel::Model.db= on model with existing dataset. Use Sequel::Model.dataset= instead." if @dataset
410
373
  @db = db
411
- if @dataset
412
- Sequel::Deprecation.deprecate("Sequel::Model.db= when the model has an existing dataset", "Use Sequel::Model.dataset= instead")
413
- set_dataset(db.dataset.clone(@dataset.opts))
414
- end
415
374
  end
416
375
 
417
376
  # Returns the cached schema information if available or gets it
@@ -438,44 +397,10 @@ module Sequel
438
397
  end
439
398
  end
440
399
 
441
- # If a block is given, define a method on the dataset (if the model currently has an dataset) with the given argument name using
442
- # the given block. Also define a class method on the model that calls the
443
- # dataset method. Stores the method name and block so that it can be reapplied if the model's
444
- # dataset changes.
445
- #
446
- # If a block is not given, just define a class method on the model for each argument
447
- # that calls the dataset method of the same argument name.
448
- #
449
- # Using dataset_module is recommended over using this method. In addition to allowing
450
- # more natural ruby syntax for defining methods manually, it also offers numerous
451
- # helper methods that make defining common dataset methods more easily, as well as
452
- # supporting dataset caching (assuming the arguments allow it).
453
- #
454
- # # Add new dataset method and class method that calls it
455
- # Artist.def_dataset_method(:by_name){order(:name)}
456
- # Artist.where(:name.like('A%')).by_name
457
- # Artist.by_name.where(:name.like('A%'))
458
- #
459
- # # Just add a class method that calls an existing dataset method
460
- # Artist.def_dataset_method(:paginate)
461
- # Artist.paginate(2, 10)
462
- def def_dataset_method(*args, &block)
463
- raise(Error, "No arguments given") if args.empty?
464
-
465
- if block
466
- raise(Error, "Defining a dataset method using a block requires only one argument") if args.length > 1
467
- Sequel::Deprecation.deprecate("Sequel::Model.def_dataset_method", "Define the method inside a dataset_module block, or use the def_dataset_method_plugin")
468
- dataset_module{define_method(args.first, &block)}
469
- else
470
- Sequel::Deprecation.deprecate("Sequel::Model.def_dataset_method", "Define a class method that calls the dataset method, or use the def_dataset_method_plugin")
471
- args.each{|arg| def_model_dataset_method(arg)}
472
- end
473
- end
474
-
475
400
  # Finds a single record according to the supplied filter.
476
401
  # You are encouraged to use Model.[] or Model.first instead of this method.
477
402
  #
478
- # Artist.find(:name=>'Bob')
403
+ # Artist.find(name: 'Bob')
479
404
  # # SELECT * FROM artists WHERE (name = 'Bob') LIMIT 1
480
405
  #
481
406
  # Artist.find{name > 'M'}
@@ -489,171 +414,34 @@ module Sequel
489
414
  # to +find+, but instead is passed to +create+ only if +find+ does not
490
415
  # return an object.
491
416
  #
492
- # Artist.find_or_create(:name=>'Bob')
417
+ # Artist.find_or_create(name: 'Bob')
493
418
  # # SELECT * FROM artists WHERE (name = 'Bob') LIMIT 1
494
419
  # # INSERT INTO artists (name) VALUES ('Bob')
495
420
  #
496
- # Artist.find_or_create(:name=>'Jim'){|a| a.hometown = 'Sactown'}
421
+ # Artist.find_or_create(name: 'Jim'){|a| a.hometown = 'Sactown'}
497
422
  # # SELECT * FROM artists WHERE (name = 'Jim') LIMIT 1
498
423
  # # INSERT INTO artists (name, hometown) VALUES ('Jim', 'Sactown')
499
424
  def find_or_create(cond, &block)
500
425
  find(cond) || create(cond, &block)
501
426
  end
502
427
 
503
- FINDER_TYPES = [:first, :all, :each, :get].freeze
504
-
505
- # Create an optimized finder method using a dataset placeholder literalizer.
506
- # This pre-computes the SQL to use for the query, except for given arguments.
507
- #
508
- # There are two ways to use this. The recommended way is to pass a symbol
509
- # that represents a model class method that returns a dataset:
510
- #
511
- # def Artist.by_name(name)
512
- # where(:name=>name)
513
- # end
514
- #
515
- # Artist.finder :by_name
516
- #
517
- # This creates an optimized first_by_name method, which you can call normally:
518
- #
519
- # Artist.first_by_name("Joe")
520
- #
521
- # The alternative way to use this to pass your own block:
522
- #
523
- # Artist.finder(:name=>:first_by_name){|pl, ds| ds.where(:name=>pl.arg).limit(1)}
524
- #
525
- # Note that if you pass your own block, you are responsible for manually setting
526
- # limits if necessary (as shown above).
527
- #
528
- # Options:
529
- # :arity :: When using a symbol method name, this specifies the arity of the method.
530
- # This should be used if if the method accepts an arbitrary number of arguments,
531
- # or the method has default argument values. Note that if the method is defined
532
- # as a dataset method, the class method Sequel creates accepts an arbitrary number
533
- # of arguments, so you should use this option in that case. If you want to handle
534
- # multiple possible arities, you need to call the finder method multiple times with
535
- # unique :arity and :name methods each time.
536
- # :name :: The name of the method to create. This must be given if you pass a block.
537
- # If you use a symbol, this defaults to the symbol prefixed by the type.
538
- # :mod :: The module in which to create the finder method. Defaults to the singleton
539
- # class of the model.
540
- # :type :: The type of query to run. Can be :first, :each, :all, or :get, defaults to
541
- # :first.
542
- #
543
- # Caveats:
544
- #
545
- # This doesn't handle all possible cases. For example, if you have a method such as:
546
- #
547
- # def Artist.by_name(name)
548
- # name ? where(:name=>name) : exclude(:name=>nil)
549
- # end
550
- #
551
- # Then calling a finder without an argument will not work as you expect.
552
- #
553
- # Artist.finder :by_name
554
- # Artist.by_name(nil).first
555
- # # WHERE (name IS NOT NULL)
556
- # Artist.first_by_name(nil)
557
- # # WHERE (name IS NULL)
558
- #
559
- # See Dataset::PlaceholderLiteralizer for additional caveats.
560
- def finder(meth=OPTS, opts=OPTS, &block)
561
- Sequel::Deprecation.deprecate("Sequel::Model.finder and Sequel::Model.prepared_finder", "They have been moved to the finder plugin")
562
- if block
563
- raise Error, "cannot pass both a method name argument and a block of Model.finder" unless meth.is_a?(Hash)
564
- raise Error, "cannot pass two option hashes to Model.finder" unless opts.equal?(OPTS)
565
- opts = meth
566
- raise Error, "must provide method name via :name option when passing block to Model.finder" unless meth_name = opts[:name]
567
- end
568
-
569
- type = opts.fetch(:type, :first)
570
- unless prepare = opts[:prepare]
571
- raise Error, ":type option to Model.finder must be :first, :all, :each, or :get" unless FINDER_TYPES.include?(type)
572
- end
573
- limit1 = type == :first || type == :get
574
- meth_name ||= opts[:name] || :"#{type}_#{meth}"
575
-
576
- argn = lambda do |model|
577
- if arity = opts[:arity]
578
- arity
579
- else
580
- method = block || model.method(meth)
581
- (method.arity < 0 ? method.arity.abs - 1 : method.arity)
582
- end
583
- end
584
-
585
- loader_proc = if prepare
586
- proc do |model|
587
- args = prepare_method_args('$a', argn.call(model))
588
- ds = if block
589
- model.instance_exec(*args, &block)
590
- else
591
- model.send(meth, *args)
592
- end
593
- ds = ds.limit(1) if limit1
594
- model_name = model.name
595
- if model_name.to_s.empty?
596
- model_name = model.object_id
597
- else
598
- model_name = model_name.gsub(/\W/, '_')
599
- end
600
- ds.prepare(type, :"#{model_name}_#{meth_name}")
601
- end
602
- else
603
- proc do |model|
604
- n = argn.call(model)
605
- block ||= lambda do |pl, model2|
606
- args = (0...n).map{pl.arg}
607
- ds = model2.send(meth, *args)
608
- ds = ds.limit(1) if limit1
609
- ds
610
- end
611
-
612
- Sequel::Dataset::PlaceholderLiteralizer.loader(model, &block)
613
- end
614
- end
615
-
616
- @finder_loaders[meth_name] = loader_proc
617
- mod = opts[:mod] || (class << self; self; end)
618
- if prepare
619
- def_prepare_method(mod, meth_name)
620
- else
621
- def_finder_method(mod, meth_name, type)
622
- end
623
- end
624
-
625
- def first_where(cond)
626
- Sequel::Deprecation.deprecate("Sequel::Model.first_where", "Instead, use Sequel::Model.first")
627
- if cond.is_a?(Integer)
628
- dataset.where(cond).first(cond)
629
- else
630
- dataset.first(cond)
631
- end
632
- end
633
-
634
428
  # Freeze a model class, disallowing any further changes to it.
635
429
  def freeze
430
+ return self if frozen?
636
431
  dataset_module.freeze
637
432
  overridable_methods_module.freeze
638
433
 
639
- @finder_loaders.freeze # SEQUEL5: Remove
640
-
641
434
  if @dataset
642
- @dataset.freeze
643
- @instance_dataset.freeze
644
435
  db_schema.freeze.each_value(&:freeze)
645
436
  columns.freeze
646
437
  setter_methods.freeze
647
- @finder_loaders.each_key{|k| finder_for(k)} # SEQUEL5: Remove
648
438
  else
649
439
  @setter_methods = [].freeze
650
440
  end
651
441
 
652
442
  @dataset_method_modules.freeze
653
443
  @default_set_fields_options.freeze
654
- @finders.freeze # SEQUEL5: Remove
655
444
  @plugins.freeze
656
- @allowed_columns.freeze if @allowed_columns # SEQUEL5: Remove
657
445
 
658
446
  super
659
447
  end
@@ -676,9 +464,9 @@ module Sequel
676
464
  # end
677
465
  def inherited(subclass)
678
466
  super
679
- ivs = subclass.instance_variables.map(&:to_s)
467
+ ivs = subclass.instance_variables
680
468
  inherited_instance_variables.each do |iv, dup|
681
- next if ivs.include?(iv.to_s)
469
+ next if ivs.include?(iv)
682
470
  if (sup_class_value = instance_variable_get(iv)) && dup
683
471
  sup_class_value = case dup
684
472
  when :dup
@@ -696,7 +484,7 @@ module Sequel
696
484
  subclass.instance_variable_set(iv, sup_class_value)
697
485
  end
698
486
 
699
- unless ivs.include?("@dataset")
487
+ unless ivs.include?(:@dataset)
700
488
  if @dataset && self != Model
701
489
  subclass.set_dataset(@dataset.clone, :inherited=>true)
702
490
  elsif (n = subclass.name) && !n.to_s.empty?
@@ -720,7 +508,7 @@ module Sequel
720
508
  call(values)
721
509
  end
722
510
 
723
- # Clear the setter_methods cache when a setter method is added
511
+ # Clear the setter_methods cache when a setter method is added.
724
512
  def method_added(meth)
725
513
  clear_setter_methods_cache if meth.to_s.end_with?('=')
726
514
  super
@@ -739,17 +527,16 @@ module Sequel
739
527
 
740
528
  # Loads a plugin for use with the model class, passing optional arguments
741
529
  # to the plugin. If the plugin is a module, load it directly. Otherwise,
742
- # require the plugin from either sequel/plugins/#{plugin} or
743
- # sequel_#{plugin}, and then attempt to load the module using a
744
- # the camelized plugin name under Sequel::Plugins.
530
+ # require the plugin from sequel/plugins/#{plugin} and then attempt to load
531
+ # the module using a the camelized plugin name under Sequel::Plugins.
745
532
  def plugin(plugin, *args, &block)
746
533
  m = plugin.is_a?(Module) ? plugin : plugin_module(plugin)
747
534
  unless @plugins.include?(m)
748
535
  @plugins << m
749
536
  m.apply(self, *args, &block) if m.respond_to?(:apply)
750
- extend(m::ClassMethods) if plugin_module_defined?(m, :ClassMethods)
751
- include(m::InstanceMethods) if plugin_module_defined?(m, :InstanceMethods)
752
- if plugin_module_defined?(m, :DatasetMethods)
537
+ extend(m::ClassMethods) if m.const_defined?(:ClassMethods, false)
538
+ include(m::InstanceMethods) if m.const_defined?(:InstanceMethods, false)
539
+ if m.const_defined?(:DatasetMethods, false)
753
540
  dataset_extend(m::DatasetMethods, :create_class_methods=>false)
754
541
  end
755
542
  end
@@ -797,28 +584,6 @@ module Sequel
797
584
  end
798
585
  end
799
586
 
800
- # Similar to finder, but uses a prepared statement instead of a placeholder
801
- # literalizer. This makes the SQL used static (cannot vary per call), but
802
- # allows binding argument values instead of literalizing them into the SQL
803
- # query string.
804
- #
805
- # If a block is used with this method, it is instance_execed by the model,
806
- # and should accept the desired number of placeholder arguments.
807
- #
808
- # The options are the same as the options for finder, with the following
809
- # exception:
810
- # :type :: Specifies the type of prepared statement to create
811
- def prepared_finder(meth=OPTS, opts=OPTS, &block)
812
- # SEQUEL5: Remove
813
- if block
814
- raise Error, "cannot pass both a method name argument and a block of Model.finder" unless meth.is_a?(Hash)
815
- meth = meth.merge(:prepare=>true)
816
- else
817
- opts = opts.merge(:prepare=>true)
818
- end
819
- finder(meth, opts, &block)
820
- end
821
-
822
587
  # Restrict the setting of the primary key(s) when using mass assignment (e.g. +set+). Because
823
588
  # this is the default, this only make sense to use in a subclass where the
824
589
  # parent class has used +unrestrict_primary_key+.
@@ -833,23 +598,6 @@ module Sequel
833
598
  @restrict_primary_key
834
599
  end
835
600
 
836
- # Set the columns to allow when using mass assignment (e.g. +set+). Using this means that
837
- # any columns not listed here will not be modified. If you have any virtual
838
- # setter methods (methods that end in =) that you want to be used during
839
- # mass assignment, they need to be listed here as well (without the =).
840
- #
841
- # It may be better to use a method such as +set_only+ or +set_fields+ that lets you specify
842
- # the allowed fields per call.
843
- #
844
- # Artist.set_allowed_columns(:name, :hometown)
845
- # Artist.set(:name=>'Bob', :hometown=>'Sactown') # No Error
846
- # Artist.set(:name=>'Bob', :records_sold=>30000) # Error
847
- def set_allowed_columns(*cols)
848
- Sequel::Deprecation.deprecate("Sequel::Model.set_allowed_columns", "Load the whitelist_security plugin into the model class")
849
- clear_setter_methods_cache
850
- @allowed_columns = cols
851
- end
852
-
853
601
  # Sets the dataset associated with the Model class. +ds+ can be a +Symbol+,
854
602
  # +LiteralString+, <tt>SQL::Identifier</tt>, <tt>SQL::QualifiedIdentifier</tt>,
855
603
  # <tt>SQL::AliasedExpression</tt>
@@ -864,26 +612,22 @@ module Sequel
864
612
  #
865
613
  # Note that you should not use this to change the model's dataset
866
614
  # at runtime. If you have that need, you should look into Sequel's
867
- # sharding support.
868
- #
869
- # You should avoid calling this method directly. Instead of doing:
870
- #
871
- # class Artist < Sequel::Model
872
- # set_dataset :tbl_artists
873
- # end
615
+ # sharding support, or creating a separate Model class per dataset
874
616
  #
875
- # You should use:
617
+ # You should avoid calling this method directly if possible. Instead you should
618
+ # set the table name or dataset when creating the model class:
876
619
  #
620
+ # # table name
877
621
  # class Artist < Sequel::Model(:tbl_artists)
878
622
  # end
879
623
  #
880
- # This ensures the class never uses an invalid dataset. Calling +set_dataset+
881
- # after creating a class can create a class with initial invalid dataset, which
882
- # will break when +require_valid_table+ or certain plugins are used.
624
+ # # dataset
625
+ # class Artist < Sequel::Model(DB[:tbl_artists])
626
+ # end
883
627
  def set_dataset(ds, opts=OPTS)
884
628
  inherited = opts[:inherited]
885
629
  @dataset = convert_input_dataset(ds)
886
- @require_modification = Sequel::Model.require_modification.nil? ? @dataset.provides_accurate_rows_matched? : Sequel::Model.require_modification
630
+ @require_modification = @dataset.provides_accurate_rows_matched? if require_modification.nil?
887
631
  if inherited
888
632
  self.simple_table = superclass.simple_table
889
633
  @columns = superclass.instance_variable_get(:@columns)
@@ -899,7 +643,7 @@ module Sequel
899
643
 
900
644
  # Sets the primary key for this model. You can use either a regular
901
645
  # or a composite primary key. To not use a primary key, set to nil
902
- # or use +no_primary_key+. On most adapters, Sequel can automatically
646
+ # or use +no_primary_key+. On most adapters, Sequel can automatically
903
647
  # determine the primary key to use, so this method is not needed often.
904
648
  #
905
649
  # class Person < Sequel::Model
@@ -926,39 +670,12 @@ module Sequel
926
670
  @primary_key = key
927
671
  end
928
672
 
929
- # Cache of setter methods to allow by default, in order to speed up new/set/update instance methods.
673
+ # Cache of setter methods to allow by default, in order to speed up mass assignment.
930
674
  def setter_methods
931
675
  return @setter_methods if @setter_methods
932
676
  @setter_methods = get_setter_methods
933
677
  end
934
678
 
935
- # Sets up a dataset method that returns a filtered dataset.
936
- # Sometimes thought of as a scope, and like most dataset methods,
937
- # they can be chained.
938
- # For example:
939
- #
940
- # Topic.subset(:joes, :username.like('%joe%'))
941
- # Topic.subset(:popular){num_posts > 100}
942
- # Topic.subset(:recent){created_on > Date.today - 7}
943
- #
944
- # Allows you to do:
945
- #
946
- # Topic.joes.recent.popular
947
- #
948
- # to get topics with a username that includes joe that
949
- # have more than 100 posts and were created less than
950
- # 7 days ago.
951
- #
952
- # Both the args given and the block are passed to <tt>Dataset#filter</tt>.
953
- #
954
- # This method creates dataset methods that do not accept arguments. To create
955
- # dataset methods that accept arguments, you should use define a
956
- # method directly inside a #dataset_module block.
957
- def subset(*args, &block)
958
- Sequel::Deprecation.deprecate("Sequel::Model.subset", "Use the subset method inside a dataset_module block, or use the def_dataset_method plugin")
959
- dataset_module{where(*args, &block)}
960
- end
961
-
962
679
  # Returns name of primary table for the dataset. If the table for the dataset
963
680
  # is aliased, returns the aliased name.
964
681
  #
@@ -972,9 +689,9 @@ module Sequel
972
689
  # Allow the setting of the primary key(s) when using the mass assignment methods.
973
690
  # Using this method can open up security issues, be very careful before using it.
974
691
  #
975
- # Artist.set(:id=>1) # Error
692
+ # Artist.set(id: 1) # Error
976
693
  # Artist.unrestrict_primary_key
977
- # Artist.set(:id=>1) # No Error
694
+ # Artist.set(id: 1) # No Error
978
695
  def unrestrict_primary_key
979
696
  clear_setter_methods_cache
980
697
  @restrict_primary_key = false
@@ -991,26 +708,18 @@ module Sequel
991
708
  end
992
709
 
993
710
  # Add model methods that call dataset methods
994
- Plugins.def_dataset_methods(self, (Dataset::ACTION_METHODS + Dataset::QUERY_METHODS + [:each_server]) - [:<<, :and, :or, :[], :columns, :columns!, :delete, :update, :add_graph_aliases])
995
- # SEQUEL5: add :set_graph_aliases to remove list and remove :and
711
+ Plugins.def_dataset_methods(self, (Dataset::ACTION_METHODS + Dataset::QUERY_METHODS + [:each_server]) - [:<<, :or, :[], :columns, :columns!, :delete, :update, :set_graph_aliases, :add_graph_aliases])
996
712
 
997
713
  private
998
714
 
999
- # Yield to the passed block and swallow all errors other than DatabaseConnectionErrors.
715
+ # Yield to the passed block and if do_raise is false, swallow all errors other than DatabaseConnectionErrors.
1000
716
  def check_non_connection_error(do_raise=require_valid_table)
1001
717
  begin
1002
718
  db.transaction(:savepoint=>:only){yield}
1003
719
  rescue Sequel::DatabaseConnectionError
1004
720
  raise
1005
721
  rescue Sequel::Error
1006
- case do_raise
1007
- when nil
1008
- Sequel::Deprecation.deprecate("Setting a model class dataset to an invalid dataset", "Either use a valid dataset or set require_valid_table = false for the model class")
1009
- when false
1010
- # nothing
1011
- else
1012
- raise
1013
- end
722
+ raise if do_raise
1014
723
  end
1015
724
  end
1016
725
 
@@ -1022,10 +731,7 @@ module Sequel
1022
731
  self.simple_table = db.literal(ds).freeze
1023
732
  ds = db.from(ds)
1024
733
  when Dataset
1025
- if ds.joined_dataset?
1026
- # raise Error, "Using a joined dataset as a model dataset is not support, use from_self on the dataset to wrap it in a subquery" # SEQUEL5
1027
- Sequel::Deprecation.deprecate("Using a joined dataset as a Sequel::Model dataset", respond_to?(:cti_base_model) ? "Use the class_table_inheritance plugin :alias option in #{cti_base_model.inspect}" : "Call from_self on the dataset to wrap it in a subquery")
1028
- end
734
+ ds = ds.from_self(:alias=>ds.first_source) if ds.joined_dataset?
1029
735
 
1030
736
  self.simple_table = if ds.send(:simple_select_all?)
1031
737
  ds.literal(ds.first_source_table).freeze
@@ -1064,16 +770,16 @@ module Sequel
1064
770
  clear_setter_methods_cache
1065
771
  columns, bad_columns = columns.partition{|x| /\A[A-Za-z_][A-Za-z0-9_]*\z/.match(x.to_s)}
1066
772
  bad_columns.each{|x| def_bad_column_accessor(x)}
1067
- im = instance_methods.map(&:to_s)
773
+ im = instance_methods
1068
774
  columns.each do |column|
1069
775
  meth = "#{column}="
1070
- overridable_methods_module.module_eval("def #{column}; self[:#{column}] end", __FILE__, __LINE__) unless im.include?(column.to_s)
776
+ overridable_methods_module.module_eval("def #{column}; self[:#{column}] end", __FILE__, __LINE__) unless im.include?(column)
1071
777
  overridable_methods_module.module_eval("def #{meth}(v); self[:#{column}] = v end", __FILE__, __LINE__) unless im.include?(meth)
1072
778
  end
1073
779
  end
1074
780
 
1075
781
  # Define a model method that calls the dataset method with the same name,
1076
- # only used for methods with names that can't be presented directly in
782
+ # only used for methods with names that can't be represented directly in
1077
783
  # ruby code.
1078
784
  def def_model_dataset_method(meth)
1079
785
  return if respond_to?(meth, true)
@@ -1081,35 +787,8 @@ module Sequel
1081
787
  if meth.to_s =~ /\A[A-Za-z_][A-Za-z0-9_]*\z/
1082
788
  instance_eval("def #{meth}(*args, &block); dataset.#{meth}(*args, &block) end", __FILE__, __LINE__)
1083
789
  else
1084
- (class << self; self; end).send(:define_method, meth){|*args, &block| dataset.send(meth, *args, &block)}
1085
- end
1086
- end
1087
-
1088
- # Define a finder method in the given module with the given method name that
1089
- # load rows using the finder with the given name.
1090
- def def_finder_method(mod, meth, type)
1091
- # SEQUEL5: Remove
1092
- mod.send(:define_method, meth){|*args, &block| finder_for(meth).send(type, *args, &block)}
1093
- end
1094
-
1095
- # Define a prepared_finder method in the given module that will call the associated prepared
1096
- # statement.
1097
- def def_prepare_method(mod, meth)
1098
- # SEQUEL5: Remove
1099
- mod.send(:define_method, meth){|*args, &block| finder_for(meth).call(prepare_method_arg_hash(args), &block)}
1100
- end
1101
-
1102
- # Find the finder to use for the give method. If a finder has not been loaded
1103
- # for the method, load the finder and set correctly in the finders hash, then
1104
- # return the finder.
1105
- def finder_for(meth)
1106
- # SEQUEL5: Remove
1107
- unless finder = (frozen? ? @finders[meth] : Sequel.synchronize{@finders[meth]})
1108
- finder_loader = @finder_loaders.fetch(meth)
1109
- finder = finder_loader.call(self)
1110
- Sequel.synchronize{@finders[meth] = finder}
790
+ define_singleton_method(meth){|*args, &block| dataset.public_send(meth, *args, &block)}
1111
791
  end
1112
- finder
1113
792
  end
1114
793
 
1115
794
  # Get the schema from the database, fall back on checking the columns
@@ -1161,14 +840,9 @@ module Sequel
1161
840
  # Uncached version of setter_methods, to be overridden by plugins
1162
841
  # that want to modify the methods used.
1163
842
  def get_setter_methods
1164
- if allowed_columns
1165
- # SEQUEL5: Remove allowed_columns handling
1166
- allowed_columns.map{|x| "#{x}="}
1167
- else
1168
- meths = instance_methods.map(&:to_s).select{|l| l.end_with?('=')} - RESTRICTED_SETTER_METHODS
1169
- meths -= Array(primary_key).map{|x| "#{x}="} if primary_key && restrict_primary_key?
1170
- meths
1171
- end
843
+ meths = instance_methods.map(&:to_s).select{|l| l.end_with?('=')} - RESTRICTED_SETTER_METHODS
844
+ meths -= Array(primary_key).map{|x| "#{x}="} if primary_key && restrict_primary_key?
845
+ meths
1172
846
  end
1173
847
 
1174
848
  # A hash of instance variables to automatically set up in subclasses.
@@ -1179,7 +853,6 @@ module Sequel
1179
853
  # Proc :: Call with subclass to do the assignment
1180
854
  def inherited_instance_variables
1181
855
  {
1182
- :@allowed_columns=>:dup, # SEQUEL5: Remove
1183
856
  :@cache_anonymous_models=>nil,
1184
857
  :@dataset_method_modules=>:dup,
1185
858
  :@dataset_module_class=>nil,
@@ -1187,8 +860,6 @@ module Sequel
1187
860
  :@default_set_fields_options=>:dup,
1188
861
  :@fast_instance_delete_sql=>nil,
1189
862
  :@fast_pk_lookup_sql=>nil,
1190
- :@finder_loaders=>:dup, # SEQUEL5: Remove
1191
- :@finders=>:dup, # SEQUEL5: Remove
1192
863
  :@plugins=>:dup,
1193
864
  :@primary_key=>nil,
1194
865
  :@raise_on_save_failure=>nil,
@@ -1202,7 +873,6 @@ module Sequel
1202
873
  :@strict_param_setting=>nil,
1203
874
  :@typecast_empty_string_to_nil=>nil,
1204
875
  :@typecast_on_assignment=>nil,
1205
- :@use_after_commit_rollback=>nil,
1206
876
  :@use_transactions=>nil
1207
877
  }
1208
878
  end
@@ -1240,54 +910,12 @@ module Sequel
1240
910
  # defined, the corresponding plugin required.
1241
911
  def plugin_module(plugin)
1242
912
  module_name = plugin.to_s.gsub(/(^|_)(.)/){|x| x[-1..-1].upcase}
1243
- if !Sequel::Plugins.const_defined?(module_name) ||
1244
- (Sequel.const_defined?(module_name) &&
1245
- Sequel::Plugins.const_get(module_name) == Sequel.const_get(module_name))
1246
- begin
1247
- require "sequel/plugins/#{plugin}"
1248
- rescue LoadError => e
1249
- begin
1250
- require "sequel_#{plugin}"
1251
- Sequel::Deprecation.deprecate("requiring 'sequel_#{plugin}' to load a plugin", "Update the #{plugin} plugin to be required via 'sequel/plugins/#{plugin}'")
1252
- rescue LoadError => e2
1253
- e.message << "; #{e2.message}"
1254
- raise e
1255
- end
1256
- end
913
+ unless Sequel::Plugins.const_defined?(module_name, false)
914
+ require "sequel/plugins/#{plugin}"
1257
915
  end
1258
916
  Sequel::Plugins.const_get(module_name)
1259
917
  end
1260
918
 
1261
- # Check if the plugin module +plugin+ defines the constant named by +submod+.
1262
- def plugin_module_defined?(plugin, submod)
1263
- if RUBY_VERSION >= '1.9'
1264
- plugin.const_defined?(submod, false)
1265
- else
1266
- # :nocov:
1267
- plugin.const_defined?(submod)
1268
- # :nocov:
1269
- end
1270
- end
1271
-
1272
- # An hash of prepared argument values for the given arguments, with keys
1273
- # starting at a. Used by the methods created by prepared_finder.
1274
- def prepare_method_arg_hash(args)
1275
- # SEQUEL5: Remove
1276
- h = {}
1277
- prepare_method_args('a', args.length).zip(args).each{|k, v| h[k] = v}
1278
- h
1279
- end
1280
-
1281
- # An array of prepared statement argument names, of length n and starting with base.
1282
- def prepare_method_args(base, n)
1283
- # SEQUEL5: Remove
1284
- (0...n).map do
1285
- s = base.to_sym
1286
- base = base.next
1287
- s
1288
- end
1289
- end
1290
-
1291
919
  # Find the row in the dataset that matches the primary key. Uses
1292
920
  # a static SQL optimization if the table and primary key are simple.
1293
921
  #
@@ -1301,9 +929,6 @@ module Sequel
1301
929
  ds.literal_append(sql, pk)
1302
930
  ds.fetch_rows(sql){|r| return ds.row_proc.call(r)}
1303
931
  nil
1304
- elsif dataset.joined_dataset?
1305
- # SEQUEL5: Remove as joined model datasets are not allowed
1306
- dataset.first(qualified_primary_key_hash(pk))
1307
932
  else
1308
933
  dataset.first(primary_key_hash(pk))
1309
934
  end
@@ -1318,17 +943,16 @@ module Sequel
1318
943
  # are used, or set it to nil if not used.
1319
944
  def reset_fast_pk_lookup_sql
1320
945
  @fast_pk_lookup_sql = if @simple_table && @simple_pk
1321
- "SELECT * FROM #@simple_table WHERE #@simple_pk = ".freeze
946
+ "SELECT * FROM #{@simple_table} WHERE #{@simple_pk} = ".freeze
1322
947
  end
1323
948
  @fast_instance_delete_sql = if @simple_table && @simple_pk
1324
- "DELETE FROM #@simple_table WHERE #@simple_pk = ".freeze
949
+ "DELETE FROM #{@simple_table} WHERE #{@simple_pk} = ".freeze
1325
950
  end
1326
951
  end
1327
952
 
1328
953
  # Reset the instance dataset to a modified copy of the current dataset,
1329
954
  # should be used whenever the model's dataset is modified.
1330
955
  def reset_instance_dataset
1331
- Sequel.synchronize{@finders.clear} if @finders && !@finders.frozen?
1332
956
  @instance_dataset = @dataset.limit(1).naked.skip_limit_check if @dataset
1333
957
  end
1334
958
 
@@ -1384,16 +1008,14 @@ module Sequel
1384
1008
  # Define instance method(s) that calls class method(s) of the
1385
1009
  # same name. Replaces the construct:
1386
1010
  #
1387
- # define_method(meth){self.class.send(meth)}
1011
+ # define_method(meth){self.class.public_send(meth)}
1388
1012
  [:columns, :db, :primary_key, :db_schema].each{|meth| class_eval("def #{meth}; self.class.#{meth} end", __FILE__, __LINE__)}
1389
1013
 
1390
1014
  # Define instance method(s) that calls class method(s) of the
1391
1015
  # same name, caching the result in an instance variable. Define
1392
1016
  # standard attr_writer method for modifying that instance variable.
1393
- [:typecast_empty_string_to_nil, :typecast_on_assignment, :strict_param_setting, \
1394
- :raise_on_save_failure, :raise_on_typecast_failure, :require_modification, :use_transactions,
1395
- :use_after_commit_rollback # SEQUEL5: Remove
1396
- ].each do |meth|
1017
+ [:typecast_empty_string_to_nil, :typecast_on_assignment, :strict_param_setting,
1018
+ :raise_on_save_failure, :raise_on_typecast_failure, :require_modification, :use_transactions].each do |meth|
1397
1019
  class_eval("def #{meth}; !defined?(@#{meth}) ? (frozen? ? self.class.#{meth} : (@#{meth} = self.class.#{meth})) : @#{meth} end", __FILE__, __LINE__)
1398
1020
  attr_writer(meth)
1399
1021
  end
@@ -1403,7 +1025,7 @@ module Sequel
1403
1025
  # receiver's values hash, and modifying it will also modify the receiver's
1404
1026
  # values.
1405
1027
  #
1406
- # Artist.new(:name=>'Bob').values # => {:name=>'Bob'}
1028
+ # Artist.new(name: 'Bob').values # => {:name=>'Bob'}
1407
1029
  # Artist[1].values # => {:id=>1, :name=>'Jim', ...}
1408
1030
  attr_reader :values
1409
1031
  alias to_hash values
@@ -1414,7 +1036,7 @@ module Sequel
1414
1036
  # method names.
1415
1037
  alias get_column_value send
1416
1038
 
1417
- # Set the value of the column. Takes two argument. The first is a
1039
+ # Set the value of the column. Takes two arguments. The first is a
1418
1040
  # symbol or string argument for the column name, suffixed with =. The
1419
1041
  # second is the value to set for the column. By default it calls send
1420
1042
  # with the argument to set the value. This can be overridden if you have
@@ -1428,7 +1050,7 @@ module Sequel
1428
1050
  # Arguments:
1429
1051
  # values :: should be a hash to pass to set.
1430
1052
  #
1431
- # Artist.new(:name=>'Bob')
1053
+ # Artist.new(name: 'Bob')
1432
1054
  #
1433
1055
  # Artist.new do |a|
1434
1056
  # a.name = 'Bob'
@@ -1530,11 +1152,8 @@ module Sequel
1530
1152
  end
1531
1153
 
1532
1154
  # Like delete but runs hooks before and after delete.
1533
- # If before_destroy returns false, returns false without
1534
- # deleting the object from the database. Otherwise, deletes
1535
- # the item from the database and returns self. Uses a transaction
1536
- # if use_transactions is true or if the :transaction option is given and
1537
- # true.
1155
+ # Uses a transaction if use_transactions is true or if the
1156
+ # :transaction option is given and true.
1538
1157
  #
1539
1158
  # Artist[1].destroy # BEGIN; DELETE FROM artists WHERE (id = 1); COMMIT;
1540
1159
  # # => #<Artist {:id=>1, ...}>
@@ -1598,7 +1217,7 @@ module Sequel
1598
1217
  validate
1599
1218
  errors.freeze
1600
1219
  end
1601
- this.freeze if !new? && model.primary_key
1220
+ this if !new? && model.primary_key
1602
1221
  super
1603
1222
  end
1604
1223
 
@@ -1606,9 +1225,9 @@ module Sequel
1606
1225
  # the same class and values (if pk is nil).
1607
1226
  #
1608
1227
  # Artist[1].hash == Artist[1].hash # true
1609
- # Artist[1].set(:name=>'Bob').hash == Artist[1].hash # true
1228
+ # Artist[1].set(name: 'Bob').hash == Artist[1].hash # true
1610
1229
  # Artist.new.hash == Artist.new.hash # true
1611
- # Artist.new(:name=>'Bob').hash == Artist.new.hash # false
1230
+ # Artist.new(name: 'Bob').hash == Artist.new.hash # false
1612
1231
  def hash
1613
1232
  case primary_key
1614
1233
  when Array
@@ -1637,7 +1256,7 @@ module Sequel
1637
1256
  # Returns the keys in +values+. May not include all column names.
1638
1257
  #
1639
1258
  # Artist.new.keys # => []
1640
- # Artist.new(:name=>'Bob').keys # => [:name]
1259
+ # Artist.new(name: 'Bob').keys # => [:name]
1641
1260
  # Artist[1].keys # => [:id, :name]
1642
1261
  def keys
1643
1262
  @values.keys
@@ -1709,7 +1328,7 @@ module Sequel
1709
1328
  #
1710
1329
  # a = Artist[1]
1711
1330
  # a.modified? # => false
1712
- # a.set(:name=>'Jim')
1331
+ # a.set(name: 'Jim')
1713
1332
  # a.modified? # => true
1714
1333
  #
1715
1334
  # If a column is given, specifically check if the given column has
@@ -1801,9 +1420,6 @@ module Sequel
1801
1420
  #
1802
1421
  # If it succeeds, it returns self.
1803
1422
  #
1804
- # You can provide an optional list of columns to update, in which
1805
- # case it only updates those columns, or a options hash.
1806
- #
1807
1423
  # Takes the following options:
1808
1424
  #
1809
1425
  # :changed :: save all changed columns, instead of all columns or the columns given
@@ -1818,12 +1434,9 @@ module Sequel
1818
1434
  def save(opts=OPTS)
1819
1435
  raise Sequel::Error, "can't save frozen object" if frozen?
1820
1436
  set_server(opts[:server]) if opts[:server]
1821
- _before_validation
1822
- if opts[:validate] != false # SEQUEL5: Remove if
1823
- unless checked_save_failure(opts){_valid?(opts)}
1824
- raise(ValidationFailed.new(self)) if raise_on_failure?(opts)
1825
- return
1826
- end
1437
+ unless checked_save_failure(opts){_valid?(opts)}
1438
+ raise(ValidationFailed.new(self)) if raise_on_failure?(opts)
1439
+ return
1827
1440
  end
1828
1441
  checked_save_failure(opts){checked_transaction(opts){_save(opts)}}
1829
1442
  end
@@ -1846,23 +1459,12 @@ module Sequel
1846
1459
  # a setter method (or ignoring it if <tt>strict_param_setting = false</tt>).
1847
1460
  # Does not save the record.
1848
1461
  #
1849
- # artist.set(:name=>'Jim')
1462
+ # artist.set(name: 'Jim')
1850
1463
  # artist.name # => 'Jim'
1851
1464
  def set(hash)
1852
1465
  set_restricted(hash, :default)
1853
1466
  end
1854
1467
 
1855
- # Set all values using the entries in the hash, ignoring any setting of
1856
- # allowed_columns in the model.
1857
- #
1858
- # Artist.set_allowed_columns(:num_albums)
1859
- # artist.set_all(:name=>'Jim')
1860
- # artist.name # => 'Jim'
1861
- def set_all(hash)
1862
- Sequel::Deprecation.deprecate("Sequel::Model#set_all", "Switch to set or load the whitelist_security plugin into the model class")
1863
- set_restricted(hash, :all)
1864
- end
1865
-
1866
1468
  # For each of the fields in the given array +fields+, call the setter
1867
1469
  # method with the value of that +hash+ entry for the field. Returns self.
1868
1470
  #
@@ -1875,19 +1477,19 @@ module Sequel
1875
1477
  #
1876
1478
  # Examples:
1877
1479
  #
1878
- # artist.set_fields({:name=>'Jim'}, [:name])
1480
+ # artist.set_fields({name: 'Jim'}, [:name])
1879
1481
  # artist.name # => 'Jim'
1880
1482
  #
1881
- # artist.set_fields({:hometown=>'LA'}, [:name])
1483
+ # artist.set_fields({hometown: 'LA'}, [:name])
1882
1484
  # artist.name # => nil
1883
1485
  # artist.hometown # => 'Sac'
1884
1486
  #
1885
1487
  # artist.name # => 'Jim'
1886
- # artist.set_fields({}, [:name], :missing=>:skip)
1488
+ # artist.set_fields({}, [:name], missing: :skip)
1887
1489
  # artist.name # => 'Jim'
1888
1490
  #
1889
1491
  # artist.name # => 'Jim'
1890
- # artist.set_fields({}, [:name], :missing=>:raise)
1492
+ # artist.set_fields({}, [:name], missing: :raise)
1891
1493
  # # Sequel::Error raised
1892
1494
  def set_fields(hash, fields, opts=nil)
1893
1495
  opts = if opts
@@ -1896,22 +1498,15 @@ module Sequel
1896
1498
  model.default_set_fields_options
1897
1499
  end
1898
1500
 
1899
- case opts[:missing]
1900
- when :skip
1501
+ case missing = opts[:missing]
1502
+ when :skip, :raise
1503
+ do_raise = true if missing == :raise
1901
1504
  fields.each do |f|
1902
1505
  if hash.has_key?(f)
1903
1506
  set_column_value("#{f}=", hash[f])
1904
1507
  elsif f.is_a?(Symbol) && hash.has_key?(sf = f.to_s)
1905
1508
  set_column_value("#{sf}=", hash[sf])
1906
- end
1907
- end
1908
- when :raise
1909
- fields.each do |f|
1910
- if hash.has_key?(f)
1911
- set_column_value("#{f}=", hash[f])
1912
- elsif f.is_a?(Symbol) && hash.has_key?(sf = f.to_s)
1913
- set_column_value("#{sf}=", hash[sf])
1914
- else
1509
+ elsif do_raise
1915
1510
  raise(Sequel::Error, "missing field in hash: #{f.inspect} not in #{hash.inspect}")
1916
1511
  end
1917
1512
  end
@@ -1921,19 +1516,6 @@ module Sequel
1921
1516
  self
1922
1517
  end
1923
1518
 
1924
- # Set the values using the entries in the hash, only if the key
1925
- # is included in only. It may be a better idea to use +set_fields+
1926
- # instead of this method.
1927
- #
1928
- # artist.set_only({:name=>'Jim'}, :name)
1929
- # artist.name # => 'Jim'
1930
- #
1931
- # artist.set_only({:hometown=>'LA'}, :name) # Raise Error
1932
- def set_only(hash, *only)
1933
- Sequel::Deprecation.deprecate("Sequel::Model#set_only", "Switch to set_fields with the :missing=>:skip option or load the whitelist_security plugin into the model class")
1934
- set_restricted(hash, only.flatten)
1935
- end
1936
-
1937
1519
  # Set the shard that this object is tied to. Returns self.
1938
1520
  def set_server(s)
1939
1521
  @server = s
@@ -1954,60 +1536,29 @@ module Sequel
1954
1536
  def this
1955
1537
  return @this if @this
1956
1538
  raise Error, "No dataset for model #{model}" unless ds = model.instance_dataset
1957
-
1958
- cond = if ds.joined_dataset?
1959
- # SEQUEL5: Remove as joined model datasets are now allowed
1960
- qualified_pk_hash
1961
- else
1962
- pk_hash
1963
- end
1964
-
1965
- @this = use_server(ds.where(cond))
1539
+ @this = use_server(ds.where(pk_hash))
1966
1540
  end
1967
1541
 
1968
1542
  # Runs #set with the passed hash and then runs save_changes.
1969
1543
  #
1970
- # artist.update(:name=>'Jim') # UPDATE artists SET name = 'Jim' WHERE (id = 1)
1544
+ # artist.update(name: 'Jim') # UPDATE artists SET name = 'Jim' WHERE (id = 1)
1971
1545
  def update(hash)
1972
1546
  update_restricted(hash, :default)
1973
1547
  end
1974
1548
 
1975
- # Update all values using the entries in the hash, ignoring any setting of
1976
- # +allowed_columns+ in the model.
1977
- #
1978
- # Artist.set_allowed_columns(:num_albums)
1979
- # artist.update_all(:name=>'Jim') # UPDATE artists SET name = 'Jim' WHERE (id = 1)
1980
- def update_all(hash)
1981
- Sequel::Deprecation.deprecate("Sequel::Model#update_all", "Switch to update or load the whitelist_security plugin into the model class")
1982
- update_restricted(hash, :all)
1983
- end
1984
-
1985
1549
  # Update the instances values by calling +set_fields+ with the arguments, then
1986
1550
  # saves any changes to the record. Returns self.
1987
1551
  #
1988
- # artist.update_fields({:name=>'Jim'}, [:name])
1552
+ # artist.update_fields({name: 'Jim'}, [:name])
1989
1553
  # # UPDATE artists SET name = 'Jim' WHERE (id = 1)
1990
1554
  #
1991
- # artist.update_fields({:hometown=>'LA'}, [:name])
1555
+ # artist.update_fields({hometown: 'LA'}, [:name])
1992
1556
  # # UPDATE artists SET name = NULL WHERE (id = 1)
1993
1557
  def update_fields(hash, fields, opts=nil)
1994
1558
  set_fields(hash, fields, opts)
1995
1559
  save_changes
1996
1560
  end
1997
1561
 
1998
- # Update the values using the entries in the hash, only if the key
1999
- # is included in only. It may be a better idea to use +update_fields+
2000
- # instead of this method.
2001
- #
2002
- # artist.update_only({:name=>'Jim'}, :name)
2003
- # # UPDATE artists SET name = 'Jim' WHERE (id = 1)
2004
- #
2005
- # artist.update_only({:hometown=>'LA'}, :name) # Raise Error
2006
- def update_only(hash, *only)
2007
- Sequel::Deprecation.deprecate("Sequel::Model#update_only", "Switch to update_fields with the :missing=>:skip option or load the whitelist_security plugin into the model class")
2008
- update_restricted(hash, only.flatten)
2009
- end
2010
-
2011
1562
  # Validates the object. If the object is invalid, errors should be added
2012
1563
  # to the errors attribute. By default, does nothing, as all models
2013
1564
  # are valid by default. See the {"Model Validations" guide}[rdoc-ref:doc/validations.rdoc].
@@ -2019,11 +1570,10 @@ module Sequel
2019
1570
 
2020
1571
  # Validates the object and returns true if no errors are reported.
2021
1572
  #
2022
- # artist.set(:name=>'Valid').valid? # => true
2023
- # artist.set(:name=>'Invalid').valid? # => false
1573
+ # artist.set(name: 'Valid').valid? # => true
1574
+ # artist.set(name: 'Invalid').valid? # => false
2024
1575
  # artist.errors.full_messages # => ['name cannot be Invalid']
2025
1576
  def valid?(opts = OPTS)
2026
- _before_validation
2027
1577
  begin
2028
1578
  _valid?(opts)
2029
1579
  rescue HookFailed
@@ -2033,42 +1583,6 @@ module Sequel
2033
1583
 
2034
1584
  private
2035
1585
 
2036
- # Run code directly after the INSERT query, before after_create.
2037
- # This is only a temporary API, it should not be overridden by external code.
2038
- def _after_create(pk)
2039
- # SEQUEL5: Remove
2040
- @this = nil
2041
- @new = false
2042
- @was_new = true
2043
- end
2044
-
2045
- # Run code after around_save returns, before calling after_commit.
2046
- # This is only a temporary API, it should not be overridden by external code.
2047
- def _after_save(pk)
2048
- # SEQUEL5: Remove
2049
- if @was_new
2050
- @was_new = nil
2051
- pk ? _save_refresh : changed_columns.clear
2052
- else
2053
- @columns_updated = nil
2054
- end
2055
- @modified = false
2056
- end
2057
-
2058
- # Run code directly after the UPDATE query, before after_update.
2059
- # This is only a temporary API, it should not be overridden by external code.
2060
- def _after_update
2061
- # SEQUEL5: Remove
2062
- @this = nil
2063
- end
2064
-
2065
- # Run code before any validation is done, but also run it before saving
2066
- # even if validation is skipped. This is a private hook. It exists so that
2067
- # plugins can set values automatically before validation (as the values
2068
- # need to be validated), but should be set even if validation is skipped.
2069
- def _before_validation
2070
- end
2071
-
2072
1586
  # Do the deletion of the object's dataset, and check that the row
2073
1587
  # was actually deleted.
2074
1588
  def _delete
@@ -2077,7 +1591,7 @@ module Sequel
2077
1591
  n
2078
1592
  end
2079
1593
 
2080
- # The dataset to use when deleting the object. The same as the object's
1594
+ # The dataset to use when deleting the object. The same as the object's
2081
1595
  # dataset by default.
2082
1596
  def _delete_dataset
2083
1597
  this
@@ -2099,28 +1613,14 @@ module Sequel
2099
1613
  # Internal destroy method, separted from destroy to
2100
1614
  # allow running inside a transaction
2101
1615
  def _destroy(opts)
2102
- sh = {:server=>this_server}
2103
- uacr = use_after_commit_rollback
2104
- if uacr.nil? ? (method(:after_destroy_rollback).owner != InstanceMethods) : uacr
2105
- Sequel::Deprecation.deprecate("Model#after_destroy_rollback", "Instead, call db.after_rollback in Model#before_destroy")
2106
- db.after_rollback(sh){after_destroy_rollback}
2107
- end
2108
1616
  called = false
2109
1617
  around_destroy do
2110
1618
  called = true
2111
- if before_destroy == false
2112
- Sequel::Deprecation.deprecate("Having before_destroy return false to cancel the destroy", "Instead, call cancel_action inside before_destroy")
2113
- raise_hook_failure(:before_destroy)
2114
- end
1619
+ before_destroy
2115
1620
  _destroy_delete
2116
1621
  after_destroy
2117
- true
2118
1622
  end
2119
1623
  raise_hook_failure(:around_destroy) unless called
2120
- if uacr.nil? ? (method(:after_destroy_commit).owner != InstanceMethods) : uacr
2121
- Sequel::Deprecation.deprecate("Model#after_destroy_commit", "Instead, call db.after_commit in Model#after_destroy")
2122
- db.after_commit(sh){after_destroy_commit}
2123
- end
2124
1624
  self
2125
1625
  end
2126
1626
 
@@ -2187,7 +1687,7 @@ module Sequel
2187
1687
  end
2188
1688
  end
2189
1689
 
2190
- # Set the refreshed values after
1690
+ # Set the values to the given hash after refreshing.
2191
1691
  def _refresh_set_values(h)
2192
1692
  @values = h
2193
1693
  end
@@ -2195,36 +1695,22 @@ module Sequel
2195
1695
  # Internal version of save, split from save to allow running inside
2196
1696
  # it's own transaction.
2197
1697
  def _save(opts)
2198
- sh = {:server=>this_server}
2199
- uacr = use_after_commit_rollback
2200
- if uacr.nil? ? (method(:after_rollback).owner != InstanceMethods) : uacr
2201
- Sequel::Deprecation.deprecate("Model#after_rollback", "Instead, call db.after_rollback in Model#before_save")
2202
- db.after_rollback(sh){after_rollback}
2203
- end
2204
1698
  pk = nil
2205
1699
  called_save = false
2206
1700
  called_cu = false
2207
1701
  around_save do
2208
1702
  called_save = true
2209
- if before_save == false
2210
- Sequel::Deprecation.deprecate("Having before_save return false to cancel the save", "Instead, call cancel_action inside before_save")
2211
- raise_hook_failure(:before_save)
2212
- end
1703
+ before_save
2213
1704
 
2214
1705
  if new?
2215
1706
  around_create do
2216
1707
  called_cu = true
2217
- if before_create == false
2218
- Sequel::Deprecation.deprecate("Having before_create return false to cancel the create", "Instead, call cancel_action inside before_create")
2219
- raise_hook_failure(:before_create)
2220
- end
1708
+ before_create
2221
1709
  pk = _insert
2222
- _after_create(pk) # SEQUEL5: Remove
2223
- # SEQUEL5
2224
- # @this = nil
2225
- # @new = false
2226
- # @modified = false
2227
- # pk ? _save_refresh : changed_columns.clear
1710
+ @this = nil
1711
+ @new = false
1712
+ @modified = false
1713
+ pk ? _save_refresh : changed_columns.clear
2228
1714
  after_create
2229
1715
  true
2230
1716
  end
@@ -2232,13 +1718,10 @@ module Sequel
2232
1718
  else
2233
1719
  around_update do
2234
1720
  called_cu = true
2235
- if before_update == false
2236
- Sequel::Deprecation.deprecate("Having before_update return false to cancel the update", "Instead, call cancel_action inside before_update")
2237
- raise_hook_failure(:before_update)
2238
- end
1721
+ before_update
2239
1722
  columns = opts[:columns]
2240
1723
  if columns.nil?
2241
- columns_updated = if opts[:changed] # SEQUEL5: Use local variable instead of instance variable
1724
+ columns_updated = if opts[:changed]
2242
1725
  @values.reject{|k,v| !changed_columns.include?(k)}
2243
1726
  else
2244
1727
  _save_update_all_columns_hash
@@ -2250,10 +1733,8 @@ module Sequel
2250
1733
  changed_columns.reject!{|c| columns.include?(c)}
2251
1734
  end
2252
1735
  _update_columns(columns_updated)
2253
- _after_update # SEQUEL5: Remove
2254
- # SEQUEL5
2255
- # @this = nil
2256
- # @modified = false
1736
+ @this = nil
1737
+ @modified = false
2257
1738
  after_update
2258
1739
  true
2259
1740
  end
@@ -2263,11 +1744,6 @@ module Sequel
2263
1744
  true
2264
1745
  end
2265
1746
  raise_hook_failure(:around_save) unless called_save
2266
- _after_save(pk) # SEQUEL5: Remove
2267
- if uacr.nil? ? (method(:after_commit).owner != InstanceMethods) : uacr
2268
- Sequel::Deprecation.deprecate("Model#after_commit", "Instead, call db.after_commit in Model#after_save")
2269
- db.after_commit(sh){after_commit}
2270
- end
2271
1747
  self
2272
1748
  end
2273
1749
 
@@ -2301,7 +1777,6 @@ module Sequel
2301
1777
  # Plugins can override this method in order to update with
2302
1778
  # additional columns, even when the column hash is initially empty.
2303
1779
  def _update_columns(columns)
2304
- @columns_updated ||= DeprecatedColumnsUpdated.new(columns) # SEQUEL5: Remove
2305
1780
  _update(columns) unless columns.empty?
2306
1781
  end
2307
1782
 
@@ -2334,18 +1809,16 @@ module Sequel
2334
1809
  return errors.empty? if frozen?
2335
1810
  errors.clear
2336
1811
  called = false
2337
- # skip_validate = opts[:validate] == false # SEQUEL5
1812
+ skip_validate = opts[:validate] == false
2338
1813
  around_validation do
2339
1814
  called = true
2340
- if before_validation == false
2341
- Sequel::Deprecation.deprecate("Having before_validation return false to mark the object as invalid", "Instead, call cancel_action inside before_validation")
2342
- raise_hook_failure(:before_validation)
2343
- else
2344
- validate # unless skip_validate # SEQUEL5
2345
- after_validation
2346
- end
1815
+ before_validation
1816
+ validate unless skip_validate
1817
+ after_validation
2347
1818
  end
2348
- # return true if skip_validate # SEQUEL5
1819
+
1820
+ return true if skip_validate
1821
+
2349
1822
  if called
2350
1823
  errors.empty?
2351
1824
  else
@@ -2384,24 +1857,12 @@ module Sequel
2384
1857
  Errors
2385
1858
  end
2386
1859
 
2387
- if RUBY_VERSION >= '1.9'
2388
- # Clone constructor -- freeze internal data structures if the original's
2389
- # are frozen.
2390
- def initialize_clone(other)
2391
- super
2392
- freeze if other.frozen?
2393
- self
2394
- end
2395
- else
2396
- # :nocov:
2397
- # Ruby 1.8 doesn't support initialize_clone, so override clone to dup and freeze.
2398
- def clone
2399
- o = dup
2400
- o.freeze if frozen?
2401
- o
2402
- end
2403
- public :clone
2404
- # :nocov:
1860
+ # Clone constructor -- freeze internal data structures if the original's
1861
+ # are frozen.
1862
+ def initialize_clone(other)
1863
+ super
1864
+ freeze if other.frozen?
1865
+ self
2405
1866
  end
2406
1867
 
2407
1868
  # Copy constructor -- Duplicate internal data structures.
@@ -2410,7 +1871,6 @@ module Sequel
2410
1871
  @values = Hash[@values]
2411
1872
  @changed_columns = @changed_columns.dup if @changed_columns
2412
1873
  @errors = @errors.dup if @errors
2413
- @this = @this.dup if @this
2414
1874
  self
2415
1875
  end
2416
1876
 
@@ -2489,19 +1949,13 @@ module Sequel
2489
1949
  # :all :: Allow setting all setters, except those specifically restricted (such as ==).
2490
1950
  # Array :: Only allow setting of columns in the given array.
2491
1951
  def setter_methods(type)
2492
- if type == :default
2493
- if !@singleton_setter_added || model.allowed_columns # SEQUEL5: Remove model.allowed_columns
2494
- return model.setter_methods
2495
- end
1952
+ if type == :default && !@singleton_setter_added
1953
+ return model.setter_methods
2496
1954
  end
2497
1955
 
2498
- if type.is_a?(Array)
2499
- type.map{|x| "#{x}="}
2500
- else
2501
- meths = methods.map(&:to_s).select{|l| l.end_with?('=')} - RESTRICTED_SETTER_METHODS
2502
- meths -= Array(primary_key).map{|x| "#{x}="} if type != :all && primary_key && model.restrict_primary_key?
2503
- meths
2504
- end
1956
+ meths = methods.map(&:to_s).select{|l| l.end_with?('=')} - RESTRICTED_SETTER_METHODS
1957
+ meths -= Array(primary_key).map{|x| "#{x}="} if primary_key && model.restrict_primary_key?
1958
+ meths
2505
1959
  end
2506
1960
 
2507
1961
  # The server/shard that the model object's dataset uses, or :default if the
@@ -2551,8 +2005,6 @@ module Sequel
2551
2005
 
2552
2006
  # DatasetMethods contains methods that all model datasets have.
2553
2007
  module DatasetMethods
2554
- Dataset.def_deprecated_opts_setter(self, :model)
2555
-
2556
2008
  # The model class associated with this dataset
2557
2009
  #
2558
2010
  # Artist.dataset.model # => Artist
@@ -2586,53 +2038,6 @@ module Sequel
2586
2038
  model.use_transactions ? @db.transaction(:server=>opts[:server], &pr) : pr.call
2587
2039
  end
2588
2040
 
2589
- # Allow Sequel::Model classes to be used as dataset arguments when graphing:
2590
- #
2591
- # Artist.graph(Album, :artist_id=>id)
2592
- # # SELECT artists.id, artists.name, albums.id AS albums_id, albums.artist_id, albums.name AS albums_name
2593
- # # FROM artists LEFT OUTER JOIN albums ON (albums.artist_id = artists.id)
2594
- def graph(table, *args, &block)
2595
- if table.is_a?(Class) && table < Sequel::Model
2596
- Sequel::Deprecation.deprecate("Passing Sequel::Model class as first argument to Sequel::Dataset#graph", "Pass the model's dataset as the first argument instead")
2597
- super(table.dataset, *args, &block)
2598
- else
2599
- super
2600
- end
2601
- end
2602
-
2603
- # Handle Sequel::Model instances when inserting, using the model instance's
2604
- # values for the insert, unless the model instance can be used directly in
2605
- # SQL.
2606
- #
2607
- # Album.insert(Album.load(:name=>'A'))
2608
- # # INSERT INTO albums (name) VALUES ('A')
2609
- def insert_sql(*values)
2610
- if values.size == 1 && (v = values[0]).is_a?(Sequel::Model) && !v.respond_to?(:sql_literal_append)
2611
- Sequel::Deprecation.deprecate("Passing Sequel::Model instance argument to Sequel::Dataset#insert", "Pass model_instance.values or model_instance.to_hash as the argument instead")
2612
- super(v.to_hash)
2613
- else
2614
- super
2615
- end
2616
- end
2617
-
2618
- # Allow Sequel::Model classes to be used as table name arguments in dataset
2619
- # join methods:
2620
- #
2621
- # Artist.join(Album, :artist_id=>id)
2622
- # # SELECT * FROM artists INNER JOIN albums ON (albums.artist_id = artists.id)
2623
- def join_table(type, table, *args, &block)
2624
- if table.is_a?(Class) && table < Sequel::Model
2625
- Sequel::Deprecation.deprecate("Passing Sequel::Model class to a dataset join method", "Pass the model's table name or dataset as the first argument instead")
2626
- if table.dataset.simple_select_all?
2627
- super(type, table.table_name, *args, &block)
2628
- else
2629
- super(type, table.dataset, *args, &block)
2630
- end
2631
- else
2632
- super
2633
- end
2634
- end
2635
-
2636
2041
  # If there is no order already defined on this dataset, order it by
2637
2042
  # the primary key and call last.
2638
2043
  #
@@ -2710,14 +2115,6 @@ module Sequel
2710
2115
 
2711
2116
  private
2712
2117
 
2713
- # SEQUEL5: Remove
2714
- def _model_where_loader
2715
- # :nocov:
2716
- Sequel::Deprecation.deprecate("Dataset#_model_where_loader", "Use _where_loader instead")
2717
- _where_loader
2718
- # :nocov:
2719
- end
2720
-
2721
2118
  # If the dataset is not already ordered, and the model has a primary key,
2722
2119
  # return a clone ordered by the primary key.
2723
2120
  def _primary_key_order
@@ -2750,5 +2147,10 @@ module Sequel
2750
2147
 
2751
2148
  extend ClassMethods
2752
2149
  plugin self
2150
+
2151
+ singleton_class.send(:undef_method, :dup, :clone, :initialize_copy)
2152
+ if RUBY_VERSION >= '1.9.3'
2153
+ singleton_class.send(:undef_method, :initialize_clone, :initialize_dup)
2154
+ end
2753
2155
  end
2754
2156
  end