sequel 4.26.0 → 5.37.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 (692) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG +405 -5656
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +232 -157
  5. data/bin/sequel +32 -9
  6. data/doc/advanced_associations.rdoc +252 -188
  7. data/doc/association_basics.rdoc +231 -273
  8. data/doc/bin_sequel.rdoc +5 -3
  9. data/doc/cheat_sheet.rdoc +75 -48
  10. data/doc/code_order.rdoc +28 -10
  11. data/doc/core_extensions.rdoc +104 -63
  12. data/doc/dataset_basics.rdoc +12 -21
  13. data/doc/dataset_filtering.rdoc +99 -86
  14. data/doc/extensions.rdoc +3 -10
  15. data/doc/mass_assignment.rdoc +74 -31
  16. data/doc/migration.rdoc +72 -46
  17. data/doc/model_dataset_method_design.rdoc +129 -0
  18. data/doc/model_hooks.rdoc +15 -25
  19. data/doc/model_plugins.rdoc +12 -12
  20. data/doc/mssql_stored_procedures.rdoc +3 -3
  21. data/doc/object_model.rdoc +59 -69
  22. data/doc/opening_databases.rdoc +84 -94
  23. data/doc/postgresql.rdoc +268 -38
  24. data/doc/prepared_statements.rdoc +29 -24
  25. data/doc/querying.rdoc +184 -164
  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.10.0.txt +84 -0
  30. data/doc/release_notes/5.11.0.txt +83 -0
  31. data/doc/release_notes/5.12.0.txt +141 -0
  32. data/doc/release_notes/5.13.0.txt +27 -0
  33. data/doc/release_notes/5.14.0.txt +63 -0
  34. data/doc/release_notes/5.15.0.txt +39 -0
  35. data/doc/release_notes/5.16.0.txt +110 -0
  36. data/doc/release_notes/5.17.0.txt +31 -0
  37. data/doc/release_notes/5.18.0.txt +69 -0
  38. data/doc/release_notes/5.19.0.txt +28 -0
  39. data/doc/release_notes/5.2.0.txt +33 -0
  40. data/doc/release_notes/5.20.0.txt +89 -0
  41. data/doc/release_notes/5.21.0.txt +87 -0
  42. data/doc/release_notes/5.22.0.txt +48 -0
  43. data/doc/release_notes/5.23.0.txt +56 -0
  44. data/doc/release_notes/5.24.0.txt +56 -0
  45. data/doc/release_notes/5.25.0.txt +32 -0
  46. data/doc/release_notes/5.26.0.txt +35 -0
  47. data/doc/release_notes/5.27.0.txt +21 -0
  48. data/doc/release_notes/5.28.0.txt +16 -0
  49. data/doc/release_notes/5.29.0.txt +22 -0
  50. data/doc/release_notes/5.3.0.txt +121 -0
  51. data/doc/release_notes/5.30.0.txt +20 -0
  52. data/doc/release_notes/5.31.0.txt +148 -0
  53. data/doc/release_notes/5.32.0.txt +46 -0
  54. data/doc/release_notes/5.33.0.txt +24 -0
  55. data/doc/release_notes/5.34.0.txt +40 -0
  56. data/doc/release_notes/5.35.0.txt +56 -0
  57. data/doc/release_notes/5.36.0.txt +60 -0
  58. data/doc/release_notes/5.37.0.txt +30 -0
  59. data/doc/release_notes/5.4.0.txt +80 -0
  60. data/doc/release_notes/5.5.0.txt +61 -0
  61. data/doc/release_notes/5.6.0.txt +31 -0
  62. data/doc/release_notes/5.7.0.txt +108 -0
  63. data/doc/release_notes/5.8.0.txt +170 -0
  64. data/doc/release_notes/5.9.0.txt +99 -0
  65. data/doc/schema_modification.rdoc +102 -77
  66. data/doc/security.rdoc +160 -87
  67. data/doc/sharding.rdoc +74 -47
  68. data/doc/sql.rdoc +135 -122
  69. data/doc/testing.rdoc +34 -18
  70. data/doc/thread_safety.rdoc +2 -4
  71. data/doc/transactions.rdoc +101 -19
  72. data/doc/validations.rdoc +64 -51
  73. data/doc/virtual_rows.rdoc +90 -109
  74. data/lib/sequel.rb +3 -1
  75. data/lib/sequel/adapters/ado.rb +154 -22
  76. data/lib/sequel/adapters/ado/access.rb +21 -21
  77. data/lib/sequel/adapters/ado/mssql.rb +8 -15
  78. data/lib/sequel/adapters/amalgalite.rb +17 -25
  79. data/lib/sequel/adapters/ibmdb.rb +52 -58
  80. data/lib/sequel/adapters/jdbc.rb +149 -127
  81. data/lib/sequel/adapters/jdbc/db2.rb +32 -40
  82. data/lib/sequel/adapters/jdbc/derby.rb +56 -58
  83. data/lib/sequel/adapters/jdbc/h2.rb +40 -30
  84. data/lib/sequel/adapters/jdbc/hsqldb.rb +22 -33
  85. data/lib/sequel/adapters/jdbc/jtds.rb +4 -10
  86. data/lib/sequel/adapters/jdbc/mssql.rb +6 -12
  87. data/lib/sequel/adapters/jdbc/mysql.rb +17 -18
  88. data/lib/sequel/adapters/jdbc/oracle.rb +25 -19
  89. data/lib/sequel/adapters/jdbc/postgresql.rb +90 -69
  90. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +14 -24
  91. data/lib/sequel/adapters/jdbc/sqlite.rb +50 -12
  92. data/lib/sequel/adapters/jdbc/sqlserver.rb +36 -9
  93. data/lib/sequel/adapters/jdbc/transactions.rb +25 -39
  94. data/lib/sequel/adapters/mock.rb +104 -113
  95. data/lib/sequel/adapters/mysql.rb +42 -61
  96. data/lib/sequel/adapters/mysql2.rb +126 -35
  97. data/lib/sequel/adapters/odbc.rb +21 -28
  98. data/lib/sequel/adapters/odbc/db2.rb +3 -1
  99. data/lib/sequel/adapters/odbc/mssql.rb +11 -15
  100. data/lib/sequel/adapters/odbc/oracle.rb +11 -0
  101. data/lib/sequel/adapters/oracle.rb +62 -68
  102. data/lib/sequel/adapters/postgres.rb +257 -311
  103. data/lib/sequel/adapters/postgresql.rb +3 -1
  104. data/lib/sequel/adapters/shared/access.rb +75 -79
  105. data/lib/sequel/adapters/shared/db2.rb +96 -74
  106. data/lib/sequel/adapters/shared/mssql.rb +258 -213
  107. data/lib/sequel/adapters/shared/mysql.rb +284 -216
  108. data/lib/sequel/adapters/shared/oracle.rb +175 -60
  109. data/lib/sequel/adapters/shared/postgres.rb +829 -383
  110. data/lib/sequel/adapters/shared/sqlanywhere.rb +105 -127
  111. data/lib/sequel/adapters/shared/sqlite.rb +382 -159
  112. data/lib/sequel/adapters/sqlanywhere.rb +53 -38
  113. data/lib/sequel/adapters/sqlite.rb +111 -105
  114. data/lib/sequel/adapters/tinytds.rb +38 -46
  115. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +8 -9
  116. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +7 -5
  117. data/lib/sequel/adapters/utils/mysql_mysql2.rb +87 -0
  118. data/lib/sequel/adapters/utils/mysql_prepared_statements.rb +56 -0
  119. data/lib/sequel/adapters/utils/replace.rb +3 -4
  120. data/lib/sequel/adapters/utils/split_alter_table.rb +2 -0
  121. data/lib/sequel/adapters/utils/stored_procedures.rb +9 -22
  122. data/lib/sequel/adapters/utils/unmodified_identifiers.rb +28 -0
  123. data/lib/sequel/ast_transformer.rb +13 -89
  124. data/lib/sequel/connection_pool.rb +54 -26
  125. data/lib/sequel/connection_pool/sharded_single.rb +19 -12
  126. data/lib/sequel/connection_pool/sharded_threaded.rb +160 -111
  127. data/lib/sequel/connection_pool/single.rb +21 -12
  128. data/lib/sequel/connection_pool/threaded.rb +137 -119
  129. data/lib/sequel/core.rb +352 -320
  130. data/lib/sequel/database.rb +19 -2
  131. data/lib/sequel/database/connecting.rb +70 -55
  132. data/lib/sequel/database/dataset.rb +15 -5
  133. data/lib/sequel/database/dataset_defaults.rb +20 -102
  134. data/lib/sequel/database/features.rb +20 -4
  135. data/lib/sequel/database/logging.rb +25 -7
  136. data/lib/sequel/database/misc.rb +132 -118
  137. data/lib/sequel/database/query.rb +51 -28
  138. data/lib/sequel/database/schema_generator.rb +188 -75
  139. data/lib/sequel/database/schema_methods.rb +161 -92
  140. data/lib/sequel/database/transactions.rb +260 -58
  141. data/lib/sequel/dataset.rb +28 -12
  142. data/lib/sequel/dataset/actions.rb +354 -170
  143. data/lib/sequel/dataset/dataset_module.rb +46 -0
  144. data/lib/sequel/dataset/features.rb +81 -34
  145. data/lib/sequel/dataset/graph.rb +82 -58
  146. data/lib/sequel/dataset/misc.rb +139 -47
  147. data/lib/sequel/dataset/placeholder_literalizer.rb +66 -26
  148. data/lib/sequel/dataset/prepared_statements.rb +188 -85
  149. data/lib/sequel/dataset/query.rb +428 -214
  150. data/lib/sequel/dataset/sql.rb +446 -339
  151. data/lib/sequel/deprecated.rb +14 -2
  152. data/lib/sequel/exceptions.rb +48 -16
  153. data/lib/sequel/extensions/_model_constraint_validations.rb +16 -0
  154. data/lib/sequel/extensions/_model_pg_row.rb +43 -0
  155. data/lib/sequel/extensions/_pretty_table.rb +10 -9
  156. data/lib/sequel/extensions/any_not_empty.rb +45 -0
  157. data/lib/sequel/extensions/arbitrary_servers.rb +15 -11
  158. data/lib/sequel/extensions/auto_literal_strings.rb +74 -0
  159. data/lib/sequel/extensions/blank.rb +2 -0
  160. data/lib/sequel/extensions/caller_logging.rb +79 -0
  161. data/lib/sequel/extensions/columns_introspection.rb +9 -4
  162. data/lib/sequel/extensions/connection_expiration.rb +99 -0
  163. data/lib/sequel/extensions/connection_validator.rb +26 -13
  164. data/lib/sequel/extensions/constant_sql_override.rb +65 -0
  165. data/lib/sequel/extensions/constraint_validations.rb +93 -38
  166. data/lib/sequel/extensions/core_extensions.rb +45 -53
  167. data/lib/sequel/extensions/core_refinements.rb +44 -46
  168. data/lib/sequel/extensions/current_datetime_timestamp.rb +5 -4
  169. data/lib/sequel/extensions/dataset_source_alias.rb +4 -0
  170. data/lib/sequel/extensions/date_arithmetic.rb +42 -16
  171. data/lib/sequel/extensions/datetime_parse_to_time.rb +37 -0
  172. data/lib/sequel/extensions/duplicate_columns_handler.rb +94 -0
  173. data/lib/sequel/extensions/empty_array_consider_nulls.rb +7 -3
  174. data/lib/sequel/extensions/error_sql.rb +7 -3
  175. data/lib/sequel/extensions/escaped_like.rb +100 -0
  176. data/lib/sequel/extensions/eval_inspect.rb +14 -15
  177. data/lib/sequel/extensions/exclude_or_null.rb +68 -0
  178. data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
  179. data/lib/sequel/extensions/freeze_datasets.rb +3 -0
  180. data/lib/sequel/extensions/from_block.rb +2 -31
  181. data/lib/sequel/extensions/graph_each.rb +19 -6
  182. data/lib/sequel/extensions/identifier_mangling.rb +180 -0
  183. data/lib/sequel/extensions/implicit_subquery.rb +48 -0
  184. data/lib/sequel/extensions/index_caching.rb +109 -0
  185. data/lib/sequel/extensions/inflector.rb +8 -4
  186. data/lib/sequel/extensions/integer64.rb +32 -0
  187. data/lib/sequel/extensions/looser_typecasting.rb +19 -9
  188. data/lib/sequel/extensions/migration.rb +132 -80
  189. data/lib/sequel/extensions/mssql_emulate_lateral_with_apply.rb +4 -0
  190. data/lib/sequel/extensions/named_timezones.rb +88 -23
  191. data/lib/sequel/extensions/no_auto_literal_strings.rb +4 -0
  192. data/lib/sequel/extensions/null_dataset.rb +12 -8
  193. data/lib/sequel/extensions/pagination.rb +35 -28
  194. data/lib/sequel/extensions/pg_array.rb +227 -316
  195. data/lib/sequel/extensions/pg_array_ops.rb +19 -7
  196. data/lib/sequel/extensions/pg_enum.rb +69 -24
  197. data/lib/sequel/extensions/pg_extended_date_support.rb +250 -0
  198. data/lib/sequel/extensions/pg_hstore.rb +50 -59
  199. data/lib/sequel/extensions/pg_hstore_ops.rb +9 -3
  200. data/lib/sequel/extensions/pg_inet.rb +34 -15
  201. data/lib/sequel/extensions/pg_inet_ops.rb +5 -1
  202. data/lib/sequel/extensions/pg_interval.rb +26 -26
  203. data/lib/sequel/extensions/pg_json.rb +422 -141
  204. data/lib/sequel/extensions/pg_json_ops.rb +248 -9
  205. data/lib/sequel/extensions/pg_loose_count.rb +5 -1
  206. data/lib/sequel/extensions/pg_range.rb +162 -146
  207. data/lib/sequel/extensions/pg_range_ops.rb +10 -5
  208. data/lib/sequel/extensions/pg_row.rb +53 -87
  209. data/lib/sequel/extensions/pg_row_ops.rb +36 -13
  210. data/lib/sequel/extensions/pg_static_cache_updater.rb +6 -2
  211. data/lib/sequel/extensions/pg_timestamptz.rb +28 -0
  212. data/lib/sequel/extensions/pretty_table.rb +4 -0
  213. data/lib/sequel/extensions/query.rb +12 -7
  214. data/lib/sequel/extensions/round_timestamps.rb +6 -9
  215. data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
  216. data/lib/sequel/extensions/s.rb +59 -0
  217. data/lib/sequel/extensions/schema_caching.rb +14 -1
  218. data/lib/sequel/extensions/schema_dumper.rb +83 -55
  219. data/lib/sequel/extensions/select_remove.rb +8 -4
  220. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +85 -0
  221. data/lib/sequel/extensions/server_block.rb +50 -17
  222. data/lib/sequel/extensions/server_logging.rb +61 -0
  223. data/lib/sequel/extensions/split_array_nil.rb +8 -4
  224. data/lib/sequel/extensions/sql_comments.rb +96 -0
  225. data/lib/sequel/extensions/sql_expr.rb +4 -1
  226. data/lib/sequel/extensions/string_agg.rb +181 -0
  227. data/lib/sequel/extensions/string_date_time.rb +2 -0
  228. data/lib/sequel/extensions/symbol_aref.rb +53 -0
  229. data/lib/sequel/extensions/symbol_aref_refinement.rb +43 -0
  230. data/lib/sequel/extensions/symbol_as.rb +23 -0
  231. data/lib/sequel/extensions/symbol_as_refinement.rb +37 -0
  232. data/lib/sequel/extensions/synchronize_sql.rb +45 -0
  233. data/lib/sequel/extensions/thread_local_timezones.rb +4 -0
  234. data/lib/sequel/extensions/to_dot.rb +15 -5
  235. data/lib/sequel/extensions/virtual_row_method_block.rb +44 -0
  236. data/lib/sequel/model.rb +36 -126
  237. data/lib/sequel/model/associations.rb +850 -257
  238. data/lib/sequel/model/base.rb +652 -764
  239. data/lib/sequel/model/dataset_module.rb +13 -10
  240. data/lib/sequel/model/default_inflections.rb +3 -1
  241. data/lib/sequel/model/errors.rb +3 -3
  242. data/lib/sequel/model/exceptions.rb +12 -12
  243. data/lib/sequel/model/inflections.rb +8 -19
  244. data/lib/sequel/model/plugins.rb +111 -0
  245. data/lib/sequel/plugins/accessed_columns.rb +2 -0
  246. data/lib/sequel/plugins/active_model.rb +32 -7
  247. data/lib/sequel/plugins/after_initialize.rb +3 -1
  248. data/lib/sequel/plugins/association_dependencies.rb +27 -18
  249. data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
  250. data/lib/sequel/plugins/association_multi_add_remove.rb +85 -0
  251. data/lib/sequel/plugins/association_pks.rb +181 -83
  252. data/lib/sequel/plugins/association_proxies.rb +33 -9
  253. data/lib/sequel/plugins/auto_validations.rb +58 -23
  254. data/lib/sequel/plugins/before_after_save.rb +8 -0
  255. data/lib/sequel/plugins/blacklist_security.rb +23 -12
  256. data/lib/sequel/plugins/boolean_readers.rb +9 -6
  257. data/lib/sequel/plugins/boolean_subsets.rb +64 -0
  258. data/lib/sequel/plugins/caching.rb +27 -16
  259. data/lib/sequel/plugins/class_table_inheritance.rb +192 -94
  260. data/lib/sequel/plugins/column_conflicts.rb +18 -3
  261. data/lib/sequel/plugins/column_select.rb +9 -5
  262. data/lib/sequel/plugins/columns_updated.rb +42 -0
  263. data/lib/sequel/plugins/composition.rb +36 -24
  264. data/lib/sequel/plugins/constraint_validations.rb +37 -16
  265. data/lib/sequel/plugins/csv_serializer.rb +58 -35
  266. data/lib/sequel/plugins/dataset_associations.rb +60 -18
  267. data/lib/sequel/plugins/def_dataset_method.rb +90 -0
  268. data/lib/sequel/plugins/defaults_setter.rb +74 -13
  269. data/lib/sequel/plugins/delay_add_association.rb +4 -1
  270. data/lib/sequel/plugins/dirty.rb +65 -24
  271. data/lib/sequel/plugins/eager_each.rb +27 -3
  272. data/lib/sequel/plugins/eager_graph_eager.rb +139 -0
  273. data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
  274. data/lib/sequel/plugins/error_splitter.rb +19 -12
  275. data/lib/sequel/plugins/finder.rb +246 -0
  276. data/lib/sequel/plugins/forbid_lazy_load.rb +216 -0
  277. data/lib/sequel/plugins/force_encoding.rb +9 -12
  278. data/lib/sequel/plugins/hook_class_methods.rb +39 -54
  279. data/lib/sequel/plugins/input_transformer.rb +20 -10
  280. data/lib/sequel/plugins/insert_conflict.rb +72 -0
  281. data/lib/sequel/plugins/insert_returning_select.rb +4 -2
  282. data/lib/sequel/plugins/instance_filters.rb +12 -8
  283. data/lib/sequel/plugins/instance_hooks.rb +36 -17
  284. data/lib/sequel/plugins/instance_specific_default.rb +113 -0
  285. data/lib/sequel/plugins/inverted_subsets.rb +24 -13
  286. data/lib/sequel/plugins/json_serializer.rb +123 -47
  287. data/lib/sequel/plugins/lazy_attributes.rb +20 -14
  288. data/lib/sequel/plugins/list.rb +40 -26
  289. data/lib/sequel/plugins/many_through_many.rb +28 -12
  290. data/lib/sequel/plugins/modification_detection.rb +17 -5
  291. data/lib/sequel/plugins/mssql_optimistic_locking.rb +8 -5
  292. data/lib/sequel/plugins/nested_attributes.rb +55 -28
  293. data/lib/sequel/plugins/optimistic_locking.rb +5 -3
  294. data/lib/sequel/plugins/pg_array_associations.rb +52 -18
  295. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +348 -0
  296. data/lib/sequel/plugins/pg_row.rb +7 -51
  297. data/lib/sequel/plugins/prepared_statements.rb +53 -72
  298. data/lib/sequel/plugins/prepared_statements_safe.rb +13 -5
  299. data/lib/sequel/plugins/rcte_tree.rb +43 -63
  300. data/lib/sequel/plugins/serialization.rb +37 -44
  301. data/lib/sequel/plugins/serialization_modification_detection.rb +3 -1
  302. data/lib/sequel/plugins/sharding.rb +17 -10
  303. data/lib/sequel/plugins/single_table_inheritance.rb +62 -28
  304. data/lib/sequel/plugins/singular_table_names.rb +2 -0
  305. data/lib/sequel/plugins/skip_create_refresh.rb +5 -3
  306. data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
  307. data/lib/sequel/plugins/split_values.rb +13 -6
  308. data/lib/sequel/plugins/static_cache.rb +79 -53
  309. data/lib/sequel/plugins/static_cache_cache.rb +53 -0
  310. data/lib/sequel/plugins/string_stripper.rb +5 -3
  311. data/lib/sequel/plugins/subclasses.rb +20 -2
  312. data/lib/sequel/plugins/subset_conditions.rb +48 -0
  313. data/lib/sequel/plugins/table_select.rb +4 -2
  314. data/lib/sequel/plugins/tactical_eager_loading.rb +120 -6
  315. data/lib/sequel/plugins/throw_failures.rb +110 -0
  316. data/lib/sequel/plugins/timestamps.rb +22 -8
  317. data/lib/sequel/plugins/touch.rb +21 -8
  318. data/lib/sequel/plugins/tree.rb +57 -30
  319. data/lib/sequel/plugins/typecast_on_load.rb +14 -4
  320. data/lib/sequel/plugins/unlimited_update.rb +3 -7
  321. data/lib/sequel/plugins/update_or_create.rb +6 -4
  322. data/lib/sequel/plugins/update_primary_key.rb +3 -1
  323. data/lib/sequel/plugins/update_refresh.rb +28 -15
  324. data/lib/sequel/plugins/uuid.rb +70 -0
  325. data/lib/sequel/plugins/validate_associated.rb +20 -0
  326. data/lib/sequel/plugins/validation_class_methods.rb +40 -19
  327. data/lib/sequel/plugins/validation_contexts.rb +49 -0
  328. data/lib/sequel/plugins/validation_helpers.rb +49 -31
  329. data/lib/sequel/plugins/whitelist_security.rb +122 -0
  330. data/lib/sequel/plugins/xml_serializer.rb +31 -30
  331. data/lib/sequel/sql.rb +479 -329
  332. data/lib/sequel/timezones.rb +62 -32
  333. data/lib/sequel/version.rb +10 -3
  334. metadata +177 -477
  335. data/Rakefile +0 -165
  336. data/doc/active_record.rdoc +0 -912
  337. data/doc/release_notes/1.0.txt +0 -38
  338. data/doc/release_notes/1.1.txt +0 -143
  339. data/doc/release_notes/1.3.txt +0 -101
  340. data/doc/release_notes/1.4.0.txt +0 -53
  341. data/doc/release_notes/1.5.0.txt +0 -155
  342. data/doc/release_notes/2.0.0.txt +0 -298
  343. data/doc/release_notes/2.1.0.txt +0 -271
  344. data/doc/release_notes/2.10.0.txt +0 -328
  345. data/doc/release_notes/2.11.0.txt +0 -215
  346. data/doc/release_notes/2.12.0.txt +0 -534
  347. data/doc/release_notes/2.2.0.txt +0 -253
  348. data/doc/release_notes/2.3.0.txt +0 -88
  349. data/doc/release_notes/2.4.0.txt +0 -106
  350. data/doc/release_notes/2.5.0.txt +0 -137
  351. data/doc/release_notes/2.6.0.txt +0 -157
  352. data/doc/release_notes/2.7.0.txt +0 -166
  353. data/doc/release_notes/2.8.0.txt +0 -171
  354. data/doc/release_notes/2.9.0.txt +0 -97
  355. data/doc/release_notes/3.0.0.txt +0 -221
  356. data/doc/release_notes/3.1.0.txt +0 -406
  357. data/doc/release_notes/3.10.0.txt +0 -286
  358. data/doc/release_notes/3.11.0.txt +0 -254
  359. data/doc/release_notes/3.12.0.txt +0 -304
  360. data/doc/release_notes/3.13.0.txt +0 -210
  361. data/doc/release_notes/3.14.0.txt +0 -118
  362. data/doc/release_notes/3.15.0.txt +0 -78
  363. data/doc/release_notes/3.16.0.txt +0 -45
  364. data/doc/release_notes/3.17.0.txt +0 -58
  365. data/doc/release_notes/3.18.0.txt +0 -120
  366. data/doc/release_notes/3.19.0.txt +0 -67
  367. data/doc/release_notes/3.2.0.txt +0 -268
  368. data/doc/release_notes/3.20.0.txt +0 -41
  369. data/doc/release_notes/3.21.0.txt +0 -87
  370. data/doc/release_notes/3.22.0.txt +0 -39
  371. data/doc/release_notes/3.23.0.txt +0 -172
  372. data/doc/release_notes/3.24.0.txt +0 -420
  373. data/doc/release_notes/3.25.0.txt +0 -88
  374. data/doc/release_notes/3.26.0.txt +0 -88
  375. data/doc/release_notes/3.27.0.txt +0 -82
  376. data/doc/release_notes/3.28.0.txt +0 -304
  377. data/doc/release_notes/3.29.0.txt +0 -459
  378. data/doc/release_notes/3.3.0.txt +0 -192
  379. data/doc/release_notes/3.30.0.txt +0 -135
  380. data/doc/release_notes/3.31.0.txt +0 -146
  381. data/doc/release_notes/3.32.0.txt +0 -202
  382. data/doc/release_notes/3.33.0.txt +0 -157
  383. data/doc/release_notes/3.34.0.txt +0 -671
  384. data/doc/release_notes/3.35.0.txt +0 -144
  385. data/doc/release_notes/3.36.0.txt +0 -245
  386. data/doc/release_notes/3.37.0.txt +0 -338
  387. data/doc/release_notes/3.38.0.txt +0 -234
  388. data/doc/release_notes/3.39.0.txt +0 -237
  389. data/doc/release_notes/3.4.0.txt +0 -325
  390. data/doc/release_notes/3.40.0.txt +0 -73
  391. data/doc/release_notes/3.41.0.txt +0 -155
  392. data/doc/release_notes/3.42.0.txt +0 -74
  393. data/doc/release_notes/3.43.0.txt +0 -105
  394. data/doc/release_notes/3.44.0.txt +0 -152
  395. data/doc/release_notes/3.45.0.txt +0 -179
  396. data/doc/release_notes/3.46.0.txt +0 -122
  397. data/doc/release_notes/3.47.0.txt +0 -270
  398. data/doc/release_notes/3.48.0.txt +0 -477
  399. data/doc/release_notes/3.5.0.txt +0 -510
  400. data/doc/release_notes/3.6.0.txt +0 -366
  401. data/doc/release_notes/3.7.0.txt +0 -179
  402. data/doc/release_notes/3.8.0.txt +0 -151
  403. data/doc/release_notes/3.9.0.txt +0 -233
  404. data/doc/release_notes/4.0.0.txt +0 -262
  405. data/doc/release_notes/4.1.0.txt +0 -85
  406. data/doc/release_notes/4.10.0.txt +0 -226
  407. data/doc/release_notes/4.11.0.txt +0 -147
  408. data/doc/release_notes/4.12.0.txt +0 -105
  409. data/doc/release_notes/4.13.0.txt +0 -169
  410. data/doc/release_notes/4.14.0.txt +0 -68
  411. data/doc/release_notes/4.15.0.txt +0 -56
  412. data/doc/release_notes/4.16.0.txt +0 -36
  413. data/doc/release_notes/4.17.0.txt +0 -38
  414. data/doc/release_notes/4.18.0.txt +0 -36
  415. data/doc/release_notes/4.19.0.txt +0 -45
  416. data/doc/release_notes/4.2.0.txt +0 -129
  417. data/doc/release_notes/4.20.0.txt +0 -79
  418. data/doc/release_notes/4.21.0.txt +0 -94
  419. data/doc/release_notes/4.22.0.txt +0 -72
  420. data/doc/release_notes/4.23.0.txt +0 -65
  421. data/doc/release_notes/4.24.0.txt +0 -99
  422. data/doc/release_notes/4.25.0.txt +0 -181
  423. data/doc/release_notes/4.26.0.txt +0 -44
  424. data/doc/release_notes/4.3.0.txt +0 -40
  425. data/doc/release_notes/4.4.0.txt +0 -92
  426. data/doc/release_notes/4.5.0.txt +0 -34
  427. data/doc/release_notes/4.6.0.txt +0 -30
  428. data/doc/release_notes/4.7.0.txt +0 -103
  429. data/doc/release_notes/4.8.0.txt +0 -175
  430. data/doc/release_notes/4.9.0.txt +0 -190
  431. data/lib/sequel/adapters/cubrid.rb +0 -142
  432. data/lib/sequel/adapters/do.rb +0 -156
  433. data/lib/sequel/adapters/do/mysql.rb +0 -64
  434. data/lib/sequel/adapters/do/postgres.rb +0 -42
  435. data/lib/sequel/adapters/do/sqlite3.rb +0 -40
  436. data/lib/sequel/adapters/jdbc/as400.rb +0 -82
  437. data/lib/sequel/adapters/jdbc/cubrid.rb +0 -62
  438. data/lib/sequel/adapters/jdbc/firebirdsql.rb +0 -34
  439. data/lib/sequel/adapters/jdbc/informix-sqli.rb +0 -31
  440. data/lib/sequel/adapters/jdbc/jdbcprogress.rb +0 -31
  441. data/lib/sequel/adapters/odbc/progress.rb +0 -8
  442. data/lib/sequel/adapters/shared/cubrid.rb +0 -243
  443. data/lib/sequel/adapters/shared/firebird.rb +0 -245
  444. data/lib/sequel/adapters/shared/informix.rb +0 -52
  445. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +0 -150
  446. data/lib/sequel/adapters/shared/progress.rb +0 -38
  447. data/lib/sequel/adapters/swift.rb +0 -158
  448. data/lib/sequel/adapters/swift/mysql.rb +0 -47
  449. data/lib/sequel/adapters/swift/postgres.rb +0 -45
  450. data/lib/sequel/adapters/swift/sqlite.rb +0 -47
  451. data/lib/sequel/adapters/utils/pg_types.rb +0 -68
  452. data/lib/sequel/dataset/mutation.rb +0 -109
  453. data/lib/sequel/extensions/empty_array_ignore_nulls.rb +0 -3
  454. data/lib/sequel/extensions/filter_having.rb +0 -59
  455. data/lib/sequel/extensions/hash_aliases.rb +0 -45
  456. data/lib/sequel/extensions/meta_def.rb +0 -31
  457. data/lib/sequel/extensions/query_literals.rb +0 -80
  458. data/lib/sequel/extensions/ruby18_symbol_extensions.rb +0 -22
  459. data/lib/sequel/extensions/sequel_3_dataset_methods.rb +0 -118
  460. data/lib/sequel/extensions/set_overrides.rb +0 -72
  461. data/lib/sequel/no_core_ext.rb +0 -1
  462. data/lib/sequel/plugins/association_autoreloading.rb +0 -7
  463. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +0 -7
  464. data/lib/sequel/plugins/pg_typecast_on_load.rb +0 -78
  465. data/lib/sequel/plugins/prepared_statements_associations.rb +0 -117
  466. data/lib/sequel/plugins/prepared_statements_with_pk.rb +0 -59
  467. data/lib/sequel/plugins/schema.rb +0 -80
  468. data/lib/sequel/plugins/scissors.rb +0 -33
  469. data/spec/adapters/db2_spec.rb +0 -160
  470. data/spec/adapters/firebird_spec.rb +0 -411
  471. data/spec/adapters/informix_spec.rb +0 -100
  472. data/spec/adapters/mssql_spec.rb +0 -706
  473. data/spec/adapters/mysql_spec.rb +0 -1287
  474. data/spec/adapters/oracle_spec.rb +0 -313
  475. data/spec/adapters/postgres_spec.rb +0 -3725
  476. data/spec/adapters/spec_helper.rb +0 -43
  477. data/spec/adapters/sqlanywhere_spec.rb +0 -170
  478. data/spec/adapters/sqlite_spec.rb +0 -653
  479. data/spec/bin_spec.rb +0 -254
  480. data/spec/core/connection_pool_spec.rb +0 -1016
  481. data/spec/core/database_spec.rb +0 -2531
  482. data/spec/core/dataset_spec.rb +0 -5098
  483. data/spec/core/deprecated_spec.rb +0 -70
  484. data/spec/core/expression_filters_spec.rb +0 -1243
  485. data/spec/core/mock_adapter_spec.rb +0 -462
  486. data/spec/core/object_graph_spec.rb +0 -303
  487. data/spec/core/placeholder_literalizer_spec.rb +0 -163
  488. data/spec/core/schema_generator_spec.rb +0 -179
  489. data/spec/core/schema_spec.rb +0 -1659
  490. data/spec/core/spec_helper.rb +0 -34
  491. data/spec/core/version_spec.rb +0 -7
  492. data/spec/core_extensions_spec.rb +0 -699
  493. data/spec/extensions/accessed_columns_spec.rb +0 -51
  494. data/spec/extensions/active_model_spec.rb +0 -123
  495. data/spec/extensions/after_initialize_spec.rb +0 -24
  496. data/spec/extensions/arbitrary_servers_spec.rb +0 -109
  497. data/spec/extensions/association_dependencies_spec.rb +0 -117
  498. data/spec/extensions/association_pks_spec.rb +0 -365
  499. data/spec/extensions/association_proxies_spec.rb +0 -86
  500. data/spec/extensions/auto_validations_spec.rb +0 -192
  501. data/spec/extensions/blacklist_security_spec.rb +0 -88
  502. data/spec/extensions/blank_spec.rb +0 -69
  503. data/spec/extensions/boolean_readers_spec.rb +0 -93
  504. data/spec/extensions/caching_spec.rb +0 -270
  505. data/spec/extensions/class_table_inheritance_spec.rb +0 -420
  506. data/spec/extensions/column_conflicts_spec.rb +0 -60
  507. data/spec/extensions/column_select_spec.rb +0 -108
  508. data/spec/extensions/columns_introspection_spec.rb +0 -91
  509. data/spec/extensions/composition_spec.rb +0 -242
  510. data/spec/extensions/connection_validator_spec.rb +0 -120
  511. data/spec/extensions/constraint_validations_plugin_spec.rb +0 -274
  512. data/spec/extensions/constraint_validations_spec.rb +0 -325
  513. data/spec/extensions/core_refinements_spec.rb +0 -519
  514. data/spec/extensions/csv_serializer_spec.rb +0 -173
  515. data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
  516. data/spec/extensions/dataset_associations_spec.rb +0 -311
  517. data/spec/extensions/dataset_source_alias_spec.rb +0 -51
  518. data/spec/extensions/date_arithmetic_spec.rb +0 -150
  519. data/spec/extensions/defaults_setter_spec.rb +0 -101
  520. data/spec/extensions/delay_add_association_spec.rb +0 -52
  521. data/spec/extensions/dirty_spec.rb +0 -180
  522. data/spec/extensions/eager_each_spec.rb +0 -42
  523. data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
  524. data/spec/extensions/error_splitter_spec.rb +0 -18
  525. data/spec/extensions/error_sql_spec.rb +0 -20
  526. data/spec/extensions/eval_inspect_spec.rb +0 -73
  527. data/spec/extensions/filter_having_spec.rb +0 -40
  528. data/spec/extensions/force_encoding_spec.rb +0 -114
  529. data/spec/extensions/from_block_spec.rb +0 -21
  530. data/spec/extensions/graph_each_spec.rb +0 -109
  531. data/spec/extensions/hash_aliases_spec.rb +0 -24
  532. data/spec/extensions/hook_class_methods_spec.rb +0 -429
  533. data/spec/extensions/inflector_spec.rb +0 -183
  534. data/spec/extensions/input_transformer_spec.rb +0 -54
  535. data/spec/extensions/insert_returning_select_spec.rb +0 -46
  536. data/spec/extensions/instance_filters_spec.rb +0 -79
  537. data/spec/extensions/instance_hooks_spec.rb +0 -276
  538. data/spec/extensions/inverted_subsets_spec.rb +0 -33
  539. data/spec/extensions/json_serializer_spec.rb +0 -291
  540. data/spec/extensions/lazy_attributes_spec.rb +0 -170
  541. data/spec/extensions/list_spec.rb +0 -267
  542. data/spec/extensions/looser_typecasting_spec.rb +0 -43
  543. data/spec/extensions/many_through_many_spec.rb +0 -2172
  544. data/spec/extensions/meta_def_spec.rb +0 -21
  545. data/spec/extensions/migration_spec.rb +0 -712
  546. data/spec/extensions/modification_detection_spec.rb +0 -80
  547. data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -91
  548. data/spec/extensions/named_timezones_spec.rb +0 -108
  549. data/spec/extensions/nested_attributes_spec.rb +0 -697
  550. data/spec/extensions/null_dataset_spec.rb +0 -85
  551. data/spec/extensions/optimistic_locking_spec.rb +0 -128
  552. data/spec/extensions/pagination_spec.rb +0 -118
  553. data/spec/extensions/pg_array_associations_spec.rb +0 -736
  554. data/spec/extensions/pg_array_ops_spec.rb +0 -143
  555. data/spec/extensions/pg_array_spec.rb +0 -395
  556. data/spec/extensions/pg_enum_spec.rb +0 -92
  557. data/spec/extensions/pg_hstore_ops_spec.rb +0 -236
  558. data/spec/extensions/pg_hstore_spec.rb +0 -206
  559. data/spec/extensions/pg_inet_ops_spec.rb +0 -101
  560. data/spec/extensions/pg_inet_spec.rb +0 -52
  561. data/spec/extensions/pg_interval_spec.rb +0 -76
  562. data/spec/extensions/pg_json_ops_spec.rb +0 -229
  563. data/spec/extensions/pg_json_spec.rb +0 -218
  564. data/spec/extensions/pg_loose_count_spec.rb +0 -17
  565. data/spec/extensions/pg_range_ops_spec.rb +0 -58
  566. data/spec/extensions/pg_range_spec.rb +0 -404
  567. data/spec/extensions/pg_row_ops_spec.rb +0 -60
  568. data/spec/extensions/pg_row_plugin_spec.rb +0 -62
  569. data/spec/extensions/pg_row_spec.rb +0 -360
  570. data/spec/extensions/pg_static_cache_updater_spec.rb +0 -92
  571. data/spec/extensions/pg_typecast_on_load_spec.rb +0 -63
  572. data/spec/extensions/prepared_statements_associations_spec.rb +0 -159
  573. data/spec/extensions/prepared_statements_safe_spec.rb +0 -61
  574. data/spec/extensions/prepared_statements_spec.rb +0 -103
  575. data/spec/extensions/prepared_statements_with_pk_spec.rb +0 -31
  576. data/spec/extensions/pretty_table_spec.rb +0 -92
  577. data/spec/extensions/query_literals_spec.rb +0 -183
  578. data/spec/extensions/query_spec.rb +0 -102
  579. data/spec/extensions/rcte_tree_spec.rb +0 -392
  580. data/spec/extensions/round_timestamps_spec.rb +0 -43
  581. data/spec/extensions/schema_caching_spec.rb +0 -41
  582. data/spec/extensions/schema_dumper_spec.rb +0 -789
  583. data/spec/extensions/schema_spec.rb +0 -117
  584. data/spec/extensions/scissors_spec.rb +0 -26
  585. data/spec/extensions/select_remove_spec.rb +0 -38
  586. data/spec/extensions/sequel_3_dataset_methods_spec.rb +0 -101
  587. data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
  588. data/spec/extensions/serialization_spec.rb +0 -362
  589. data/spec/extensions/server_block_spec.rb +0 -90
  590. data/spec/extensions/set_overrides_spec.rb +0 -61
  591. data/spec/extensions/sharding_spec.rb +0 -198
  592. data/spec/extensions/shared_caching_spec.rb +0 -175
  593. data/spec/extensions/single_table_inheritance_spec.rb +0 -297
  594. data/spec/extensions/singular_table_names_spec.rb +0 -22
  595. data/spec/extensions/skip_create_refresh_spec.rb +0 -17
  596. data/spec/extensions/spec_helper.rb +0 -71
  597. data/spec/extensions/split_array_nil_spec.rb +0 -24
  598. data/spec/extensions/split_values_spec.rb +0 -22
  599. data/spec/extensions/sql_expr_spec.rb +0 -60
  600. data/spec/extensions/static_cache_spec.rb +0 -361
  601. data/spec/extensions/string_date_time_spec.rb +0 -95
  602. data/spec/extensions/string_stripper_spec.rb +0 -68
  603. data/spec/extensions/subclasses_spec.rb +0 -66
  604. data/spec/extensions/table_select_spec.rb +0 -71
  605. data/spec/extensions/tactical_eager_loading_spec.rb +0 -82
  606. data/spec/extensions/thread_local_timezones_spec.rb +0 -67
  607. data/spec/extensions/timestamps_spec.rb +0 -175
  608. data/spec/extensions/to_dot_spec.rb +0 -154
  609. data/spec/extensions/touch_spec.rb +0 -203
  610. data/spec/extensions/tree_spec.rb +0 -274
  611. data/spec/extensions/typecast_on_load_spec.rb +0 -80
  612. data/spec/extensions/unlimited_update_spec.rb +0 -20
  613. data/spec/extensions/update_or_create_spec.rb +0 -87
  614. data/spec/extensions/update_primary_key_spec.rb +0 -100
  615. data/spec/extensions/update_refresh_spec.rb +0 -53
  616. data/spec/extensions/validate_associated_spec.rb +0 -52
  617. data/spec/extensions/validation_class_methods_spec.rb +0 -1027
  618. data/spec/extensions/validation_helpers_spec.rb +0 -541
  619. data/spec/extensions/xml_serializer_spec.rb +0 -207
  620. data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
  621. data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
  622. data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  623. data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  624. data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
  625. data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
  626. data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
  627. data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
  628. data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
  629. data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
  630. data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
  631. data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
  632. data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
  633. data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
  634. data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  635. data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
  636. data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
  637. data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
  638. data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
  639. data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
  640. data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  641. data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
  642. data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  643. data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
  644. data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  645. data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
  646. data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
  647. data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  648. data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  649. data/spec/files/reversible_migrations/001_reversible.rb +0 -5
  650. data/spec/files/reversible_migrations/002_reversible.rb +0 -5
  651. data/spec/files/reversible_migrations/003_reversible.rb +0 -5
  652. data/spec/files/reversible_migrations/004_reversible.rb +0 -5
  653. data/spec/files/reversible_migrations/005_reversible.rb +0 -10
  654. data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
  655. data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
  656. data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
  657. data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
  658. data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
  659. data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
  660. data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
  661. data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
  662. data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
  663. data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
  664. data/spec/guards_helper.rb +0 -55
  665. data/spec/integration/associations_test.rb +0 -2454
  666. data/spec/integration/database_test.rb +0 -113
  667. data/spec/integration/dataset_test.rb +0 -1808
  668. data/spec/integration/eager_loader_test.rb +0 -687
  669. data/spec/integration/migrator_test.rb +0 -240
  670. data/spec/integration/model_test.rb +0 -226
  671. data/spec/integration/plugin_test.rb +0 -2240
  672. data/spec/integration/prepared_statement_test.rb +0 -467
  673. data/spec/integration/schema_test.rb +0 -817
  674. data/spec/integration/spec_helper.rb +0 -48
  675. data/spec/integration/timezone_test.rb +0 -86
  676. data/spec/integration/transaction_test.rb +0 -374
  677. data/spec/integration/type_test.rb +0 -133
  678. data/spec/model/association_reflection_spec.rb +0 -525
  679. data/spec/model/associations_spec.rb +0 -4426
  680. data/spec/model/base_spec.rb +0 -759
  681. data/spec/model/class_dataset_methods_spec.rb +0 -146
  682. data/spec/model/dataset_methods_spec.rb +0 -149
  683. data/spec/model/eager_loading_spec.rb +0 -2137
  684. data/spec/model/hooks_spec.rb +0 -604
  685. data/spec/model/inflector_spec.rb +0 -26
  686. data/spec/model/model_spec.rb +0 -982
  687. data/spec/model/plugins_spec.rb +0 -299
  688. data/spec/model/record_spec.rb +0 -2147
  689. data/spec/model/spec_helper.rb +0 -46
  690. data/spec/model/validations_spec.rb +0 -193
  691. data/spec/sequel_coverage.rb +0 -15
  692. data/spec/spec_config.rb +0 -10
@@ -1,5 +0,0 @@
1
- Sequel.migration do
2
- change do
3
- create_table(:a){Integer :a}
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- Sequel.migration do
2
- change do
3
- add_column :a, :b, String
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- Sequel.migration do
2
- change do
3
- rename_column :a, :b, :c
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- Sequel.migration do
2
- change do
3
- rename_table :a, :b
4
- end
5
- end
@@ -1,10 +0,0 @@
1
- Sequel.migration do
2
- change do
3
- alter_table(:b) do
4
- add_column :d, String
5
- end
6
- alter_table(:b) do
7
- rename_column :d, :e
8
- end
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- class CreateSessions < Sequel::Migration
2
- def up
3
- create_table(:sm1111){Integer :smc1}
4
- end
5
-
6
- def down
7
- drop_table(:sm1111)
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- Class.new(Sequel::Migration) do
2
- def up
3
- create_table(:sm2222){Integer :smc2}
4
- end
5
-
6
- def down
7
- drop_table(:sm2222)
8
- end
9
- end
@@ -1,4 +0,0 @@
1
- Sequel.migration do
2
- up{create_table(:sm3333){Integer :smc3}}
3
- down{drop_table(:sm3333)}
4
- end
@@ -1,4 +0,0 @@
1
- Sequel.migration do
2
- transaction
3
- change{create_table(:sm11111){Integer :smc1}}
4
- end
@@ -1,4 +0,0 @@
1
- Sequel.migration do
2
- no_transaction
3
- change{create_table(:sm){Integer :smc1}}
4
- end
@@ -1,3 +0,0 @@
1
- Sequel.migration do
2
- change{create_table(:sm11111){Integer :smc1}}
3
- end
@@ -1,3 +0,0 @@
1
- Sequel.migration do
2
- change{create_table(:sm){Integer :smc1}}
3
- end
@@ -1,9 +0,0 @@
1
- class CreateSessions < Sequel::Migration
2
- def up
3
- create_table(:sm1111){Integer :smc1}
4
- end
5
-
6
- def down
7
- drop_table(:sm1111)
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- Class.new(Sequel::Migration) do
2
- def up
3
- create_table(:sm2222){Integer :smc2}
4
- end
5
-
6
- def down
7
- drop_table(:sm2222)
8
- end
9
- end
@@ -1,4 +0,0 @@
1
- Sequel.migration do
2
- up{create_table(:sm3333){Integer :smc3}}
3
- down{drop_table(:sm3333)}
4
- end
@@ -1,55 +0,0 @@
1
- gem 'minitest'
2
- require 'minitest/autorun'
3
- require 'minitest/hooks/default'
4
- require 'minitest/shared_description'
5
-
6
- def Sequel.guarded?(*checked)
7
- unless ENV['SEQUEL_NO_PENDING']
8
- checked.each do |c|
9
- case c
10
- when DB.database_type
11
- return c
12
- when Array
13
- case c.length
14
- when 1
15
- return c if c.first == DB.adapter_scheme
16
- when 2
17
- if c.first.is_a?(Proc)
18
- return c if c.last == DB.database_type && c.first.call(DB)
19
- elsif c.last.is_a?(Proc)
20
- return c if c.first == DB.adapter_scheme && c.last.call(DB)
21
- else
22
- return c if c.first == DB.adapter_scheme && c.last == DB.database_type
23
- end
24
- when 3
25
- return c if c[0] == DB.adapter_scheme && c[1] == DB.database_type && c[2].call(DB)
26
- end
27
- end
28
- end
29
- end
30
- false
31
- end
32
-
33
- module Minitest::Spec::DSL
34
- def cspecify(message, *checked, &block)
35
- if pending = Sequel.guarded?(*checked)
36
- it(message) do
37
- skip "Not yet working on #{Array(pending).map{|x| x.is_a?(Proc) ? :proc : x}.join(', ')}"
38
- end
39
- else
40
- it(message, &block)
41
- end
42
- end
43
- end
44
-
45
- class Minitest::HooksSpec
46
- def log
47
- begin
48
- DB.loggers << Logger.new(STDOUT)
49
- yield
50
- ensure
51
- DB.loggers.pop
52
- end
53
- end
54
- end
55
-
@@ -1,2454 +0,0 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
2
-
3
- OneToOneEagerLimitStrategies = shared_description do
4
- it "eager loading one_to_one associations should work correctly" do
5
- Artist.one_to_one :first_album, {:clone=>:first_album}.merge(@els) if @els
6
- Artist.one_to_one :last_album, {:clone=>:last_album}.merge(@els) if @els
7
- Artist.one_to_one :second_album, {:clone=>:second_album}.merge(@els) if @els && @els[:eager_limit_strategy] != :distinct_on
8
- @album.update(:artist => @artist)
9
- diff_album = @diff_album.call
10
- ar = @pr.call[1]
11
-
12
- a = Artist.eager(:first_album, :last_album, :second_album).order(:name).all
13
- a.must_equal [@artist, ar]
14
- a.first.first_album.must_equal @album
15
- a.first.last_album.must_equal diff_album
16
- a.first.second_album.must_equal diff_album
17
- a.last.first_album.must_equal nil
18
- a.last.last_album.must_equal nil
19
- a.last.second_album.must_equal nil
20
-
21
- # Check that no extra columns got added by the eager loading
22
- a.first.first_album.values.must_equal @album.values
23
- a.first.last_album.values.must_equal diff_album.values
24
- a.first.second_album.values.must_equal diff_album.values
25
-
26
- same_album = @same_album.call
27
- a = Artist.eager(:first_album).order(:name).all
28
- a.must_equal [@artist, ar]
29
- [@album, same_album].must_include(a.first.first_album)
30
- a.last.first_album.must_equal nil
31
- end
32
- end
33
-
34
- OneToOneEagerGraphLimitStrategies = shared_description do
35
- it "eager graphing one_to_one associations should work correctly" do
36
- @album.update(:artist => @artist)
37
- diff_album = @diff_album.call
38
- ar = @pr.call[1]
39
- ds = Artist.order(:artists__name)
40
- limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
41
-
42
- a = ds.eager_graph_with_options(:first_album, limit_strategy).all
43
- a.must_equal [@artist, ar]
44
- a.first.first_album.must_equal @album
45
- a.last.first_album.must_equal nil
46
- a.first.first_album.values.must_equal @album.values
47
-
48
- a = ds.eager_graph_with_options(:last_album, limit_strategy).all
49
- a = ds.eager_graph(:last_album).all
50
- a.must_equal [@artist, ar]
51
- a.first.last_album.must_equal diff_album
52
- a.last.last_album.must_equal nil
53
- a.first.last_album.values.must_equal diff_album.values
54
-
55
- if @els[:eager_limit_strategy] != :distinct_on && (@els[:eager_limit_strategy] != :correlated_subquery || Album.dataset.supports_offsets_in_correlated_subqueries?)
56
- a = ds.eager_graph_with_options(:second_album, limit_strategy).all
57
- a = ds.eager_graph(:second_album).all
58
- a.must_equal [@artist, ar]
59
- a.first.second_album.must_equal diff_album
60
- a.last.second_album.must_equal nil
61
- a.first.second_album.values.must_equal diff_album.values
62
- end
63
-
64
- same_album = @same_album.call
65
- a = ds.eager_graph_with_options(:first_album, limit_strategy).all
66
- a.must_equal [@artist, ar]
67
- [@album, same_album].must_include(a.first.first_album)
68
- a.last.first_album.must_equal nil
69
- end
70
- end
71
-
72
- OneToManyEagerLimitStrategies = shared_description do
73
- it "should correctly handle limits and offsets when eager loading one_to_many associations" do
74
- Artist.one_to_many :first_two_albums, {:clone=>:first_two_albums}.merge(@els) if @els
75
- Artist.one_to_many :second_two_albums, {:clone=>:second_two_albums}.merge(@els) if @els
76
- Artist.one_to_many :not_first_albums, {:clone=>:not_first_albums}.merge(@els) if @els
77
- Artist.one_to_many :last_two_albums, {:clone=>:last_two_albums}.merge(@els) if @els
78
- @album.update(:artist => @artist)
79
- middle_album = @middle_album.call
80
- diff_album = @diff_album.call
81
- ar = @pr.call[1]
82
-
83
- ars = Artist.eager(:first_two_albums, :second_two_albums, :not_first_albums, :last_two_albums).order(:name).all
84
- ars.must_equal [@artist, ar]
85
- ars.first.first_two_albums.must_equal [@album, middle_album]
86
- ars.first.second_two_albums.must_equal [middle_album, diff_album]
87
- ars.first.not_first_albums.must_equal [middle_album, diff_album]
88
- ars.first.last_two_albums.must_equal [diff_album, middle_album]
89
- ars.last.first_two_albums.must_equal []
90
- ars.last.second_two_albums.must_equal []
91
- ars.last.not_first_albums.must_equal []
92
- ars.last.last_two_albums.must_equal []
93
-
94
- # Check that no extra columns got added by the eager loading
95
- ars.first.first_two_albums.map{|x| x.values}.must_equal [@album, middle_album].map{|x| x.values}
96
- ars.first.second_two_albums.map{|x| x.values}.must_equal [middle_album, diff_album].map{|x| x.values}
97
- ars.first.not_first_albums.map{|x| x.values}.must_equal [middle_album, diff_album].map{|x| x.values}
98
- ars.first.last_two_albums.map{|x| x.values}.must_equal [diff_album, middle_album].map{|x| x.values}
99
- end
100
- end
101
-
102
- OneToManyEagerGraphLimitStrategies = shared_description do
103
- it "should correctly handle limits and offsets when eager graphing one_to_many associations" do
104
- @album.update(:artist => @artist)
105
- middle_album = @middle_album.call
106
- diff_album = @diff_album.call
107
- ar = @pr.call[1]
108
- ds = Artist.order(:artists__name)
109
- limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
110
-
111
- ars = ds.eager_graph_with_options(:first_two_albums, limit_strategy).all
112
- ars.must_equal [@artist, ar]
113
- ars.first.first_two_albums.must_equal [@album, middle_album]
114
- ars.last.first_two_albums.must_equal []
115
- ars.first.first_two_albums.map{|x| x.values}.must_equal [@album, middle_album].map{|x| x.values}
116
-
117
- if @els[:eager_limit_strategy] != :correlated_subquery || Album.dataset.supports_offsets_in_correlated_subqueries?
118
- ars = ds.eager_graph_with_options(:second_two_albums, limit_strategy).all
119
- ars.must_equal [@artist, ar]
120
- ars.first.second_two_albums.must_equal [middle_album, diff_album]
121
- ars.last.second_two_albums.must_equal []
122
- ars.first.second_two_albums.map{|x| x.values}.must_equal [middle_album, diff_album].map{|x| x.values}
123
-
124
- ars = ds.eager_graph_with_options(:not_first_albums, limit_strategy).all
125
- ars.must_equal [@artist, ar]
126
- ars.first.not_first_albums.must_equal [middle_album, diff_album]
127
- ars.last.not_first_albums.must_equal []
128
- ars.first.not_first_albums.map{|x| x.values}.must_equal [middle_album, diff_album].map{|x| x.values}
129
- end
130
-
131
- ars = ds.eager_graph_with_options(:last_two_albums, limit_strategy).all
132
- ars.must_equal [@artist, ar]
133
- ars.first.last_two_albums.must_equal [diff_album, middle_album]
134
- ars.last.last_two_albums.must_equal []
135
- ars.first.last_two_albums.map{|x| x.values}.must_equal [diff_album, middle_album].map{|x| x.values}
136
- end
137
- end
138
-
139
- OneThroughOneEagerLimitStrategies = shared_description do
140
- it "should correctly handle offsets when eager loading one_through_one associations" do
141
- Album.one_through_one :first_tag, {:clone=>:first_tag}.merge(@els) if @els
142
- Album.one_through_one :second_tag, {:clone=>:second_tag}.merge(@els) if @els && @els[:eager_limit_strategy] != :distinct_on
143
- Album.one_through_one :last_tag, {:clone=>:last_tag}.merge(@els) if @els
144
- tu, tv = @other_tags.call
145
- al = @pr.call.first
146
-
147
- als = Album.eager(:first_tag, :second_tag, :last_tag).order(:name).all
148
- als.must_equal [@album, al]
149
- als.first.first_tag.must_equal @tag
150
- als.first.second_tag.must_equal tu
151
- als.first.last_tag.must_equal tv
152
- als.last.first_tag.must_equal nil
153
- als.last.second_tag.must_equal nil
154
- als.last.last_tag.must_equal nil
155
-
156
- # Check that no extra columns got added by the eager loading
157
- als.first.first_tag.values.must_equal @tag.values
158
- als.first.second_tag.values.must_equal tu.values
159
- als.first.last_tag.values.must_equal tv.values
160
- end
161
- end
162
-
163
- OneThroughOneEagerGraphLimitStrategies = shared_description do
164
- it "should correctly handle offsets when eager graphing one_through_one associations" do
165
- tu, tv = @other_tags.call
166
- al = @pr.call.first
167
- ds = Album.order(:albums__name)
168
- limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
169
-
170
- als = ds.eager_graph_with_options(:first_tag, limit_strategy).all
171
- als.must_equal [@album, al]
172
- als.first.first_tag.must_equal @tag
173
- als.last.first_tag.must_equal nil
174
- als.first.first_tag.values.must_equal @tag.values
175
-
176
- als = ds.eager_graph_with_options(:second_tag, @els[:eager_limit_strategy] != :distinct_on ? limit_strategy : {}).all
177
- als.must_equal [@album, al]
178
- als.first.second_tag.must_equal tu
179
- als.last.second_tag.must_equal nil
180
- als.first.second_tag.values.must_equal tu.values
181
-
182
- als = ds.eager_graph_with_options(:last_tag, limit_strategy).all
183
- als.must_equal [@album, al]
184
- als.first.last_tag.must_equal tv
185
- als.last.last_tag.must_equal nil
186
- als.first.last_tag.values.must_equal tv.values
187
- end
188
- end
189
-
190
- ManyToManyEagerLimitStrategies = shared_description do
191
- it "should correctly handle limits and offsets when eager loading many_to_many associations" do
192
- Album.send @many_to_many_method||:many_to_many, :first_two_tags, {:clone=>:first_two_tags}.merge(@els) if @els
193
- Album.send @many_to_many_method||:many_to_many, :second_two_tags, {:clone=>:second_two_tags}.merge(@els) if @els
194
- Album.send @many_to_many_method||:many_to_many, :not_first_tags, {:clone=>:not_first_tags}.merge(@els) if @els
195
- Album.send @many_to_many_method||:many_to_many, :last_two_tags, {:clone=>:last_two_tags}.merge(@els) if @els
196
- tu, tv = @other_tags.call
197
- al = @pr.call.first
198
- al.add_tag(tu)
199
-
200
- als = Album.eager(:first_two_tags, :second_two_tags, :not_first_tags, :last_two_tags).order(:name).all
201
- als.must_equal [@album, al]
202
- als.first.first_two_tags.must_equal [@tag, tu]
203
- als.first.second_two_tags.must_equal [tu, tv]
204
- als.first.not_first_tags.must_equal [tu, tv]
205
- als.first.last_two_tags.must_equal [tv, tu]
206
- als.last.first_two_tags.must_equal [tu]
207
- als.last.second_two_tags.must_equal []
208
- als.last.last_two_tags.must_equal [tu]
209
-
210
- # Check that no extra columns got added by the eager loading
211
- als.first.first_two_tags.map{|x| x.values}.must_equal [@tag, tu].map{|x| x.values}
212
- als.first.second_two_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
213
- als.first.not_first_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
214
- als.first.last_two_tags.map{|x| x.values}.must_equal [tv, tu].map{|x| x.values}
215
- end
216
- end
217
-
218
- ManyToManyEagerGraphLimitStrategies = shared_description do
219
- it "should correctly handle limits and offsets when eager loading many_to_many associations" do
220
- tu, tv = @other_tags.call
221
- al = @pr.call.first
222
- al.add_tag(tu)
223
- ds = Album.order(:albums__name)
224
- limit_strategy = {:limit_strategy=>(@els||{})[:eager_limit_strategy]}
225
-
226
- als = ds.eager_graph_with_options(:first_two_tags, limit_strategy).all
227
- als.must_equal [@album, al]
228
- als.first.first_two_tags.must_equal [@tag, tu]
229
- als.last.first_two_tags.must_equal [tu]
230
- als.first.first_two_tags.map{|x| x.values}.must_equal [@tag, tu].map{|x| x.values}
231
-
232
- als = ds.eager_graph_with_options(:second_two_tags, limit_strategy).all
233
- als.must_equal [@album, al]
234
- als.first.second_two_tags.must_equal [tu, tv]
235
- als.last.second_two_tags.must_equal []
236
- als.first.second_two_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
237
-
238
- als = ds.eager_graph_with_options(:not_first_tags, limit_strategy).all
239
- als.must_equal [@album, al]
240
- als.first.not_first_tags.must_equal [tu, tv]
241
- als.last.not_first_tags.must_equal []
242
- als.first.not_first_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
243
-
244
- als = ds.eager_graph_with_options(:last_two_tags, limit_strategy).all
245
- als.must_equal [@album, al]
246
- als.first.last_two_tags.must_equal [tv, tu]
247
- als.last.last_two_tags.must_equal [tu]
248
- als.first.last_two_tags.map{|x| x.values}.must_equal [tv, tu].map{|x| x.values}
249
- end
250
- end
251
-
252
- ManyThroughManyEagerLimitStrategies = shared_description do
253
- it "should correctly handle limits and offsets when eager loading many_through_many associations" do
254
- Artist.many_through_many :first_two_tags, {:clone=>:first_two_tags}.merge(@els) if @els
255
- Artist.many_through_many :second_two_tags, {:clone=>:second_two_tags}.merge(@els) if @els
256
- Artist.many_through_many :not_first_tags, {:clone=>:not_first_tags}.merge(@els) if @els
257
- Artist.many_through_many :last_two_tags, {:clone=>:last_two_tags}.merge(@els) if @els
258
- @album.update(:artist => @artist)
259
- tu, tv = @other_tags.call
260
- al, ar, _ = @pr.call
261
- al.update(:artist=>ar)
262
- al.add_tag(tu)
263
-
264
- ars = Artist.eager(:first_two_tags, :second_two_tags, :not_first_tags, :last_two_tags).order(:name).all
265
- ars.must_equal [@artist, ar]
266
- ars.first.first_two_tags.must_equal [@tag, tu]
267
- ars.first.second_two_tags.must_equal [tu, tv]
268
- ars.first.not_first_tags.must_equal [tu, tv]
269
- ars.first.last_two_tags.must_equal [tv, tu]
270
- ars.last.first_two_tags.must_equal [tu]
271
- ars.last.second_two_tags.must_equal []
272
- ars.last.not_first_tags.must_equal []
273
- ars.last.last_two_tags.must_equal [tu]
274
-
275
- # Check that no extra columns got added by the eager loading
276
- ars.first.first_two_tags.map{|x| x.values}.must_equal [@tag, tu].map{|x| x.values}
277
- ars.first.second_two_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
278
- ars.first.not_first_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
279
- ars.first.last_two_tags.map{|x| x.values}.must_equal [tv, tu].map{|x| x.values}
280
- end
281
- end
282
-
283
- ManyThroughManyEagerGraphLimitStrategies = shared_description do
284
- it "should correctly handle limits and offsets when eager loading many_through_many associations" do
285
- @album.update(:artist => @artist)
286
- tu, tv = @other_tags.call
287
- al, ar, _ = @pr.call
288
- al.update(:artist=>ar)
289
- al.add_tag(tu)
290
- ds = Artist.order(:artists__name)
291
- limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
292
-
293
- ars = ds.eager_graph_with_options(:first_two_tags, limit_strategy).all
294
- ars.must_equal [@artist, ar]
295
- ars.first.first_two_tags.must_equal [@tag, tu]
296
- ars.last.first_two_tags.must_equal [tu]
297
- ars.first.first_two_tags.map{|x| x.values}.must_equal [@tag, tu].map{|x| x.values}
298
-
299
- ars = ds.eager_graph_with_options(:second_two_tags, limit_strategy).all
300
- ars.must_equal [@artist, ar]
301
- ars.first.second_two_tags.must_equal [tu, tv]
302
- ars.last.second_two_tags.must_equal []
303
- ars.first.second_two_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
304
-
305
- ars = ds.eager_graph_with_options(:not_first_tags, limit_strategy).all
306
- ars.must_equal [@artist, ar]
307
- ars.first.not_first_tags.must_equal [tu, tv]
308
- ars.last.not_first_tags.must_equal []
309
- ars.first.not_first_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
310
-
311
- ars = ds.eager_graph_with_options(:last_two_tags, limit_strategy).all
312
- ars.must_equal [@artist, ar]
313
- ars.first.last_two_tags.must_equal [tv, tu]
314
- ars.last.last_two_tags.must_equal [tu]
315
- ars.first.last_two_tags.map{|x| x.values}.must_equal [tv, tu].map{|x| x.values}
316
- end
317
- end
318
-
319
- OneThroughManyEagerLimitStrategies = shared_description do
320
- it "should correctly handle offsets when eager loading one_through_many associations" do
321
- Artist.one_through_many :first_tag, {:clone=>:first_tag}.merge(@els) if @els
322
- Artist.one_through_many :second_tag, {:clone=>:second_tag}.merge(@els) if @els && @els[:eager_limit_strategy] != :distinct_on
323
- Artist.one_through_many :last_tag, {:clone=>:last_tag}.merge(@els) if @els
324
- @album.update(:artist => @artist)
325
- tu, tv = @other_tags.call
326
- al, ar, _ = @pr.call
327
- al.update(:artist=>ar)
328
- al.add_tag(tu)
329
-
330
- ars = Artist.eager(:first_tag, :second_tag, :last_tag).order(:name).all
331
- ars.must_equal [@artist, ar]
332
- ars.first.first_tag.must_equal @tag
333
- ars.first.second_tag.must_equal tu
334
- ars.first.last_tag.must_equal tv
335
- ars.last.first_tag.must_equal tu
336
- ars.last.second_tag.must_equal nil
337
- ars.last.last_tag.must_equal tu
338
-
339
- # Check that no extra columns got added by the eager loading
340
- ars.first.first_tag.values.must_equal @tag.values
341
- ars.first.second_tag.values.must_equal tu.values
342
- ars.first.last_tag.values.must_equal tv.values
343
- end
344
- end
345
-
346
- OneThroughManyEagerGraphLimitStrategies = shared_description do
347
- it "should correctly handle offsets when eager graphing one_through_many associations" do
348
- @album.update(:artist => @artist)
349
- tu, tv = @other_tags.call
350
- al, ar, _ = @pr.call
351
- al.update(:artist=>ar)
352
- al.add_tag(tu)
353
- ds = Artist.order(:artists__name)
354
- limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
355
-
356
- ars = ds.eager_graph_with_options(:first_tag, limit_strategy).all
357
- ars.must_equal [@artist, ar]
358
- ars.first.first_tag.must_equal @tag
359
- ars.last.first_tag.must_equal tu
360
- ars.first.first_tag.values.must_equal @tag.values
361
-
362
- ars = ds.eager_graph_with_options(:second_tag, @els[:eager_limit_strategy] != :distinct_on ? limit_strategy : {}).all
363
- ars.must_equal [@artist, ar]
364
- ars.first.second_tag.must_equal tu
365
- ars.last.second_tag.must_equal nil
366
- ars.first.second_tag.values.must_equal tu.values
367
-
368
- ars = ds.eager_graph_with_options(:last_tag, limit_strategy).all
369
- ars.must_equal [@artist, ar]
370
- ars.first.last_tag.must_equal tv
371
- ars.last.last_tag.must_equal tu
372
- ars.first.last_tag.values.must_equal tv.values
373
- end
374
- end
375
-
376
- EagerLimitStrategies = shared_description do
377
- include OneToOneEagerLimitStrategies
378
- include OneToManyEagerLimitStrategies
379
- include ManyToManyEagerLimitStrategies
380
- include OneThroughOneEagerLimitStrategies
381
- include ManyThroughManyEagerLimitStrategies
382
- include OneThroughManyEagerLimitStrategies
383
- end
384
-
385
- EagerGraphLimitStrategies = shared_description do
386
- include OneToOneEagerGraphLimitStrategies
387
- include OneToManyEagerGraphLimitStrategies
388
- include ManyToManyEagerGraphLimitStrategies
389
- include OneThroughOneEagerGraphLimitStrategies
390
- include ManyThroughManyEagerGraphLimitStrategies
391
- include OneThroughManyEagerGraphLimitStrategies
392
- end
393
-
394
- FilterByAssociations = shared_description do
395
- it "should handle association inner joins" do
396
- @Artist.association_join(:albums).all.must_equal []
397
- @Artist.association_join(:first_album).all.must_equal []
398
- @Album.association_join(:artist).all.must_equal []
399
- @Album.association_join(:tags).all.must_equal []
400
- @Album.association_join(:alias_tags).all.must_equal []
401
- @Tag.association_join(:albums).all.must_equal []
402
- unless @no_many_through_many
403
- @Artist.association_join(:tags).all.must_equal []
404
- @Artist.association_join(:first_tag).all.must_equal []
405
- end
406
-
407
- @album.update(:artist => @artist)
408
- @album.add_tag(@tag)
409
-
410
- @Artist.association_join(:albums).select_all(:artists).all.must_equal [@artist]
411
- @Artist.association_join(:first_album).select_all(:artists).all.must_equal [@artist]
412
- @Album.association_join(:artist).select_all(:albums).all.must_equal [@album]
413
- @Album.association_join(:tags).select_all(:albums).all.must_equal [@album]
414
- @Album.association_join(:alias_tags).select_all(:albums).all.must_equal [@album]
415
- @Tag.association_join(:albums).select_all(:tags).all.must_equal [@tag]
416
- unless @no_many_through_many
417
- @Artist.association_join(:tags).select_all(:artists).all.must_equal [@artist]
418
- @Artist.association_join(:first_tag).select_all(:artists).all.must_equal [@artist]
419
- end
420
-
421
- @Artist.association_join(:albums).select_all(:albums).naked.all.must_equal [@album.values]
422
- @Artist.association_join(:first_album).select_all(:first_album).naked.all.must_equal [@album.values]
423
- @Album.association_join(:artist).select_all(:artist).naked.all.must_equal [@artist.values]
424
- @Album.association_join(:tags).select_all(:tags).naked.all.must_equal [@tag.values]
425
- @Album.association_join(:alias_tags).select_all(:alias_tags).naked.all.must_equal [@tag.values]
426
- @Tag.association_join(:albums).select_all(:albums).naked.all.must_equal [@album.values]
427
- unless @no_many_through_many
428
- @Artist.association_join(:tags).select_all(:tags).naked.all.must_equal [@tag.values]
429
- @Artist.association_join(:first_tag).select_all(:first_tag).naked.all.must_equal [@tag.values]
430
- end
431
- end
432
-
433
- it "should handle association left joins" do
434
- @Artist.association_left_join(:albums).select_all(:artists).all.must_equal [@artist]
435
- @Artist.association_left_join(:first_album).select_all(:artists).all.must_equal [@artist]
436
- @Album.association_left_join(:artist).select_all(:albums).all.must_equal [@album]
437
- @Album.association_left_join(:tags).select_all(:albums).all.must_equal [@album]
438
- @Album.association_left_join(:alias_tags).select_all(:albums).all.must_equal [@album]
439
- @Tag.association_left_join(:albums).select_all(:tags).all.must_equal [@tag]
440
- unless @no_many_through_many
441
- @Artist.association_left_join(:tags).select_all(:artists).all.must_equal [@artist]
442
- @Artist.association_left_join(:first_tag).select_all(:artists).all.must_equal [@artist]
443
- end
444
-
445
- nil_hash = lambda{|obj| [obj.values.keys.inject({}){|h,k| h[k] = nil; h}]}
446
- @Artist.association_left_join(:albums).select_all(:albums).naked.all.must_equal nil_hash[@album]
447
- @Artist.association_left_join(:first_album).select_all(:first_album).naked.all.must_equal nil_hash[@album]
448
- @Album.association_left_join(:artist).select_all(:artist).naked.all.must_equal nil_hash[@artist]
449
- @Album.association_left_join(:tags).select_all(:tags).naked.all.must_equal nil_hash[@tag]
450
- @Album.association_left_join(:alias_tags).select_all(:alias_tags).naked.all.must_equal nil_hash[@tag]
451
- @Tag.association_left_join(:albums).select_all(:albums).naked.all.must_equal nil_hash[@album]
452
- unless @no_many_through_many
453
- @Artist.association_left_join(:tags).select_all(:tags).naked.all.must_equal nil_hash[@tag]
454
- @Artist.association_left_join(:first_tag).select_all(:first_tag).naked.all.must_equal nil_hash[@tag]
455
- end
456
-
457
- @album.update(:artist => @artist)
458
- @album.add_tag(@tag)
459
-
460
-
461
- @Artist.association_left_join(:albums).select_all(:albums).naked.all.must_equal [@album.values]
462
- @Artist.association_left_join(:first_album).select_all(:first_album).naked.all.must_equal [@album.values]
463
- @Album.association_left_join(:artist).select_all(:artist).naked.all.must_equal [@artist.values]
464
- @Album.association_left_join(:tags).select_all(:tags).naked.all.must_equal [@tag.values]
465
- @Album.association_left_join(:alias_tags).select_all(:alias_tags).naked.all.must_equal [@tag.values]
466
- @Tag.association_left_join(:albums).select_all(:albums).naked.all.must_equal [@album.values]
467
- unless @no_many_through_many
468
- @Artist.association_left_join(:tags).select_all(:tags).naked.all.must_equal [@tag.values]
469
- @Artist.association_left_join(:first_tag).select_all(:first_tag).naked.all.must_equal [@tag.values]
470
- end
471
- end
472
-
473
- it "should work correctly when filtering by associations" do
474
- @album.update(:artist => @artist)
475
- @album.add_tag(@tag)
476
-
477
- @Artist.filter(:albums=>@album).all.must_equal [@artist]
478
- @Artist.filter(:first_album=>@album).all.must_equal [@artist]
479
- unless @no_many_through_many
480
- @Artist.filter(:tags=>@tag).all.must_equal [@artist]
481
- @Artist.filter(:first_tag=>@tag).all.must_equal [@artist]
482
- end
483
- @Album.filter(:artist=>@artist).all.must_equal [@album]
484
- @Album.filter(:tags=>@tag).all.must_equal [@album]
485
- @Album.filter(:alias_tags=>@tag).all.must_equal [@album]
486
- @Tag.filter(:albums=>@album).all.must_equal [@tag]
487
- @Album.filter(:artist=>@artist, :tags=>@tag).all.must_equal [@album]
488
- @artist.albums_dataset.filter(:tags=>@tag).all.must_equal [@album]
489
- end
490
-
491
- it "should work correctly when excluding by associations" do
492
- @album.update(:artist => @artist)
493
- @album.add_tag(@tag)
494
- album, artist, tag = @pr.call
495
-
496
- @Artist.exclude(:albums=>@album).all.must_equal [artist]
497
- @Artist.exclude(:first_album=>@album).all.must_equal [artist]
498
- unless @no_many_through_many
499
- @Artist.exclude(:tags=>@tag).all.must_equal [artist]
500
- @Artist.exclude(:first_tag=>@tag).all.must_equal [artist]
501
- end
502
- @Album.exclude(:artist=>@artist).all.must_equal [album]
503
- @Album.exclude(:tags=>@tag).all.must_equal [album]
504
- @Album.exclude(:alias_tags=>@tag).all.must_equal [album]
505
- @Tag.exclude(:albums=>@album).all.must_equal [tag]
506
- @Album.exclude(:artist=>@artist, :tags=>@tag).all.must_equal [album]
507
- end
508
-
509
- it "should work correctly when filtering by associations with conditions" do
510
- @album.update(:artist => @artist)
511
- @album.add_tag(@tag)
512
-
513
- @Artist.filter(:a_albums=>@album).all.must_equal [@artist]
514
- @Artist.filter(:first_a_album=>@album).all.must_equal [@artist]
515
- @album.update(:name=>'Foo')
516
- @Artist.filter(:a_albums=>@album).all.must_equal []
517
- @Artist.filter(:first_a_album=>@album).all.must_equal []
518
-
519
- @Album.filter(:a_artist=>@artist).all.must_equal [@album]
520
- @artist.update(:name=>'Foo')
521
- @Album.filter(:a_artist=>@artist).all.must_equal []
522
-
523
- @Album.filter(:t_tags=>@tag).all.must_equal [@album]
524
- @Album.filter(:alias_t_tags=>@tag).all.must_equal [@album]
525
- unless @no_many_through_many
526
- @Album.filter(:t_tag=>@tag).all.must_equal [@album]
527
- @Album.filter(:alias_t_tag=>@tag).all.must_equal [@album]
528
- @Artist.filter(:t_tags=>@tag).all.must_equal [@artist]
529
- @Artist.filter(:t_tag=>@tag).all.must_equal [@artist]
530
- end
531
- @tag.update(:name=>'Foo')
532
- @Album.filter(:t_tags=>@tag).all.must_equal []
533
- @Album.filter(:alias_t_tags=>@tag).all.must_equal []
534
- unless @no_many_through_many
535
- @Album.filter(:t_tag=>@tag).all.must_equal []
536
- @Album.filter(:alias_t_tag=>@tag).all.must_equal []
537
- @Artist.filter(:t_tags=>@tag).all.must_equal []
538
- @Artist.filter(:t_tag=>@tag).all.must_equal []
539
- end
540
- end
541
-
542
- it "should work correctly when excluding by associations with conditions" do
543
- @album.update(:artist => @artist)
544
- @album.add_tag(@tag)
545
-
546
- @Artist.exclude(:a_albums=>@album).all.must_equal []
547
- @Artist.exclude(:first_a_album=>@album).all.must_equal []
548
- @album.update(:name=>'Foo')
549
- @Artist.exclude(:a_albums=>@album).all.must_equal [@artist]
550
- @Artist.exclude(:first_a_album=>@album).all.must_equal [@artist]
551
-
552
- @Album.exclude(:a_artist=>@artist).all.must_equal []
553
- @artist.update(:name=>'Foo')
554
- @Album.exclude(:a_artist=>@artist).all.must_equal [@album]
555
-
556
- @Album.exclude(:t_tags=>@tag).all.must_equal []
557
- @Album.exclude(:alias_t_tags=>@tag).all.must_equal []
558
- unless @no_many_through_many
559
- @Album.exclude(:t_tag=>@tag).all.must_equal []
560
- @Album.exclude(:alias_t_tag=>@tag).all.must_equal []
561
- @Artist.exclude(:t_tags=>@tag).all.must_equal []
562
- @Artist.exclude(:t_tag=>@tag).all.must_equal []
563
- end
564
- @tag.update(:name=>'Foo')
565
- @Album.exclude(:t_tags=>@tag).all.must_equal [@album]
566
- @Album.exclude(:alias_t_tags=>@tag).all.must_equal [@album]
567
- unless @no_many_through_many
568
- @Album.exclude(:t_tag=>@tag).all.must_equal [@album]
569
- @Album.exclude(:alias_t_tag=>@tag).all.must_equal [@album]
570
- @Artist.exclude(:t_tags=>@tag).all.must_equal [@artist]
571
- @Artist.exclude(:t_tag=>@tag).all.must_equal [@artist]
572
- end
573
- end
574
-
575
- it "should work correctly when filtering by multiple associations" do
576
- album, artist, tag = @pr.call
577
- @album.update(:artist => @artist)
578
- @album.add_tag(@tag)
579
-
580
- @Artist.filter(:albums=>[@album, album]).all.must_equal [@artist]
581
- @Artist.filter(:first_album=>[@album, album]).all.must_equal [@artist]
582
- @Album.filter(:artist=>[@artist, artist]).all.must_equal [@album]
583
- @Album.filter(:tags=>[@tag, tag]).all.must_equal [@album]
584
- @Album.filter(:alias_tags=>[@tag, tag]).all.must_equal [@album]
585
- @Tag.filter(:albums=>[@album, album]).all.must_equal [@tag]
586
- @Album.filter(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.must_equal [@album]
587
- @artist.albums_dataset.filter(:tags=>[@tag, tag]).all.must_equal [@album]
588
- unless @no_many_through_many
589
- @Artist.filter(:tags=>[@tag, tag]).all.must_equal [@artist]
590
- @Artist.filter(:first_tag=>[@tag, tag]).all.must_equal [@artist]
591
- end
592
-
593
- album.add_tag(tag)
594
-
595
- @Artist.filter(:albums=>[@album, album]).all.must_equal [@artist]
596
- @Artist.filter(:first_album=>[@album, album]).all.must_equal [@artist]
597
- @Album.filter(:artist=>[@artist, artist]).all.must_equal [@album]
598
- @Album.filter(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
599
- @Album.filter(:alias_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
600
- @Tag.filter(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@tag, tag]
601
- @Album.filter(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.must_equal [@album]
602
- unless @no_many_through_many
603
- @Artist.filter(:tags=>[@tag, tag]).all.must_equal [@artist]
604
- @Artist.filter(:first_tag=>[@tag, tag]).all.must_equal [@artist]
605
- end
606
-
607
- album.update(:artist => artist)
608
-
609
- @Artist.filter(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
610
- @Artist.filter(:first_album=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
611
- @Album.filter(:artist=>[@artist, artist]).all.sort_by{|x| x.pk}.must_equal [@album, album]
612
- @Album.filter(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
613
- @Album.filter(:alias_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
614
- @Tag.filter(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@tag, tag]
615
- @Album.filter(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
616
- unless @no_many_through_many
617
- @Artist.filter(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
618
- @Artist.filter(:first_tag=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
619
- end
620
- end
621
-
622
- it "should work correctly when excluding by multiple associations" do
623
- album, artist, tag = @pr.call
624
-
625
- @Artist.exclude(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
626
- @Artist.exclude(:first_album=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
627
- @Album.exclude(:artist=>[@artist, artist]).all.sort_by{|x| x.pk}.must_equal [@album, album]
628
- @Album.exclude(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
629
- @Album.exclude(:alias_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
630
- @Tag.exclude(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@tag, tag]
631
- @Album.exclude(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
632
- unless @no_many_through_many
633
- @Artist.exclude(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
634
- @Artist.exclude(:first_tag=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
635
- end
636
-
637
- @album.update(:artist => @artist)
638
- @album.add_tag(@tag)
639
-
640
- @Artist.exclude(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [artist]
641
- @Artist.exclude(:first_album=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [artist]
642
- @Album.exclude(:artist=>[@artist, artist]).all.sort_by{|x| x.pk}.must_equal [album]
643
- @Album.exclude(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [album]
644
- @Album.exclude(:alias_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [album]
645
- @Tag.exclude(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [tag]
646
- @Album.exclude(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [album]
647
- unless @no_many_through_many
648
- @Artist.exclude(:tags=>[@tag, tag]).all.must_equal [artist]
649
- @Artist.exclude(:first_tag=>[@tag, tag]).all.must_equal [artist]
650
- end
651
-
652
- album.add_tag(tag)
653
-
654
- @Artist.exclude(:albums=>[@album, album]).all.must_equal [artist]
655
- @Artist.exclude(:first_album=>[@album, album]).all.must_equal [artist]
656
- @Album.exclude(:artist=>[@artist, artist]).all.must_equal [album]
657
- @Album.exclude(:tags=>[@tag, tag]).all.must_equal []
658
- @Album.exclude(:alias_tags=>[@tag, tag]).all.must_equal []
659
- @Tag.exclude(:albums=>[@album, album]).all.must_equal []
660
- @Album.exclude(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.must_equal [album]
661
- unless @no_many_through_many
662
- @Artist.exclude(:tags=>[@tag, tag]).all.must_equal [artist]
663
- @Artist.exclude(:first_tag=>[@tag, tag]).all.must_equal [artist]
664
- end
665
-
666
- album.update(:artist => artist)
667
-
668
- @Artist.exclude(:albums=>[@album, album]).all.must_equal []
669
- @Artist.exclude(:first_album=>[@album, album]).all.must_equal []
670
- @Album.exclude(:artist=>[@artist, artist]).all.must_equal []
671
- @Album.exclude(:tags=>[@tag, tag]).all.must_equal []
672
- @Album.exclude(:alias_tags=>[@tag, tag]).all.must_equal []
673
- @Tag.exclude(:albums=>[@album, album]).all.must_equal []
674
- @Album.exclude(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.must_equal []
675
- unless @no_many_through_many
676
- @Artist.exclude(:tags=>[@tag, tag]).all.must_equal []
677
- @Artist.exclude(:first_tag=>[@tag, tag]).all.must_equal []
678
- end
679
- end
680
-
681
- it "should work correctly when filtering associations with conditions with multiple objects" do
682
- album, artist, tag = @pr.call
683
- album.update(:name=>@album.name)
684
- artist.update(:name=>@artist.name)
685
- tag.update(:name=>@tag.name)
686
-
687
- @album.update(:artist => @artist)
688
- @album.add_tag(@tag)
689
- album.update(:artist => @artist)
690
- tag.add_album(@album)
691
-
692
- @Artist.filter(:a_albums=>[@album, album]).all.must_equal [@artist]
693
- @Artist.filter(:first_a_album=>[@album, album]).all.must_equal [@artist]
694
- @album.update(:name=>'Foo')
695
- @Artist.filter(:a_albums=>[@album, album]).all.must_equal [@artist]
696
- @Artist.filter(:first_a_album=>[@album, album]).all.must_equal [@artist]
697
- album.update(:name=>'Foo')
698
- @Artist.filter(:a_albums=>[@album, album]).all.must_equal []
699
- @Artist.filter(:first_a_album=>[@album, album]).all.must_equal []
700
-
701
- album.update(:artist => nil)
702
- artist.add_album(@album)
703
- @Album.filter(:a_artist=>[@artist, artist]).all.must_equal [@album]
704
- @artist.update(:name=>'Foo')
705
- @Album.filter(:a_artist=>[@artist, artist]).all.must_equal [@album]
706
- artist.update(:name=>'Foo')
707
- @Album.filter(:a_artist=>[@artist, artist]).all.must_equal []
708
-
709
- @Album.filter(:t_tags=>[@tag, tag]).all.must_equal [@album]
710
- @Album.filter(:alias_t_tags=>[@tag, tag]).all.must_equal [@album]
711
- unless @no_many_through_many
712
- @Album.filter(:t_tag=>[@tag, tag]).all.must_equal [@album]
713
- @Album.filter(:alias_t_tag=>[@tag, tag]).all.must_equal [@album]
714
- @Artist.filter(:t_tags=>[@tag, tag]).all.must_equal [artist]
715
- @Artist.filter(:t_tag=>[@tag, tag]).all.must_equal [artist]
716
- end
717
- @tag.update(:name=>'Foo')
718
- @Album.filter(:t_tags=>[@tag, tag]).all.must_equal [@album]
719
- @Album.filter(:alias_t_tags=>[@tag, tag]).all.must_equal [@album]
720
- unless @no_many_through_many
721
- @Album.filter(:t_tag=>[@tag, tag]).all.must_equal [@album]
722
- @Album.filter(:alias_t_tag=>[@tag, tag]).all.must_equal [@album]
723
- @Artist.filter(:t_tags=>[@tag, tag]).all.must_equal [artist]
724
- @Artist.filter(:t_tag=>[@tag, tag]).all.must_equal [artist]
725
- end
726
- tag.update(:name=>'Foo')
727
- @Album.filter(:t_tags=>[@tag, tag]).all.must_equal []
728
- @Album.filter(:alias_t_tags=>[@tag, tag]).all.must_equal []
729
- unless @no_many_through_many
730
- @Album.filter(:t_tag=>[@tag, tag]).all.must_equal []
731
- @Album.filter(:alias_t_tag=>[@tag, tag]).all.must_equal []
732
- @Artist.filter(:t_tags=>[@tag, tag]).all.must_equal []
733
- @Artist.filter(:t_tag=>[@tag, tag]).all.must_equal []
734
- end
735
- end
736
-
737
- it "should work correctly when excluding associations with conditions with multiple objects" do
738
- album, artist, tag = @pr.call
739
- album.update(:name=>@album.name)
740
- artist.update(:name=>@artist.name)
741
- tag.update(:name=>@tag.name)
742
-
743
- @album.update(:artist => @artist)
744
- @album.add_tag(@tag)
745
- album.update(:artist => @artist)
746
- tag.add_album(@album)
747
-
748
- artist.add_album(@album)
749
- @Artist.exclude(:a_albums=>[@album, album]).all.must_equal []
750
- @Artist.exclude(:first_a_album=>[@album, album]).all.must_equal []
751
- @album.update(:name=>'Foo')
752
- @Artist.exclude(:a_albums=>[@album, album]).all.must_equal [artist]
753
- @Artist.exclude(:first_a_album=>[@album, album]).all.must_equal [artist]
754
- album.update(:name=>'Foo')
755
- @Artist.exclude(:a_albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
756
- @Artist.exclude(:first_a_album=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
757
-
758
- @Album.exclude(:a_artist=>[@artist, artist]).all.must_equal []
759
- album.update(:artist => nil)
760
- @artist.update(:name=>'Foo')
761
- @Album.exclude(:a_artist=>[@artist, artist]).all.must_equal [album]
762
- artist.update(:name=>'Foo')
763
- @Album.exclude(:a_artist=>[@artist, artist]).all.sort_by{|x| x.pk}.must_equal [@album, album]
764
-
765
- @tag.add_album(album)
766
- @Album.exclude(:t_tags=>[@tag, tag]).all.must_equal []
767
- @Album.exclude(:alias_t_tags=>[@tag, tag]).all.must_equal []
768
- unless @no_many_through_many
769
- @Album.exclude(:t_tag=>[@tag, tag]).all.must_equal []
770
- @Album.exclude(:alias_t_tag=>[@tag, tag]).all.must_equal []
771
- @Artist.exclude(:t_tags=>[@tag, tag]).all.must_equal [@artist]
772
- @Artist.exclude(:t_tag=>[@tag, tag]).all.must_equal [@artist]
773
- end
774
- @tag.update(:name=>'Foo')
775
- @Album.exclude(:t_tags=>[@tag, tag]).all.must_equal [album]
776
- @Album.exclude(:alias_t_tags=>[@tag, tag]).all.must_equal [album]
777
- unless @no_many_through_many
778
- @Album.exclude(:t_tag=>[@tag, tag]).all.must_equal [album]
779
- @Album.exclude(:alias_t_tag=>[@tag, tag]).all.must_equal [album]
780
- @Artist.exclude(:t_tags=>[@tag, tag]).all.must_equal [@artist]
781
- @Artist.exclude(:t_tag=>[@tag, tag]).all.must_equal [@artist]
782
- end
783
- tag.update(:name=>'Foo')
784
- @Album.exclude(:t_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
785
- @Album.exclude(:alias_t_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
786
- unless @no_many_through_many
787
- @Album.exclude(:t_tag=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
788
- @Album.exclude(:alias_t_tag=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
789
- @Artist.exclude(:t_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
790
- @Artist.exclude(:t_tag=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
791
- end
792
- end
793
-
794
- it "should work correctly when excluding by associations in regards to NULL values" do
795
- @Artist.exclude(:albums=>@album).all.must_equal [@artist]
796
- @Artist.exclude(:first_album=>@album).all.must_equal [@artist]
797
- @Album.exclude(:artist=>@artist).all.must_equal [@album]
798
- @Album.exclude(:tags=>@tag).all.must_equal [@album]
799
- @Album.exclude(:alias_tags=>@tag).all.must_equal [@album]
800
- @Tag.exclude(:albums=>@album).all.must_equal [@tag]
801
- @Album.exclude(:artist=>@artist, :tags=>@tag).all.must_equal [@album]
802
-
803
- @Artist.exclude(:a_albums=>@album).all.must_equal [@artist]
804
- @Artist.exclude(:first_a_album=>@album).all.must_equal [@artist]
805
- @Album.exclude(:a_artist=>@artist).all.must_equal [@album]
806
- @Album.exclude(:t_tags=>@tag).all.must_equal [@album]
807
- @Album.exclude(:alias_t_tags=>@tag).all.must_equal [@album]
808
- unless @no_many_through_many
809
- @Album.exclude(:t_tag=>@tag).all.must_equal [@album]
810
- @Album.exclude(:alias_t_tag=>@tag).all.must_equal [@album]
811
- @Artist.exclude(:t_tags=>@tag).all.must_equal [@artist]
812
- @Artist.exclude(:t_tag=>@tag).all.must_equal [@artist]
813
- end
814
-
815
- @album.update(:artist => @artist)
816
- @artist.albums_dataset.exclude(:tags=>@tag).all.must_equal [@album]
817
- end
818
-
819
- it "should handle NULL values in join table correctly when filtering/excluding many_to_many associations" do
820
- @ins.call
821
- @Album.exclude(:tags=>@tag).all.must_equal [@album]
822
- @Album.exclude(:alias_tags=>@tag).all.must_equal [@album]
823
- @Album.exclude(:t_tags=>@tag).all.must_equal [@album]
824
- @Album.exclude(:alias_t_tags=>@tag).all.must_equal [@album]
825
- @album.add_tag(@tag)
826
- @Album.filter(:tags=>@tag).all.must_equal [@album]
827
- @Album.filter(:alias_tags=>@tag).all.must_equal [@album]
828
- @Album.filter(:t_tags=>@tag).all.must_equal [@album]
829
- @Album.filter(:alias_t_tags=>@tag).all.must_equal [@album]
830
- album, tag = @pr.call.values_at(0, 2)
831
- @Album.exclude(:tags=>@tag).all.must_equal [album]
832
- @Album.exclude(:alias_tags=>@tag).all.must_equal [album]
833
- @Album.exclude(:t_tags=>@tag).all.must_equal [album]
834
- @Album.exclude(:alias_t_tags=>@tag).all.must_equal [album]
835
- @Album.exclude(:tags=>tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
836
- @Album.exclude(:alias_tags=>tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
837
- @Album.exclude(:t_tags=>tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
838
- @Album.exclude(:alias_t_tags=>tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
839
- end
840
-
841
- it "should work correctly when filtering by association datasets" do
842
- album, artist, tag = @pr.call
843
- @album.update(:artist => @artist)
844
- @album.add_tag(@tag)
845
- album.add_tag(tag)
846
- album.update(:artist => artist)
847
-
848
- @Artist.filter(:albums=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
849
- @Artist.filter(:albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
850
- @Artist.filter(:albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
851
- @Artist.filter(:first_album=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
852
- @Artist.filter(:first_album=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
853
- @Artist.filter(:first_album=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
854
- @Album.filter(:artist=>@Artist).all.sort_by{|x| x.pk}.must_equal [@album, album]
855
- @Album.filter(:artist=>@Artist.filter(Array(Artist.primary_key).map{|k| Sequel.qualify(Artist.table_name, k)}.zip(Array(artist.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
856
- @Album.filter(:artist=>@Artist.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
857
- @Album.filter(:tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
858
- @Album.filter(:tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
859
- @Album.filter(:tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
860
- @Album.filter(:alias_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
861
- @Album.filter(:alias_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
862
- @Album.filter(:alias_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
863
- @Tag.filter(:albums=>@Album).all.sort_by{|x| x.pk}.must_equal [@tag, tag]
864
- @Tag.filter(:albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [tag]
865
- @Tag.filter(:albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
866
-
867
- unless @no_many_through_many
868
- @Artist.filter(:tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
869
- @Artist.filter(:tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
870
- @Artist.filter(:tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
871
- @Artist.filter(:first_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
872
- @Artist.filter(:first_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
873
- @Artist.filter(:first_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
874
- end
875
- end
876
-
877
- it "should work correctly when excluding by association datasets" do
878
- album, artist, tag = @pr.call
879
- @album.update(:artist => @artist)
880
- @album.add_tag(@tag)
881
- album.add_tag(tag)
882
- album.update(:artist => artist)
883
-
884
- @Artist.exclude(:albums=>@Album).all.sort_by{|x| x.pk}.must_equal []
885
- @Artist.exclude(:albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
886
- @Artist.exclude(:albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
887
- @Artist.exclude(:first_album=>@Album).all.sort_by{|x| x.pk}.must_equal []
888
- @Artist.exclude(:first_album=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
889
- @Artist.exclude(:first_album=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
890
- @Album.exclude(:artist=>@Artist).all.sort_by{|x| x.pk}.must_equal []
891
- @Album.exclude(:artist=>@Artist.filter(Array(Artist.primary_key).map{|k| Sequel.qualify(Artist.table_name, k)}.zip(Array(artist.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
892
- @Album.exclude(:artist=>@Artist.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
893
- @Album.exclude(:tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
894
- @Album.exclude(:tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
895
- @Album.exclude(:tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
896
- @Album.exclude(:alias_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
897
- @Album.exclude(:alias_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
898
- @Album.exclude(:alias_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
899
- @Tag.exclude(:albums=>@Album).all.sort_by{|x| x.pk}.must_equal []
900
- @Tag.exclude(:albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [@tag]
901
- @Tag.exclude(:albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@tag, tag]
902
-
903
- unless @no_many_through_many
904
- @Artist.exclude(:tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
905
- @Artist.exclude(:tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
906
- @Artist.exclude(:tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
907
- @Artist.exclude(:first_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal []
908
- @Artist.exclude(:first_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
909
- @Artist.exclude(:first_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
910
- end
911
- end
912
-
913
- it "should work correctly when filtering by association datasets with conditions" do
914
- album, artist, tag = @pr.call
915
- @album.update(:artist => @artist)
916
- @album.add_tag(@tag)
917
- album.add_tag(tag)
918
- album.update(:artist => artist)
919
-
920
- @Artist.filter(:a_albums=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist]
921
- @Artist.filter(:first_a_album=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist]
922
- @Album.filter(:a_artist=>@Artist).all.sort_by{|x| x.pk}.must_equal [@album]
923
- @Album.filter(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album]
924
- @Album.filter(:alias_t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album]
925
- unless @no_many_through_many
926
- @Album.filter(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album]
927
- @Album.filter(:alias_t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album]
928
- @Artist.filter(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist]
929
- @Artist.filter(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist]
930
- end
931
-
932
- artist.update(:name=>@artist.name)
933
- album.update(:name=>@album.name)
934
- tag.update(:name=>@tag.name)
935
-
936
- @Artist.filter(:a_albums=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
937
- @Artist.filter(:first_a_album=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
938
- @Album.filter(:a_artist=>@Artist).all.sort_by{|x| x.pk}.must_equal [@album, album]
939
- @Album.filter(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
940
- @Album.filter(:alias_t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
941
- unless @no_many_through_many
942
- @Album.filter(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
943
- @Album.filter(:alias_t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
944
- @Artist.filter(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
945
- @Artist.filter(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
946
- end
947
-
948
- @Artist.filter(:a_albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
949
- @Artist.filter(:first_a_album=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
950
- @Album.filter(:a_artist=>@Artist.filter(Array(Artist.primary_key).map{|k| Sequel.qualify(Artist.table_name, k)}.zip(Array(artist.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
951
- @Album.filter(:t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
952
- @Album.filter(:alias_t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
953
- unless @no_many_through_many
954
- @Album.filter(:t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
955
- @Album.filter(:alias_t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
956
- @Artist.filter(:t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
957
- @Artist.filter(:t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
958
- end
959
-
960
- @Artist.filter(:a_albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
961
- @Artist.filter(:first_a_album=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
962
- @Album.filter(:a_artist=>@Artist.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
963
- @Album.filter(:t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
964
- @Album.filter(:t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
965
- @Album.filter(:alias_t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
966
- unless @no_many_through_many
967
- @Album.filter(:t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
968
- @Album.filter(:t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
969
- @Album.filter(:alias_t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
970
- @Artist.filter(:t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
971
- @Artist.filter(:t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
972
- end
973
- end
974
-
975
- it "should work correctly when excluding by association datasets with conditions" do
976
- album, artist, tag = @pr.call
977
- @album.update(:artist => @artist)
978
- @album.add_tag(@tag)
979
- album.add_tag(tag)
980
- album.update(:artist => artist)
981
-
982
- @Artist.exclude(:a_albums=>@Album).all.sort_by{|x| x.pk}.must_equal [artist]
983
- @Artist.exclude(:first_a_album=>@Album).all.sort_by{|x| x.pk}.must_equal [artist]
984
- @Album.exclude(:a_artist=>@Artist).all.sort_by{|x| x.pk}.must_equal [album]
985
- @Album.exclude(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [album]
986
- @Album.exclude(:alias_t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [album]
987
- unless @no_many_through_many
988
- @Album.exclude(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [album]
989
- @Album.exclude(:alias_t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [album]
990
- @Artist.exclude(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [artist]
991
- @Artist.exclude(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [artist]
992
- end
993
-
994
- artist.update(:name=>@artist.name)
995
- album.update(:name=>@album.name)
996
- tag.update(:name=>@tag.name)
997
-
998
- @Artist.exclude(:a_albums=>@Album).all.sort_by{|x| x.pk}.must_equal []
999
- @Artist.exclude(:first_a_album=>@Album).all.sort_by{|x| x.pk}.must_equal []
1000
- @Album.exclude(:a_artist=>@Artist).all.sort_by{|x| x.pk}.must_equal []
1001
- @Album.exclude(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
1002
- @Album.exclude(:alias_t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
1003
- unless @no_many_through_many
1004
- @Album.exclude(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal []
1005
- @Album.exclude(:alias_t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal []
1006
- @Artist.exclude(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
1007
- @Artist.exclude(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal []
1008
- end
1009
-
1010
- @Artist.exclude(:a_albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
1011
- @Artist.exclude(:first_a_album=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
1012
- @Album.exclude(:a_artist=>@Artist.filter(Array(Artist.primary_key).map{|k| Sequel.qualify(Artist.table_name, k)}.zip(Array(artist.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
1013
- @Album.exclude(:t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
1014
- @Album.exclude(:alias_t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
1015
- unless @no_many_through_many
1016
- @Album.exclude(:t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
1017
- @Album.exclude(:alias_t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
1018
- @Artist.exclude(:t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
1019
- @Artist.exclude(:t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
1020
- end
1021
-
1022
- @Artist.exclude(:a_albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
1023
- @Artist.exclude(:first_a_album=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
1024
- @Album.exclude(:a_artist=>@Artist.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
1025
- @Album.exclude(:t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
1026
- @Album.exclude(:alias_t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
1027
- unless @no_many_through_many
1028
- @Album.exclude(:t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
1029
- @Album.exclude(:alias_t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
1030
- @Artist.exclude(:t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
1031
- @Artist.exclude(:t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
1032
- end
1033
- end
1034
- end
1035
-
1036
- FilterByAssociationsOneToOneLimitStrategies = shared_description do
1037
- it "filter by associations with limited one_to_one associations should work correctly" do
1038
- Artist.one_to_one :first_album, {:clone=>:first_album}.merge(@els)
1039
- Artist.one_to_one :last_album, {:clone=>:last_album}.merge(@els)
1040
- Artist.one_to_one :second_album, {:clone=>:second_album}.merge(@els)
1041
- @album.update(:artist => @artist)
1042
- diff_album = @diff_album.call
1043
- ar = @pr.call[1]
1044
- ds = Artist.order(:name)
1045
-
1046
- ds.where(:first_album=>@album).all.must_equal [@artist]
1047
- ds.where(:first_album=>diff_album).all.must_equal []
1048
- ds.exclude(:first_album=>@album).all.must_equal [ar]
1049
- ds.exclude(:first_album=>diff_album).all.must_equal [@artist, ar]
1050
-
1051
- if @els[:eager_limit_strategy] != :distinct_on && (@els[:eager_limit_strategy] != :correlated_subquery || Album.dataset.supports_offsets_in_correlated_subqueries?)
1052
- ds.where(:second_album=>@album).all.must_equal []
1053
- ds.where(:second_album=>diff_album).all.must_equal [@artist]
1054
- ds.exclude(:second_album=>@album).all.must_equal [@artist, ar]
1055
- ds.exclude(:second_album=>diff_album).all.must_equal [ar]
1056
- end
1057
-
1058
- ds.where(:last_album=>@album).all.must_equal []
1059
- ds.where(:last_album=>diff_album).all.must_equal [@artist]
1060
- ds.exclude(:last_album=>@album).all.must_equal [@artist, ar]
1061
- ds.exclude(:last_album=>diff_album).all.must_equal [ar]
1062
-
1063
- Artist.one_to_one :first_album, :clone=>:first_album do |ads| ads.where(:albums__name=>diff_album.name) end
1064
- ar.add_album(diff_album)
1065
- ds.where(:first_album=>[@album, diff_album]).all.must_equal [ar]
1066
- ds.exclude(:first_album=>[@album, diff_album]).all.must_equal [@artist]
1067
- end
1068
- end
1069
-
1070
- FilterByAssociationsSingularLimitStrategies = shared_description do
1071
- include FilterByAssociationsOneToOneLimitStrategies
1072
-
1073
- it "dataset associations with limited one_to_one associations should work correctly" do
1074
- Artist.one_to_one :first_album, {:clone=>:first_album}.merge(@els)
1075
- Artist.one_to_one :last_album, {:clone=>:last_album}.merge(@els)
1076
- Artist.one_to_one :second_album, {:clone=>:second_album}.merge(@els) if @els[:eager_limit_strategy] != :distinct_on
1077
- @album.update(:artist => @artist)
1078
- diff_album = @diff_album.call
1079
- ar = @pr.call[1]
1080
- ds = Artist
1081
-
1082
- ds.where(@artist.pk_hash).first_albums.all.must_equal [@album]
1083
- ds.where(@artist.pk_hash).second_albums.all.must_equal [diff_album]
1084
- ds.where(@artist.pk_hash).last_albums.all.must_equal [diff_album]
1085
- ds.where(ar.pk_hash).first_albums.all.must_equal []
1086
- ds.where(ar.pk_hash).second_albums.all.must_equal []
1087
- ds.where(ar.pk_hash).last_albums.all.must_equal []
1088
-
1089
- Artist.one_to_one :first_album, :clone=>:first_album do |ads| ads.where(:albums__name=>diff_album.name) end
1090
- ar.add_album(diff_album)
1091
- ds.where(@artist.pk_hash).first_albums.all.must_equal []
1092
- ds.where(ar.pk_hash).first_albums.all.must_equal [diff_album]
1093
- end
1094
-
1095
- it "filter by associations with limited one_through_one associations should work correctly" do
1096
- Album.one_through_one :first_tag, {:clone=>:first_tag}.merge(@els)
1097
- Album.one_through_one :second_tag, {:clone=>:second_tag}.merge(@els) if @els[:eager_limit_strategy] != :distinct_on
1098
- Album.one_through_one :last_tag, {:clone=>:last_tag}.merge(@els)
1099
- tu, tv = @other_tags.call
1100
- al = @pr.call.first
1101
- ds = Album.order(:name)
1102
- al.add_tag(tu)
1103
-
1104
- ds.where(:first_tag=>@tag).all.must_equal [@album]
1105
- ds.where(:first_tag=>tu).all.must_equal [al]
1106
- ds.where(:first_tag=>tv).all.must_equal []
1107
- ds.exclude(:first_tag=>@tag).all.must_equal [al]
1108
- ds.exclude(:first_tag=>tu).all.must_equal [@album]
1109
- ds.exclude(:first_tag=>tv).all.must_equal [@album, al]
1110
-
1111
- ds.where(:second_tag=>@tag).all.must_equal []
1112
- ds.where(:second_tag=>tu).all.must_equal [@album]
1113
- ds.where(:second_tag=>tv).all.must_equal []
1114
- ds.exclude(:second_tag=>@tag).all.must_equal [@album, al]
1115
- ds.exclude(:second_tag=>tu).all.must_equal [al]
1116
- ds.exclude(:second_tag=>tv).all.must_equal [@album, al]
1117
-
1118
- ds.where(:last_tag=>@tag).all.must_equal []
1119
- ds.where(:last_tag=>tu).all.must_equal [al]
1120
- ds.where(:last_tag=>tv).all.must_equal [@album]
1121
- ds.exclude(:last_tag=>@tag).all.must_equal [@album, al]
1122
- ds.exclude(:last_tag=>tu).all.must_equal [@album]
1123
- ds.exclude(:last_tag=>tv).all.must_equal [al]
1124
-
1125
- Album.one_through_one :first_tag, :clone=>:first_tag do |ads| ads.where(:tags__name=>tu.name) end
1126
- Album.one_through_one :second_tag, :clone=>:second_tag do |ads| ads.where(:tags__name=>[tu.name, tv.name]) end
1127
-
1128
- ds.where(:first_tag=>[@tag, tu]).all.must_equal [@album, al]
1129
- ds.exclude(:first_tag=>[@tag, tu]).all.must_equal []
1130
-
1131
- al.add_tag(tv)
1132
- ds.where(:second_tag=>[tv, tu]).all.must_equal [@album, al]
1133
- ds.exclude(:second_tag=>[tv, tu]).all.must_equal []
1134
- end
1135
-
1136
- it "dataset associations with limited one_through_one associations should work correctly" do
1137
- Album.one_through_one :first_tag, {:clone=>:first_tag}.merge(@els)
1138
- Album.one_through_one :second_tag, {:clone=>:second_tag}.merge(@els) if @els[:eager_limit_strategy] != :distinct_on
1139
- Album.one_through_one :last_tag, {:clone=>:last_tag}.merge(@els)
1140
- tu, tv = @other_tags.call
1141
- al = @pr.call.first
1142
- ds = Album
1143
- al.add_tag(tu)
1144
-
1145
- ds.where(@album.pk_hash).first_tags.all.must_equal [@tag]
1146
- ds.where(@album.pk_hash).second_tags.all.must_equal [tu]
1147
- ds.where(@album.pk_hash).last_tags.all.must_equal [tv]
1148
- ds.where(al.pk_hash).first_tags.all.must_equal [tu]
1149
- ds.where(al.pk_hash).second_tags.all.must_equal []
1150
- ds.where(al.pk_hash).last_tags.all.must_equal [tu]
1151
-
1152
- Album.one_through_one :first_tag, :clone=>:first_tag do |ads| ads.where(:tags__name=>tu.name) end
1153
- Album.one_through_one :second_tag, :clone=>:second_tag do |ads| ads.where(:tags__name=>[tu.name, tv.name]) end
1154
-
1155
- ds.where(@album.pk_hash).first_tags.all.must_equal [tu]
1156
- ds.where(@album.pk_hash).second_tags.all.must_equal [tv]
1157
- ds.where(al.pk_hash).first_tags.all.must_equal [tu]
1158
- ds.where(al.pk_hash).second_tags.all.must_equal []
1159
-
1160
- al.add_tag(tv)
1161
- ds.where(@album.pk_hash).first_tags.all.must_equal [tu]
1162
- ds.where(@album.pk_hash).second_tags.all.must_equal [tv]
1163
- ds.where(al.pk_hash).first_tags.all.must_equal [tu]
1164
- ds.where(al.pk_hash).second_tags.all.must_equal [tv]
1165
- end
1166
-
1167
- it "filter by associations with limited one_through_many associations should work correctly" do
1168
- Artist.one_through_many :first_tag, {:clone=>:first_tag}.merge(@els)
1169
- Artist.one_through_many :second_tag, {:clone=>:second_tag}.merge(@els) if @els[:eager_limit_strategy] != :distinct_on
1170
- Artist.one_through_many :last_tag, {:clone=>:last_tag}.merge(@els)
1171
- @album.update(:artist => @artist)
1172
- tu, tv = @other_tags.call
1173
- al, ar, _ = @pr.call
1174
- al.update(:artist=>ar)
1175
- al.add_tag(tu)
1176
- ds = Artist.order(:name)
1177
-
1178
- ds.where(:first_tag=>@tag).all.must_equal [@artist]
1179
- ds.where(:first_tag=>tu).all.must_equal [ar]
1180
- ds.where(:first_tag=>tv).all.must_equal []
1181
- ds.exclude(:first_tag=>@tag).all.must_equal [ar]
1182
- ds.exclude(:first_tag=>tu).all.must_equal [@artist]
1183
- ds.exclude(:first_tag=>tv).all.must_equal [@artist, ar]
1184
-
1185
- ds.where(:second_tag=>@tag).all.must_equal []
1186
- ds.where(:second_tag=>tu).all.must_equal [@artist]
1187
- ds.where(:second_tag=>tv).all.must_equal []
1188
- ds.exclude(:second_tag=>@tag).all.must_equal [@artist, ar]
1189
- ds.exclude(:second_tag=>tu).all.must_equal [ar]
1190
- ds.exclude(:second_tag=>tv).all.must_equal [@artist, ar]
1191
-
1192
- ds.where(:last_tag=>@tag).all.must_equal []
1193
- ds.where(:last_tag=>tu).all.must_equal [ar]
1194
- ds.where(:last_tag=>tv).all.must_equal [@artist]
1195
- ds.exclude(:last_tag=>@tag).all.must_equal [@artist, ar]
1196
- ds.exclude(:last_tag=>tu).all.must_equal [@artist]
1197
- ds.exclude(:last_tag=>tv).all.must_equal [ar]
1198
-
1199
- Artist.one_through_many :first_tag, :clone=>:first_tag do |ads| ads.where(:tags__name=>tu.name) end
1200
- Artist.one_through_many :second_tag, :clone=>:second_tag do |ads| ads.where(:tags__name=>[tu.name, tv.name]) end
1201
-
1202
- ds.where(:first_tag=>[@tag, tu]).all.must_equal [@artist, ar]
1203
- ds.exclude(:first_tag=>[@tag, tu]).all.must_equal []
1204
-
1205
- al.add_tag(tv)
1206
- ds.where(:second_tag=>[tv, tu]).all.must_equal [@artist, ar]
1207
- ds.exclude(:second_tag=>[tv, tu]).all.must_equal []
1208
- end
1209
-
1210
- it "dataset associations with limited one_through_many associations should work correctly" do
1211
- Artist.one_through_many :first_tag, {:clone=>:first_tag}.merge(@els)
1212
- Artist.one_through_many :second_tag, {:clone=>:second_tag}.merge(@els) if @els[:eager_limit_strategy] != :distinct_on
1213
- Artist.one_through_many :last_tag, {:clone=>:last_tag}.merge(@els)
1214
- @album.update(:artist => @artist)
1215
- tu, tv = @other_tags.call
1216
- al, ar, _ = @pr.call
1217
- al.update(:artist=>ar)
1218
- al.add_tag(tu)
1219
- ds = Artist.order(:name)
1220
-
1221
- ds.where(@artist.pk_hash).first_tags.all.must_equal [@tag]
1222
- ds.where(@artist.pk_hash).second_tags.all.must_equal [tu]
1223
- ds.where(@artist.pk_hash).last_tags.all.must_equal [tv]
1224
- ds.where(ar.pk_hash).first_tags.all.must_equal [tu]
1225
- ds.where(ar.pk_hash).second_tags.all.must_equal []
1226
- ds.where(ar.pk_hash).last_tags.all.must_equal [tu]
1227
-
1228
- Artist.one_through_many :first_tag, :clone=>:first_tag do |ads| ads.where(:tags__name=>tu.name) end
1229
- Artist.one_through_many :second_tag, :clone=>:second_tag do |ads| ads.where(:tags__name=>[tu.name, tv.name]) end
1230
-
1231
- ds.where(@artist.pk_hash).first_tags.all.must_equal [tu]
1232
- ds.where(@artist.pk_hash).second_tags.all.must_equal [tv]
1233
- ds.where(ar.pk_hash).first_tags.all.must_equal [tu]
1234
- ds.where(ar.pk_hash).second_tags.all.must_equal []
1235
-
1236
- al.add_tag(tv)
1237
- ds.where(@artist.pk_hash).first_tags.all.must_equal [tu]
1238
- ds.where(@artist.pk_hash).second_tags.all.must_equal [tv]
1239
- ds.where(ar.pk_hash).first_tags.all.must_equal [tu]
1240
- ds.where(ar.pk_hash).second_tags.all.must_equal [tv]
1241
- end
1242
- end
1243
-
1244
- FilterByAssociationsOneToManyLimitStrategies = shared_description do
1245
- it "filter by associations with limited one_to_many associations should work correctly" do
1246
- Artist.one_to_many :first_two_albums, {:clone=>:first_two_albums}.merge(@els)
1247
- Artist.one_to_many :second_two_albums, {:clone=>:second_two_albums}.merge(@els)
1248
- Artist.one_to_many :not_first_albums, {:clone=>:not_first_albums}.merge(@els)
1249
- Artist.one_to_many :last_two_albums, {:clone=>:last_two_albums}.merge(@els)
1250
- @album.update(:artist => @artist)
1251
- middle_album = @middle_album.call
1252
- diff_album = @diff_album.call
1253
- ar = @pr.call[1]
1254
- ds = Artist.order(:name)
1255
-
1256
- ds.where(:first_two_albums=>@album).all.must_equal [@artist]
1257
- ds.where(:first_two_albums=>middle_album).all.must_equal [@artist]
1258
- ds.where(:first_two_albums=>diff_album).all.must_equal []
1259
- ds.exclude(:first_two_albums=>@album).all.must_equal [ar]
1260
- ds.exclude(:first_two_albums=>middle_album).all.must_equal [ar]
1261
- ds.exclude(:first_two_albums=>diff_album).all.must_equal [@artist, ar]
1262
-
1263
- assocs = if @els[:eager_limit_strategy] != :correlated_subquery || Album.dataset.supports_offsets_in_correlated_subqueries?
1264
- [:second_two_albums, :not_first_albums, :last_two_albums]
1265
- else
1266
- [:last_two_albums]
1267
- end
1268
-
1269
- assocs.each do |a|
1270
- ds.where(a=>@album).all.must_equal []
1271
- ds.where(a=>middle_album).all.must_equal [@artist]
1272
- ds.where(a=>diff_album).all.must_equal [@artist]
1273
- ds.exclude(a=>@album).all.must_equal [@artist, ar]
1274
- ds.exclude(a=>middle_album).all.must_equal [ar]
1275
- ds.exclude(a=>diff_album).all.must_equal [ar]
1276
- end
1277
-
1278
- Artist.one_to_one :first_two_albums, :clone=>:first_two_albums do |ads| ads.where(:albums__name=>diff_album.name) end
1279
- ar.add_album(diff_album)
1280
- ds.where(:first_two_albums=>[@album, diff_album]).all.must_equal [ar]
1281
- ds.exclude(:first_two_albums=>[@album, diff_album]).all.must_equal [@artist]
1282
- end
1283
- end
1284
-
1285
- FilterByAssociationsLimitStrategies = shared_description do
1286
- include FilterByAssociationsSingularLimitStrategies
1287
- include FilterByAssociationsOneToManyLimitStrategies
1288
-
1289
- it "dataset associations with limited one_to_many associations should work correctly" do
1290
- Artist.one_to_many :first_two_albums, {:clone=>:first_two_albums}.merge(@els)
1291
- Artist.one_to_many :second_two_albums, {:clone=>:second_two_albums}.merge(@els)
1292
- Artist.one_to_many :not_first_albums, {:clone=>:not_first_albums}.merge(@els)
1293
- Artist.one_to_many :last_two_albums, {:clone=>:last_two_albums}.merge(@els)
1294
- @album.update(:artist => @artist)
1295
- middle_album = @middle_album.call
1296
- diff_album = @diff_album.call
1297
- ar = @pr.call[1]
1298
- ds = Artist.order(:name)
1299
-
1300
- ds.where(@artist.pk_hash).first_two_albums.all.must_equal [@album, middle_album]
1301
- ds.where(@artist.pk_hash).second_two_albums.all.must_equal [middle_album, diff_album]
1302
- ds.where(@artist.pk_hash).not_first_albums.all.must_equal [middle_album, diff_album]
1303
- ds.where(@artist.pk_hash).last_two_albums.all.must_equal [diff_album, middle_album]
1304
- ds.where(ar.pk_hash).first_two_albums.all.must_equal []
1305
- ds.where(ar.pk_hash).second_two_albums.all.must_equal []
1306
- ds.where(ar.pk_hash).not_first_albums.all.must_equal []
1307
- ds.where(ar.pk_hash).last_two_albums.all.must_equal []
1308
-
1309
- Artist.one_to_one :first_two_albums, :clone=>:first_two_albums do |ads| ads.where(:albums__name=>[diff_album.name, middle_album.name]) end
1310
- ar.add_album(diff_album)
1311
- ds.where(@artist.pk_hash).first_two_albums.all.must_equal [middle_album]
1312
- ds.where(ar.pk_hash).first_two_albums.all.must_equal [diff_album]
1313
- end
1314
-
1315
- it "filter by associations with limited many_to_many associations should work correctly" do
1316
- Album.send :many_to_many, :first_two_tags, {:clone=>:first_two_tags}.merge(@els)
1317
- Album.send :many_to_many, :second_two_tags, {:clone=>:second_two_tags}.merge(@els)
1318
- Album.send :many_to_many, :not_first_tags, {:clone=>:not_first_tags}.merge(@els)
1319
- Album.send :many_to_many, :last_two_tags, {:clone=>:last_two_tags}.merge(@els)
1320
- tu, tv = @other_tags.call
1321
- al = @pr.call.first
1322
- al.add_tag(tu)
1323
- ds = Album.order(:name)
1324
-
1325
- ds.where(:first_two_tags=>@tag).all.must_equal [@album]
1326
- ds.where(:first_two_tags=>tu).all.must_equal [@album, al]
1327
- ds.where(:first_two_tags=>tv).all.must_equal []
1328
- ds.exclude(:first_two_tags=>@tag).all.must_equal [al]
1329
- ds.exclude(:first_two_tags=>tu).all.must_equal []
1330
- ds.exclude(:first_two_tags=>tv).all.must_equal [@album, al]
1331
-
1332
- ds.where(:second_two_tags=>@tag).all.must_equal []
1333
- ds.where(:second_two_tags=>tu).all.must_equal [@album]
1334
- ds.where(:second_two_tags=>tv).all.must_equal [@album]
1335
- ds.exclude(:second_two_tags=>@tag).all.must_equal [@album, al]
1336
- ds.exclude(:second_two_tags=>tu).all.must_equal [al]
1337
- ds.exclude(:second_two_tags=>tv).all.must_equal [al]
1338
-
1339
- ds.where(:not_first_tags=>@tag).all.must_equal []
1340
- ds.where(:not_first_tags=>tu).all.must_equal [@album]
1341
- ds.where(:not_first_tags=>tv).all.must_equal [@album]
1342
- ds.exclude(:not_first_tags=>@tag).all.must_equal [@album, al]
1343
- ds.exclude(:not_first_tags=>tu).all.must_equal [al]
1344
- ds.exclude(:not_first_tags=>tv).all.must_equal [al]
1345
-
1346
- ds.where(:last_two_tags=>@tag).all.must_equal []
1347
- ds.where(:last_two_tags=>tu).all.must_equal [@album, al]
1348
- ds.where(:last_two_tags=>tv).all.must_equal [@album]
1349
- ds.exclude(:last_two_tags=>@tag).all.must_equal [@album, al]
1350
- ds.exclude(:last_two_tags=>tu).all.must_equal []
1351
- ds.exclude(:last_two_tags=>tv).all.must_equal [al]
1352
-
1353
- Album.many_to_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(:tags__name=>tu.name) end
1354
- Album.many_to_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(:tags__name=>[tu.name, tv.name]) end
1355
-
1356
- ds.where(:first_two_tags=>[@tag, tu]).all.must_equal [@album, al]
1357
- ds.exclude(:first_two_tags=>[@tag, tu]).all.must_equal []
1358
-
1359
- al.add_tag(tv)
1360
- ds.where(:second_two_tags=>[tv, tu]).all.must_equal [@album, al]
1361
- ds.exclude(:second_two_tags=>[tv, tu]).all.must_equal []
1362
- end
1363
-
1364
- it "dataset associations with limited many_to_many associations should work correctly" do
1365
- Album.send :many_to_many, :first_two_tags, {:clone=>:first_two_tags}.merge(@els)
1366
- Album.send :many_to_many, :second_two_tags, {:clone=>:second_two_tags}.merge(@els)
1367
- Album.send :many_to_many, :not_first_tags, {:clone=>:not_first_tags}.merge(@els)
1368
- Album.send :many_to_many, :last_two_tags, {:clone=>:last_two_tags}.merge(@els)
1369
- tu, tv = @other_tags.call
1370
- al = @pr.call.first
1371
- al.add_tag(tu)
1372
- ds = Album.order(:name)
1373
-
1374
- ds.where(@album.pk_hash).first_two_tags.all.must_equal [@tag, tu]
1375
- ds.where(@album.pk_hash).second_two_tags.all.must_equal [tu, tv]
1376
- ds.where(@album.pk_hash).not_first_tags.all.must_equal [tu, tv]
1377
- ds.where(@album.pk_hash).last_two_tags.all.must_equal [tv, tu]
1378
- ds.where(al.pk_hash).first_two_tags.all.must_equal [tu]
1379
- ds.where(al.pk_hash).second_two_tags.all.must_equal []
1380
- ds.where(al.pk_hash).not_first_tags.all.must_equal []
1381
- ds.where(al.pk_hash).last_two_tags.all.must_equal [tu]
1382
-
1383
- Album.many_to_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(:tags__name=>tu.name) end
1384
- Album.many_to_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(:tags__name=>[tu.name, tv.name]) end
1385
-
1386
- ds.where(@album.pk_hash).first_two_tags.all.must_equal [tu]
1387
- ds.where(@album.pk_hash).second_two_tags.all.must_equal [tv]
1388
- ds.where(al.pk_hash).first_two_tags.all.must_equal [tu]
1389
- ds.where(al.pk_hash).second_two_tags.all.must_equal []
1390
-
1391
- al.add_tag(tv)
1392
- ds.where(@album.pk_hash).first_two_tags.all.must_equal [tu]
1393
- ds.where(@album.pk_hash).second_two_tags.all.must_equal [tv]
1394
- ds.where(al.pk_hash).first_two_tags.all.must_equal [tu]
1395
- ds.where(al.pk_hash).second_two_tags.all.must_equal [tv]
1396
- end
1397
-
1398
- it "filter by associations with limited many_through_many associations should work correctly" do
1399
- Artist.many_through_many :first_two_tags, {:clone=>:first_two_tags}.merge(@els)
1400
- Artist.many_through_many :second_two_tags, {:clone=>:second_two_tags}.merge(@els)
1401
- Artist.many_through_many :not_first_tags, {:clone=>:not_first_tags}.merge(@els)
1402
- Artist.many_through_many :last_two_tags, {:clone=>:last_two_tags}.merge(@els)
1403
- @album.update(:artist => @artist)
1404
- tu, tv = @other_tags.call
1405
- al, ar, _ = @pr.call
1406
- al.update(:artist=>ar)
1407
- al.add_tag(tu)
1408
- ds = Artist.order(:name)
1409
-
1410
- ds.where(:first_two_tags=>@tag).all.must_equal [@artist]
1411
- ds.where(:first_two_tags=>tu).all.must_equal [@artist, ar]
1412
- ds.where(:first_two_tags=>tv).all.must_equal []
1413
- ds.exclude(:first_two_tags=>@tag).all.must_equal [ar]
1414
- ds.exclude(:first_two_tags=>tu).all.must_equal []
1415
- ds.exclude(:first_two_tags=>tv).all.must_equal [@artist, ar]
1416
-
1417
- ds.where(:second_two_tags=>@tag).all.must_equal []
1418
- ds.where(:second_two_tags=>tu).all.must_equal [@artist]
1419
- ds.where(:second_two_tags=>tv).all.must_equal [@artist]
1420
- ds.exclude(:second_two_tags=>@tag).all.must_equal [@artist, ar]
1421
- ds.exclude(:second_two_tags=>tu).all.must_equal [ar]
1422
- ds.exclude(:second_two_tags=>tv).all.must_equal [ar]
1423
-
1424
- ds.where(:not_first_tags=>@tag).all.must_equal []
1425
- ds.where(:not_first_tags=>tu).all.must_equal [@artist]
1426
- ds.where(:not_first_tags=>tv).all.must_equal [@artist]
1427
- ds.exclude(:not_first_tags=>@tag).all.must_equal [@artist, ar]
1428
- ds.exclude(:not_first_tags=>tu).all.must_equal [ar]
1429
- ds.exclude(:not_first_tags=>tv).all.must_equal [ar]
1430
-
1431
- ds.where(:last_two_tags=>@tag).all.must_equal []
1432
- ds.where(:last_two_tags=>tu).all.must_equal [@artist, ar]
1433
- ds.where(:last_two_tags=>tv).all.must_equal [@artist]
1434
- ds.exclude(:last_two_tags=>@tag).all.must_equal [@artist, ar]
1435
- ds.exclude(:last_two_tags=>tu).all.must_equal []
1436
- ds.exclude(:last_two_tags=>tv).all.must_equal [ar]
1437
-
1438
- Artist.many_through_many :first_two_tags, :clone=>:first_tag do |ads| ads.where(:tags__name=>tu.name) end
1439
- Artist.many_through_many :second_two_tags, :clone=>:first_tag do |ads| ads.where(:tags__name=>[tv.name, tu.name]) end
1440
-
1441
- ds.where(:first_two_tags=>[@tag, tu]).all.must_equal [@artist, ar]
1442
- ds.exclude(:first_two_tags=>[@tag, tu]).all.must_equal []
1443
-
1444
- al.add_tag(tv)
1445
- ds.where(:second_two_tags=>[tv, tu]).all.must_equal [@artist, ar]
1446
- ds.exclude(:second_two_tags=>[tv, tu]).all.must_equal []
1447
- end
1448
-
1449
- it "dataset associations with limited many_through_many associations should work correctly" do
1450
- Artist.many_through_many :first_two_tags, {:clone=>:first_two_tags}.merge(@els)
1451
- Artist.many_through_many :second_two_tags, {:clone=>:second_two_tags}.merge(@els)
1452
- Artist.many_through_many :not_first_tags, {:clone=>:not_first_tags}.merge(@els)
1453
- Artist.many_through_many :last_two_tags, {:clone=>:last_two_tags}.merge(@els)
1454
- @album.update(:artist => @artist)
1455
- tu, tv = @other_tags.call
1456
- al, ar, _ = @pr.call
1457
- al.update(:artist=>ar)
1458
- al.add_tag(tu)
1459
- ds = Artist.order(:name)
1460
-
1461
- ds.where(@artist.pk_hash).first_two_tags.all.must_equal [@tag, tu]
1462
- ds.where(@artist.pk_hash).second_two_tags.all.must_equal [tu, tv]
1463
- ds.where(@artist.pk_hash).not_first_tags.all.must_equal [tu, tv]
1464
- ds.where(@artist.pk_hash).last_two_tags.all.must_equal [tv, tu]
1465
- ds.where(ar.pk_hash).first_two_tags.all.must_equal [tu]
1466
- ds.where(ar.pk_hash).second_two_tags.all.must_equal []
1467
- ds.where(ar.pk_hash).not_first_tags.all.must_equal []
1468
- ds.where(ar.pk_hash).last_two_tags.all.must_equal [tu]
1469
-
1470
- Artist.many_through_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(:tags__name=>tu.name) end
1471
- Artist.many_through_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(:tags__name=>[tu.name, tv.name]) end
1472
-
1473
- ds.where(@artist.pk_hash).first_two_tags.all.must_equal [tu]
1474
- ds.where(@artist.pk_hash).second_two_tags.all.must_equal [tv]
1475
- ds.where(ar.pk_hash).first_two_tags.all.must_equal [tu]
1476
- ds.where(ar.pk_hash).second_two_tags.all.must_equal []
1477
-
1478
- al.add_tag(tv)
1479
- ds.where(@artist.pk_hash).first_two_tags.all.must_equal [tu]
1480
- ds.where(@artist.pk_hash).second_two_tags.all.must_equal [tv]
1481
- ds.where(ar.pk_hash).first_two_tags.all.must_equal [tu]
1482
- ds.where(ar.pk_hash).second_two_tags.all.must_equal [tv]
1483
- end
1484
- end
1485
-
1486
- BasicRegularAndCompositeKeyAssociations = shared_description do
1487
- describe "when filtering/excluding by associations" do
1488
- before do
1489
- @Artist = Artist.dataset
1490
- @Album = Album.dataset
1491
- @Tag = Tag.dataset
1492
- end
1493
-
1494
- include FilterByAssociations
1495
- end
1496
-
1497
- it "should return no objects if none are associated" do
1498
- @album.artist.must_equal nil
1499
- @artist.first_album.must_equal nil
1500
- @artist.albums.must_equal []
1501
- @album.tags.must_equal []
1502
- @album.alias_tags.must_equal []
1503
- @tag.albums.must_equal []
1504
- end
1505
-
1506
- it "should have add and set methods work any associated objects" do
1507
- @album.update(:artist => @artist)
1508
- @album.add_tag(@tag)
1509
-
1510
- @album.reload
1511
- @artist.reload
1512
- @tag.reload
1513
-
1514
- @album.artist.must_equal @artist
1515
- @artist.first_album.must_equal @album
1516
- @artist.albums.must_equal [@album]
1517
- @album.tags.must_equal [@tag]
1518
- @album.alias_tags.must_equal [@tag]
1519
- @tag.albums.must_equal [@album]
1520
- end
1521
-
1522
- it "should work correctly with prepared_statements_association plugin" do
1523
- @album.update(:artist => @artist)
1524
- @album.add_tag(@tag)
1525
-
1526
- @album.reload
1527
- @artist.reload
1528
- @tag.reload
1529
-
1530
- [Tag, Album, Artist].each{|x| x.plugin :prepared_statements_associations}
1531
- @album.artist.must_equal @artist
1532
- @artist.first_album.must_equal @album
1533
- @artist.albums.must_equal [@album]
1534
- @album.tags.must_equal [@tag]
1535
- @album.alias_tags.must_equal [@tag]
1536
- @tag.albums.must_equal [@album]
1537
- end
1538
-
1539
- it "should have working dataset associations" do
1540
- album, artist, tag = @pr.call
1541
-
1542
- Tag.albums.all.must_equal []
1543
- Album.artists.all.must_equal []
1544
- Album.tags.all.must_equal []
1545
- Album.alias_tags.all.must_equal []
1546
- Artist.albums.all.must_equal []
1547
- unless @no_many_through_many
1548
- Album.first_tags.all.must_equal []
1549
- Artist.tags.all.must_equal []
1550
- Artist.first_tags.all.must_equal []
1551
- end
1552
- Artist.albums.tags.all.must_equal []
1553
-
1554
- @album.update(:artist => @artist)
1555
- @album.add_tag(@tag)
1556
-
1557
- Tag.albums.all.must_equal [@album]
1558
- Album.artists.all.must_equal [@artist]
1559
- Album.tags.all.must_equal [@tag]
1560
- Album.alias_tags.all.must_equal [@tag]
1561
- Artist.albums.all.must_equal [@album]
1562
- unless @no_many_through_many
1563
- Album.first_tags.all.must_equal [@tag]
1564
- Artist.tags.all.must_equal [@tag]
1565
- Artist.first_tags.all.must_equal [@tag]
1566
- end
1567
- Artist.albums.tags.all.must_equal [@tag]
1568
-
1569
- album.add_tag(tag)
1570
- album.update(:artist => artist)
1571
-
1572
- Tag.albums.order(:name).all.must_equal [@album, album]
1573
- Album.artists.order(:name).all.must_equal [@artist, artist]
1574
- Album.tags.order(:name).all.must_equal [@tag, tag]
1575
- Album.alias_tags.order(:name).all.must_equal [@tag, tag]
1576
- Artist.albums.order(:name).all.must_equal [@album, album]
1577
- unless @no_many_through_many
1578
- Album.first_tags.order(:name).all.must_equal [@tag, tag]
1579
- Artist.tags.order(:name).all.must_equal [@tag, tag]
1580
- Artist.first_tags.order(:name).all.must_equal [@tag, tag]
1581
- end
1582
- Artist.albums.tags.order(:name).all.must_equal [@tag, tag]
1583
-
1584
- Tag.filter(Tag.qualified_primary_key_hash(tag.pk)).albums.all.must_equal [album]
1585
- Album.filter(Album.qualified_primary_key_hash(album.pk)).artists.all.must_equal [artist]
1586
- Album.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.must_equal [tag]
1587
- Album.filter(Album.qualified_primary_key_hash(album.pk)).alias_tags.all.must_equal [tag]
1588
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.all.must_equal [album]
1589
- unless @no_many_through_many
1590
- Album.filter(Album.qualified_primary_key_hash(album.pk)).first_tags.all.must_equal [tag]
1591
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).tags.all.must_equal [tag]
1592
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).first_tags.all.must_equal [tag]
1593
- end
1594
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.tags.all.must_equal [tag]
1595
-
1596
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.must_equal [tag]
1597
- Artist.filter(Artist.qualified_primary_key_hash(@artist.pk)).albums.filter(Album.qualified_primary_key_hash(@album.pk)).tags.all.must_equal [@tag]
1598
- Artist.filter(Artist.qualified_primary_key_hash(@artist.pk)).albums.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.must_equal []
1599
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.filter(Album.qualified_primary_key_hash(@album.pk)).tags.all.must_equal []
1600
- end
1601
-
1602
- it "should have remove methods work" do
1603
- @album.update(:artist => @artist)
1604
- @album.add_tag(@tag)
1605
-
1606
- @album.update(:artist => nil)
1607
- @album.remove_tag(@tag)
1608
-
1609
- @album.add_alias_tag(@tag)
1610
- @album.remove_alias_tag(@tag)
1611
-
1612
- @album.reload
1613
- @artist.reload
1614
- @tag.reload
1615
-
1616
- @album.artist.must_equal nil
1617
- @artist.albums.must_equal []
1618
- @album.tags.must_equal []
1619
- @tag.albums.must_equal []
1620
-
1621
- @album.add_alias_tag(@tag)
1622
- @album.remove_alias_tag(@tag)
1623
-
1624
- @album.reload
1625
- @album.alias_tags.must_equal []
1626
- end
1627
-
1628
- it "should have remove_all methods work" do
1629
- @artist.add_album(@album)
1630
- @album.add_tag(@tag)
1631
-
1632
- @album.remove_all_tags
1633
- @artist.remove_all_albums
1634
-
1635
- @album.reload
1636
- @artist.reload
1637
- @tag.reload
1638
-
1639
- @album.artist.must_equal nil
1640
- @artist.albums.must_equal []
1641
- @album.tags.must_equal []
1642
- @tag.albums.must_equal []
1643
-
1644
- @album.add_alias_tag(@tag)
1645
- @album.remove_all_alias_tags
1646
-
1647
- @album.reload
1648
- @album.alias_tags.must_equal []
1649
- end
1650
-
1651
- it "should eager load via eager correctly" do
1652
- @album.update(:artist => @artist)
1653
- @album.add_tag(@tag)
1654
-
1655
- a = Artist.eager(:albums=>[:tags, :alias_tags]).eager(:first_album).all
1656
- a.must_equal [@artist]
1657
- a.first.albums.must_equal [@album]
1658
- a.first.first_album.must_equal @album
1659
- a.first.albums.first.tags.must_equal [@tag]
1660
- a.first.albums.first.alias_tags.must_equal [@tag]
1661
-
1662
- a = Tag.eager(:albums=>:artist).all
1663
- a.must_equal [@tag]
1664
- a.first.albums.must_equal [@album]
1665
- a.first.albums.first.artist.must_equal @artist
1666
- end
1667
-
1668
- it "should eager load via eager_graph correctly" do
1669
- @album.update(:artist => @artist)
1670
- @album.add_tag(@tag)
1671
-
1672
- a = Artist.eager_graph(:albums=>[:tags, :alias_tags]).eager_graph(:first_album).all
1673
- a.must_equal [@artist]
1674
- a.first.albums.must_equal [@album]
1675
- a.first.first_album.must_equal @album
1676
- a.first.albums.first.tags.must_equal [@tag]
1677
- a.first.albums.first.alias_tags.must_equal [@tag]
1678
-
1679
- a = Tag.eager_graph(:albums=>:artist).all
1680
- a.must_equal [@tag]
1681
- a.first.albums.must_equal [@album]
1682
- a.first.albums.first.artist.must_equal @artist
1683
- end
1684
- end
1685
-
1686
- RegularAndCompositeKeyAssociations = shared_description do
1687
- include BasicRegularAndCompositeKeyAssociations
1688
-
1689
- describe "when filtering/excluding by associations when joining" do
1690
- def self_join(c)
1691
- c.join(Sequel.as(c.table_name, :b), Array(c.primary_key).zip(Array(c.primary_key))).select_all(c.table_name)
1692
- end
1693
-
1694
- before do
1695
- @Artist = self_join(Artist)
1696
- @Album = self_join(Album)
1697
- @Tag = self_join(Tag)
1698
- end
1699
-
1700
- include FilterByAssociations
1701
- end
1702
-
1703
- describe "with default/union :eager_limit_strategy" do
1704
- before do
1705
- @els = {}
1706
- end
1707
- include EagerLimitStrategies
1708
- end
1709
-
1710
- describe "with :eager_limit_strategy=>:ruby" do
1711
- before do
1712
- @els = {:eager_limit_strategy=>:ruby}
1713
- end
1714
- include EagerLimitStrategies
1715
- include EagerGraphLimitStrategies
1716
- end
1717
-
1718
- describe "with :eager_limit_strategy=>:distinct_on" do
1719
- before do
1720
- @els = {:eager_limit_strategy=>:distinct_on}
1721
- end
1722
-
1723
- include OneToOneEagerLimitStrategies
1724
- include OneThroughOneEagerLimitStrategies
1725
- include OneThroughManyEagerLimitStrategies
1726
- include OneToOneEagerGraphLimitStrategies
1727
- include OneThroughOneEagerGraphLimitStrategies
1728
- include OneThroughManyEagerGraphLimitStrategies
1729
- include FilterByAssociationsSingularLimitStrategies
1730
- end if DB.dataset.supports_ordered_distinct_on?
1731
-
1732
- describe "with :eager_limit_strategy=>:window_function" do
1733
- before do
1734
- @els = {:eager_limit_strategy=>:window_function}
1735
- end
1736
- include EagerLimitStrategies
1737
- include EagerGraphLimitStrategies
1738
- include FilterByAssociationsLimitStrategies
1739
- end if DB.dataset.supports_window_functions?
1740
-
1741
- it "should work with a many_through_many association" do
1742
- @album.update(:artist => @artist)
1743
- @album.add_tag(@tag)
1744
-
1745
- @album.reload
1746
- @artist.reload
1747
- @tag.reload
1748
-
1749
- @album.tags.must_equal [@tag]
1750
-
1751
- a = Artist.eager(:tags).all
1752
- a.must_equal [@artist]
1753
- a.first.tags.must_equal [@tag]
1754
-
1755
- a = Artist.eager_graph(:tags).all
1756
- a.must_equal [@artist]
1757
- a.first.tags.must_equal [@tag]
1758
-
1759
- a = Album.eager(:artist=>:tags).all
1760
- a.must_equal [@album]
1761
- a.first.artist.must_equal @artist
1762
- a.first.artist.tags.must_equal [@tag]
1763
-
1764
- a = Album.eager_graph(:artist=>:tags).all
1765
- a.must_equal [@album]
1766
- a.first.artist.must_equal @artist
1767
- a.first.artist.tags.must_equal [@tag]
1768
- end
1769
-
1770
- it "should work with a one_through_many association" do
1771
- @album.update(:artist => @artist)
1772
- @album.add_tag(@tag)
1773
-
1774
- @album.reload
1775
- @artist.reload
1776
- @tag.reload
1777
-
1778
- @album.tags.must_equal [@tag]
1779
-
1780
- a = Artist.eager(:first_tag).all
1781
- a.must_equal [@artist]
1782
- a.first.first_tag.must_equal @tag
1783
-
1784
- a = Artist.eager_graph(:first_tag).all
1785
- a.must_equal [@artist]
1786
- a.first.first_tag.must_equal @tag
1787
-
1788
- a = Album.eager(:artist=>:first_tag).all
1789
- a.must_equal [@album]
1790
- a.first.artist.must_equal @artist
1791
- a.first.artist.first_tag.must_equal @tag
1792
-
1793
- a = Album.eager_graph(:artist=>:first_tag).all
1794
- a.must_equal [@album]
1795
- a.first.artist.must_equal @artist
1796
- a.first.artist.first_tag.must_equal @tag
1797
- end
1798
- end
1799
-
1800
- describe "Sequel::Model Simple Associations" do
1801
- before(:all) do
1802
- @db = DB
1803
- @db.drop_table?(:albums_tags, :tags, :albums, :artists)
1804
- @db.create_table(:artists) do
1805
- primary_key :id
1806
- String :name
1807
- end
1808
- @db.create_table(:albums) do
1809
- primary_key :id
1810
- String :name
1811
- foreign_key :artist_id, :artists
1812
- end
1813
- @db.create_table(:tags) do
1814
- primary_key :id
1815
- String :name
1816
- end
1817
- @db.create_table(:albums_tags) do
1818
- foreign_key :album_id, :albums
1819
- foreign_key :tag_id, :tags
1820
- end
1821
- end
1822
- before do
1823
- [:albums_tags, :tags, :albums, :artists].each{|t| @db[t].delete}
1824
- class ::Artist < Sequel::Model(@db)
1825
- plugin :dataset_associations
1826
- one_to_many :albums, :order=>:name
1827
- one_to_one :first_album, :clone=>:albums
1828
- one_to_one :second_album, :clone=>:albums, :limit=>[nil, 1]
1829
- one_to_one :last_album, :class=>:Album, :order=>Sequel.desc(:name)
1830
- one_to_many :first_two_albums, :clone=>:albums, :limit=>2
1831
- one_to_many :second_two_albums, :clone=>:albums, :limit=>[2, 1]
1832
- one_to_many :not_first_albums, :clone=>:albums, :limit=>[nil, 1]
1833
- one_to_many :last_two_albums, :class=>:Album, :order=>Sequel.desc(:name), :limit=>2
1834
- one_to_many :a_albums, :clone=>:albums, :conditions=>{:name=>'Al'}
1835
- one_to_one :first_a_album, :clone=>:a_albums
1836
- plugin :many_through_many
1837
- many_through_many :tags, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]]
1838
- many_through_many :first_two_tags, :clone=>:tags, :order=>:tags__name, :limit=>2, :graph_order=>:name
1839
- many_through_many :second_two_tags, :clone=>:tags, :order=>:tags__name, :limit=>[2, 1], :graph_order=>:name
1840
- many_through_many :not_first_tags, :clone=>:tags, :order=>:tags__name, :limit=>[nil, 1], :graph_order=>:name
1841
- many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:tags__name), :limit=>2, :graph_order=>Sequel.desc(:name)
1842
- many_through_many :t_tags, :clone=>:tags, :conditions=>{:tags__name=>'T'}
1843
- one_through_many :first_tag, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :order=>:tags__name, :graph_order=>:name, :class=>:Tag
1844
- one_through_many :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
1845
- one_through_many :last_tag, :clone=>:first_tag, :order=>Sequel.desc(:tags__name), :graph_order=>Sequel.desc(:name)
1846
- one_through_many :t_tag, :clone=>:first_tag, :conditions=>{:tags__name=>'T'}
1847
- end
1848
- class ::Album < Sequel::Model(@db)
1849
- plugin :dataset_associations
1850
- many_to_one :artist, :reciprocal=>nil
1851
- many_to_one :a_artist, :clone=>:artist, :conditions=>{:name=>'Ar'}, :key=>:artist_id
1852
- many_to_many :tags, :right_key=>:tag_id
1853
- many_to_many :alias_tags, :clone=>:tags, :join_table=>:albums_tags___at
1854
- many_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
1855
- many_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
1856
- many_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
1857
- many_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
1858
- many_to_many :t_tags, :clone=>:tags, :conditions=>{:name=>'T'}
1859
- many_to_many :alias_t_tags, :clone=>:t_tags, :join_table=>:albums_tags___at
1860
- one_through_one :first_tag, :clone=>:tags, :order=>:name
1861
- one_through_one :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
1862
- one_through_one :last_tag, :clone=>:tags, :order=>Sequel.desc(:name)
1863
- one_through_one :t_tag, :clone=>:t_tags
1864
- one_through_one :alias_t_tag, :clone=>:alias_t_tags
1865
- end
1866
- class ::Tag < Sequel::Model(@db)
1867
- plugin :dataset_associations
1868
- many_to_many :albums
1869
- end
1870
- @album = Album.create(:name=>'Al')
1871
- @artist = Artist.create(:name=>'Ar')
1872
- @tag = Tag.create(:name=>'T')
1873
- @same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
1874
- @diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
1875
- @middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
1876
- @other_tags = lambda{t = [Tag.create(:name=>'U'), Tag.create(:name=>'V')]; @db[:albums_tags].insert([:album_id, :tag_id], Tag.select(@album.id, :id)); t}
1877
- @pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
1878
- @ins = lambda{@db[:albums_tags].insert(:tag_id=>@tag.id)}
1879
- end
1880
- after do
1881
- [:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
1882
- end
1883
- after(:all) do
1884
- @db.drop_table?(:albums_tags, :tags, :albums, :artists)
1885
- end
1886
-
1887
- include RegularAndCompositeKeyAssociations
1888
-
1889
- describe "with :correlated_subquery limit strategy" do
1890
- before do
1891
- @els = {:eager_limit_strategy=>:correlated_subquery}
1892
- end
1893
-
1894
- include OneToOneEagerGraphLimitStrategies
1895
- include OneToManyEagerGraphLimitStrategies
1896
- include FilterByAssociationsOneToOneLimitStrategies
1897
- include FilterByAssociationsOneToManyLimitStrategies
1898
- end if DB.dataset.supports_limits_in_correlated_subqueries?
1899
-
1900
- it "should handle eager loading limited associations for many objects" do
1901
- @db[:artists].import([:name], (1..99).map{|i| [i.to_s]})
1902
- artists = Artist.eager(:albums).all
1903
- artists.length.must_equal 100
1904
- artists.each{|a| a.albums.must_equal []}
1905
- artists = Artist.eager(:first_two_albums).all
1906
- artists.length.must_equal 100
1907
- artists.each{|a| a.first_two_albums.must_equal []}
1908
- @db[:albums].insert([:artist_id], @db[:artists].select(:id))
1909
- artists = Artist.eager(:albums).all
1910
- artists.length.must_equal 100
1911
- artists.each{|a| a.albums.length.must_equal 1}
1912
- artists = Artist.eager(:first_two_albums).all
1913
- artists.length.must_equal 100
1914
- artists.each{|a| a.first_two_albums.length.must_equal 1}
1915
- end
1916
-
1917
- it "should handle many_to_one associations with same name as :key" do
1918
- Album.def_column_alias(:artist_id_id, :artist_id)
1919
- Album.many_to_one :artist_id, :key_column =>:artist_id, :class=>Artist
1920
- @album.update(:artist_id_id => @artist.id)
1921
- @album.artist_id.must_equal @artist
1922
-
1923
- as = Album.eager(:artist_id).all
1924
- as.must_equal [@album]
1925
- as.map{|a| a.artist_id}.must_equal [@artist]
1926
-
1927
- as = Album.eager_graph(:artist_id).all
1928
- as.must_equal [@album]
1929
- as.map{|a| a.artist_id}.must_equal [@artist]
1930
- end
1931
-
1932
- it "should handle aliased tables when eager_graphing" do
1933
- @album.update(:artist => @artist)
1934
- @album.add_tag(@tag)
1935
-
1936
- Artist.set_dataset(:artists___ar)
1937
- Album.set_dataset(:albums___a)
1938
- Tag.set_dataset(:tags___t)
1939
- Artist.one_to_many :balbums, :class=>Album, :key=>:artist_id, :reciprocal=>nil
1940
- Album.many_to_many :btags, :class=>Tag, :join_table=>:albums_tags, :right_key=>:tag_id
1941
- Album.many_to_one :bartist, :class=>Artist, :key=>:artist_id
1942
- Tag.many_to_many :balbums, :class=>Album, :join_table=>:albums_tags, :right_key=>:album_id
1943
-
1944
- a = Artist.eager_graph(:balbums=>:btags).all
1945
- a.must_equal [@artist]
1946
- a.first.balbums.must_equal [@album]
1947
- a.first.balbums.first.btags.must_equal [@tag]
1948
-
1949
- a = Tag.eager_graph(:balbums=>:bartist).all
1950
- a.must_equal [@tag]
1951
- a.first.balbums.must_equal [@album]
1952
- a.first.balbums.first.bartist.must_equal @artist
1953
- end
1954
-
1955
- it "should have add method accept hashes and create new records" do
1956
- @artist.remove_all_albums
1957
- Album.dataset.delete
1958
- @album = @artist.add_album(:name=>'Al2')
1959
- Album.first[:name].must_equal 'Al2'
1960
- @artist.albums_dataset.first[:name].must_equal 'Al2'
1961
-
1962
- @album.remove_all_tags
1963
- Tag.dataset.delete
1964
- @album.add_tag(:name=>'T2')
1965
- Tag.first[:name].must_equal 'T2'
1966
- @album.tags_dataset.first[:name].must_equal 'T2'
1967
- end
1968
-
1969
- it "should have add method accept primary key and add related records" do
1970
- @artist.remove_all_albums
1971
- @artist.add_album(@album.id)
1972
- @artist.albums_dataset.first[:id].must_equal @album.id
1973
-
1974
- @album.remove_all_tags
1975
- @album.add_tag(@tag.id)
1976
- @album.tags_dataset.first[:id].must_equal @tag.id
1977
- end
1978
-
1979
- it "should have remove method accept primary key and remove related album" do
1980
- @artist.add_album(@album)
1981
- @artist.reload.remove_album(@album.id)
1982
- @artist.reload.albums.must_equal []
1983
-
1984
- @album.add_tag(@tag)
1985
- @album.reload.remove_tag(@tag.id)
1986
- @tag.reload.albums.must_equal []
1987
- end
1988
-
1989
- it "should handle dynamic callbacks for regular loading" do
1990
- @artist.add_album(@album)
1991
-
1992
- @artist.albums.must_equal [@album]
1993
- @artist.albums(proc{|ds| ds.exclude(:id=>@album.id)}).must_equal []
1994
- @artist.albums(proc{|ds| ds.filter(:id=>@album.id)}).must_equal [@album]
1995
-
1996
- @album.artist.must_equal @artist
1997
- @album.artist(proc{|ds| ds.exclude(:id=>@artist.id)}).must_equal nil
1998
- @album.artist(proc{|ds| ds.filter(:id=>@artist.id)}).must_equal @artist
1999
-
2000
- @artist.albums{|ds| ds.exclude(:id=>@album.id)}.must_equal []
2001
- @artist.albums{|ds| ds.filter(:id=>@album.id)}.must_equal [@album]
2002
- @album.artist{|ds| ds.exclude(:id=>@artist.id)}.must_equal nil
2003
- @album.artist{|ds| ds.filter(:id=>@artist.id)}.must_equal @artist
2004
- end
2005
-
2006
- it "should handle dynamic callbacks for eager loading via eager and eager_graph" do
2007
- @artist.add_album(@album)
2008
- @album.add_tag(@tag)
2009
- album2 = @artist.add_album(:name=>'Foo')
2010
- tag2 = album2.add_tag(:name=>'T2')
2011
-
2012
- artist = Artist.eager(:albums=>:tags).all.first
2013
- artist.albums.must_equal [@album, album2]
2014
- artist.albums.map{|x| x.tags}.must_equal [[@tag], [tag2]]
2015
-
2016
- artist = Artist.eager_graph(:albums=>:tags).all.first
2017
- artist.albums.must_equal [@album, album2]
2018
- artist.albums.map{|x| x.tags}.must_equal [[@tag], [tag2]]
2019
-
2020
- artist = Artist.eager(:albums=>{proc{|ds| ds.where(:id=>album2.id)}=>:tags}).all.first
2021
- artist.albums.must_equal [album2]
2022
- artist.albums.first.tags.must_equal [tag2]
2023
-
2024
- artist = Artist.eager_graph(:albums=>{proc{|ds| ds.where(:id=>album2.id)}=>:tags}).all.first
2025
- artist.albums.must_equal [album2]
2026
- artist.albums.first.tags.must_equal [tag2]
2027
- end
2028
-
2029
- it "should have remove method raise an error for one_to_many records if the object isn't already associated" do
2030
- proc{@artist.remove_album(@album.id)}.must_raise(Sequel::Error)
2031
- proc{@artist.remove_album(@album)}.must_raise(Sequel::Error)
2032
- end
2033
- end
2034
-
2035
- describe "Sequel::Model Composite Key Associations" do
2036
- before(:all) do
2037
- @db = DB
2038
- @db.drop_table?(:albums_tags, :tags, :albums, :artists)
2039
- @db.create_table(:artists) do
2040
- Integer :id1
2041
- Integer :id2
2042
- String :name
2043
- primary_key [:id1, :id2]
2044
- end
2045
- @db.create_table(:albums) do
2046
- Integer :id1
2047
- Integer :id2
2048
- String :name
2049
- Integer :artist_id1
2050
- Integer :artist_id2
2051
- foreign_key [:artist_id1, :artist_id2], :artists
2052
- primary_key [:id1, :id2]
2053
- end
2054
- @db.create_table(:tags) do
2055
- Integer :id1
2056
- Integer :id2
2057
- String :name
2058
- primary_key [:id1, :id2]
2059
- end
2060
- @db.create_table(:albums_tags) do
2061
- Integer :album_id1
2062
- Integer :album_id2
2063
- Integer :tag_id1
2064
- Integer :tag_id2
2065
- foreign_key [:album_id1, :album_id2], :albums
2066
- foreign_key [:tag_id1, :tag_id2], :tags
2067
- end
2068
- end
2069
- before do
2070
- [:albums_tags, :tags, :albums, :artists].each{|t| @db[t].delete}
2071
- class ::Artist < Sequel::Model(@db)
2072
- plugin :dataset_associations
2073
- set_primary_key [:id1, :id2]
2074
- unrestrict_primary_key
2075
- one_to_many :albums, :key=>[:artist_id1, :artist_id2], :order=>:name
2076
- one_to_one :first_album, :clone=>:albums
2077
- one_to_one :last_album, :clone=>:albums, :order=>Sequel.desc(:name)
2078
- one_to_one :second_album, :clone=>:albums, :limit=>[nil, 1]
2079
- one_to_many :first_two_albums, :clone=>:albums, :order=>:name, :limit=>2
2080
- one_to_many :second_two_albums, :clone=>:albums, :order=>:name, :limit=>[2, 1]
2081
- one_to_many :not_first_albums, :clone=>:albums, :order=>:name, :limit=>[nil, 1]
2082
- one_to_many :last_two_albums, :clone=>:albums, :order=>Sequel.desc(:name), :limit=>2
2083
- one_to_many :a_albums, :clone=>:albums do |ds| ds.where(:name=>'Al') end
2084
- one_to_one :first_a_album, :clone=>:a_albums
2085
- plugin :many_through_many
2086
- many_through_many :tags, [[:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]]
2087
- many_through_many :first_two_tags, :clone=>:tags, :order=>:tags__name, :limit=>2, :graph_order=>:name
2088
- many_through_many :second_two_tags, :clone=>:tags, :order=>:tags__name, :limit=>[2, 1], :graph_order=>:name
2089
- many_through_many :not_first_tags, :clone=>:tags, :order=>:tags__name, :limit=>[nil, 1], :graph_order=>:name
2090
- many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:tags__name), :limit=>2, :graph_order=>Sequel.desc(:name)
2091
- many_through_many :t_tags, :clone=>:tags do |ds| ds.where(:tags__name=>'T') end
2092
- one_through_many :first_tag, [[:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :order=>:tags__name, :graph_order=>:name, :class=>:Tag
2093
- one_through_many :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
2094
- one_through_many :last_tag, :clone=>:first_tag, :order=>Sequel.desc(:tags__name), :graph_order=>Sequel.desc(:name)
2095
- one_through_many :t_tag, :clone=>:first_tag do |ds| ds.where(:tags__name=>'T') end
2096
- end
2097
- class ::Album < Sequel::Model(@db)
2098
- plugin :dataset_associations
2099
- set_primary_key [:id1, :id2]
2100
- unrestrict_primary_key
2101
- many_to_one :artist, :key=>[:artist_id1, :artist_id2], :reciprocal=>nil
2102
- many_to_one(:a_artist, :clone=>:artist){|ds| ds.where(:name=>'Ar')}
2103
- many_to_many :tags, :left_key=>[:album_id1, :album_id2], :right_key=>[:tag_id1, :tag_id2]
2104
- many_to_many :alias_tags, :clone=>:tags, :join_table=>:albums_tags___at
2105
- many_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
2106
- many_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
2107
- many_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
2108
- many_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
2109
- many_to_many :t_tags, :clone=>:tags do |ds| ds.where(:name=>'T') end
2110
- many_to_many :alias_t_tags, :clone=>:t_tags, :join_table=>:albums_tags___at
2111
- one_through_one :first_tag, :clone=>:tags, :order=>:name
2112
- one_through_one :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
2113
- one_through_one :last_tag, :clone=>:tags, :order=>Sequel.desc(:name)
2114
- one_through_one :t_tag, :clone=>:t_tags
2115
- one_through_one :alias_t_tag, :clone=>:alias_t_tags
2116
- end
2117
- class ::Tag < Sequel::Model(@db)
2118
- plugin :dataset_associations
2119
- set_primary_key [:id1, :id2]
2120
- unrestrict_primary_key
2121
- many_to_many :albums, :right_key=>[:album_id1, :album_id2], :left_key=>[:tag_id1, :tag_id2]
2122
- end
2123
- @album = Album.create(:name=>'Al', :id1=>1, :id2=>2)
2124
- @artist = Artist.create(:name=>'Ar', :id1=>3, :id2=>4)
2125
- @tag = Tag.create(:name=>'T', :id1=>5, :id2=>6)
2126
- @same_album = lambda{Album.create(:name=>'Al', :id1=>7, :id2=>8, :artist_id1=>3, :artist_id2=>4)}
2127
- @diff_album = lambda{Album.create(:name=>'lA', :id1=>9, :id2=>10, :artist_id1=>3, :artist_id2=>4)}
2128
- @middle_album = lambda{Album.create(:name=>'Bl', :id1=>13, :id2=>14, :artist_id1=>3, :artist_id2=>4)}
2129
- @other_tags = lambda{t = [Tag.create(:name=>'U', :id1=>17, :id2=>18), Tag.create(:name=>'V', :id1=>19, :id2=>20)]; @db[:albums_tags].insert([:album_id1, :album_id2, :tag_id1, :tag_id2], Tag.select(1, 2, :id1, :id2)); t}
2130
- @pr = lambda{[Album.create(:name=>'Al2', :id1=>11, :id2=>12),Artist.create(:name=>'Ar2', :id1=>13, :id2=>14),Tag.create(:name=>'T2', :id1=>15, :id2=>16)]}
2131
- @ins = lambda{@db[:albums_tags].insert(:tag_id1=>@tag.id1, :tag_id2=>@tag.id2)}
2132
- end
2133
- after do
2134
- [:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
2135
- end
2136
- after(:all) do
2137
- @db.drop_table?(:albums_tags, :tags, :albums, :artists)
2138
- end
2139
-
2140
- include RegularAndCompositeKeyAssociations
2141
-
2142
- describe "with :correlated_subquery limit strategy" do
2143
- before do
2144
- @els = {:eager_limit_strategy=>:correlated_subquery}
2145
- end
2146
-
2147
- include OneToOneEagerGraphLimitStrategies
2148
- include OneToManyEagerGraphLimitStrategies
2149
- include FilterByAssociationsOneToOneLimitStrategies
2150
- include FilterByAssociationsOneToManyLimitStrategies
2151
- end if DB.dataset.supports_limits_in_correlated_subqueries? && DB.dataset.supports_multiple_column_in?
2152
-
2153
- it "should have add method accept hashes and create new records" do
2154
- @artist.remove_all_albums
2155
- Album.dataset.delete
2156
- @artist.add_album(:id1=>1, :id2=>2, :name=>'Al2')
2157
- Album.first[:name].must_equal 'Al2'
2158
- @artist.albums_dataset.first[:name].must_equal 'Al2'
2159
-
2160
- @album.remove_all_tags
2161
- Tag.dataset.delete
2162
- @album.add_tag(:id1=>1, :id2=>2, :name=>'T2')
2163
- Tag.first[:name].must_equal 'T2'
2164
- @album.tags_dataset.first[:name].must_equal 'T2'
2165
- end
2166
-
2167
- it "should have add method accept primary key and add related records" do
2168
- @artist.remove_all_albums
2169
- @artist.add_album([@album.id1, @album.id2])
2170
- @artist.albums_dataset.first.pk.must_equal [@album.id1, @album.id2]
2171
-
2172
- @album.remove_all_tags
2173
- @album.add_tag([@tag.id1, @tag.id2])
2174
- @album.tags_dataset.first.pk.must_equal [@tag.id1, @tag.id2]
2175
- end
2176
-
2177
- it "should have remove method accept primary key and remove related album" do
2178
- @artist.add_album(@album)
2179
- @artist.reload.remove_album([@album.id1, @album.id2])
2180
- @artist.reload.albums.must_equal []
2181
-
2182
- @album.add_tag(@tag)
2183
- @album.reload.remove_tag([@tag.id1, @tag.id2])
2184
- @tag.reload.albums.must_equal []
2185
- end
2186
-
2187
- it "should have remove method raise an error for one_to_many records if the object isn't already associated" do
2188
- proc{@artist.remove_album([@album.id1, @album.id2])}.must_raise(Sequel::Error)
2189
- proc{@artist.remove_album(@album)}.must_raise(Sequel::Error)
2190
- end
2191
- end
2192
-
2193
- describe "Sequel::Model pg_array_to_many" do
2194
- before(:all) do
2195
- @db = DB
2196
- @db.extension :pg_array
2197
- Sequel.extension :pg_array_ops
2198
- @db.drop_table?(:tags, :albums, :artists)
2199
- @db.create_table(:artists) do
2200
- primary_key :id
2201
- String :name
2202
- end
2203
- @db.create_table(:albums) do
2204
- primary_key :id
2205
- String :name
2206
- foreign_key :artist_id, :artists
2207
- column :tag_ids, 'int4[]'
2208
- end
2209
- @db.create_table(:tags) do
2210
- primary_key :id
2211
- String :name
2212
- end
2213
- end
2214
- before do
2215
- [:tags, :albums, :artists].each{|t| @db[t].delete}
2216
- class ::Artist < Sequel::Model(@db)
2217
- plugin :dataset_associations
2218
- one_to_many :albums, :order=>:name
2219
- one_to_one :first_album, :clone=>:albums
2220
- one_to_many :a_albums, :clone=>:albums do |ds| ds.where(:name=>'Al') end
2221
- one_to_one :first_a_album, :clone=>:a_albums
2222
- end
2223
- class ::Album < Sequel::Model(@db)
2224
- plugin :dataset_associations
2225
- plugin :pg_array_associations
2226
- many_to_one :artist, :reciprocal=>nil
2227
- many_to_one :a_artist, :clone=>:artist, :key=>:artist_id do |ds| ds.where(:name=>'Ar') end
2228
- pg_array_to_many :tags, :key=>:tag_ids, :save_after_modify=>true
2229
- pg_array_to_many :alias_tags, :clone=>:tags
2230
- pg_array_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
2231
- pg_array_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
2232
- pg_array_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
2233
- pg_array_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
2234
- pg_array_to_many :t_tags, :clone=>:tags do |ds| ds.where(:tags__name=>'T') end
2235
- pg_array_to_many :alias_t_tags, :clone=>:t_tags
2236
- end
2237
- class ::Tag < Sequel::Model(@db)
2238
- plugin :dataset_associations
2239
- plugin :pg_array_associations
2240
- many_to_pg_array :albums
2241
- end
2242
- @album = Album.create(:name=>'Al')
2243
- @artist = Artist.create(:name=>'Ar')
2244
- @tag = Tag.create(:name=>'T')
2245
- @many_to_many_method = :pg_array_to_many
2246
- @no_many_through_many = true
2247
- @same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
2248
- @diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
2249
- @middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
2250
- @other_tags = lambda{t = [Tag.create(:name=>'U'), Tag.create(:name=>'V')]; Tag.all{|x| @album.add_tag(x)}; t}
2251
- @pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
2252
- @ins = lambda{}
2253
- end
2254
- after do
2255
- [:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
2256
- end
2257
- after(:all) do
2258
- @db.drop_table?(:tags, :albums, :artists)
2259
- end
2260
-
2261
- include BasicRegularAndCompositeKeyAssociations
2262
- include ManyToManyEagerLimitStrategies
2263
- include ManyToManyEagerGraphLimitStrategies
2264
-
2265
- it "should handle adding and removing entries in array" do
2266
- a = Album.create
2267
- a.typecast_on_assignment = false
2268
- a.add_tag(@tag)
2269
- a.remove_tag(@tag)
2270
- a.save
2271
- end
2272
- end if DB.database_type == :postgres && [:postgres, :jdbc].include?(DB.adapter_scheme) && DB.server_version >= 90300
2273
-
2274
- describe "Sequel::Model many_to_pg_array" do
2275
- before(:all) do
2276
- @db = DB
2277
- @db.extension :pg_array
2278
- Sequel.extension :pg_array_ops
2279
- @db.drop_table?(:tags, :albums, :artists)
2280
- @db.create_table(:artists) do
2281
- primary_key :id
2282
- String :name
2283
- end
2284
- @db.create_table(:albums) do
2285
- primary_key :id
2286
- String :name
2287
- foreign_key :artist_id, :artists
2288
- end
2289
- @db.create_table(:tags) do
2290
- primary_key :id
2291
- String :name
2292
- column :album_ids, 'int4[]'
2293
- end
2294
- end
2295
- before do
2296
- [:tags, :albums, :artists].each{|t| @db[t].delete}
2297
- class ::Artist < Sequel::Model(@db)
2298
- plugin :dataset_associations
2299
- one_to_many :albums, :order=>:name
2300
- one_to_one :first_album, :class=>:Album, :order=>:name
2301
- one_to_many :a_albums, :clone=>:albums do |ds| ds.where(:name=>'Al') end
2302
- one_to_one :first_a_album, :clone=>:a_albums
2303
- end
2304
- class ::Album < Sequel::Model(@db)
2305
- plugin :dataset_associations
2306
- plugin :pg_array_associations
2307
- many_to_one :artist, :reciprocal=>nil
2308
- many_to_one :a_artist, :clone=>:artist, :key=>:artist_id do |ds| ds.where(:name=>'Ar') end
2309
- many_to_pg_array :tags
2310
- many_to_pg_array :alias_tags, :clone=>:tags
2311
- many_to_pg_array :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
2312
- many_to_pg_array :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
2313
- many_to_pg_array :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
2314
- many_to_pg_array :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
2315
- many_to_pg_array :t_tags, :clone=>:tags do |ds| ds.where(:tags__name=>'T') end
2316
- many_to_pg_array :alias_t_tags, :clone=>:t_tags
2317
- end
2318
- class ::Tag < Sequel::Model(@db)
2319
- plugin :dataset_associations
2320
- plugin :pg_array_associations
2321
- pg_array_to_many :albums, :save_after_modify=>true
2322
- end
2323
- @album = Album.create(:name=>'Al')
2324
- @artist = Artist.create(:name=>'Ar')
2325
- @tag = Tag.create(:name=>'T')
2326
- @many_to_many_method = :pg_array_to_many
2327
- @no_many_through_many = true
2328
- @same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
2329
- @diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
2330
- @middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
2331
- @other_tags = lambda{t = [Tag.create(:name=>'U'), Tag.create(:name=>'V')]; Tag.all{|x| @album.add_tag(x)}; @tag.refresh; t.each{|x| x.refresh}; t}
2332
- @pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
2333
- @ins = lambda{}
2334
- end
2335
- after do
2336
- [:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
2337
- end
2338
- after(:all) do
2339
- @db.drop_table?(:tags, :albums, :artists)
2340
- end
2341
-
2342
- include BasicRegularAndCompositeKeyAssociations
2343
- include ManyToManyEagerLimitStrategies
2344
- include ManyToManyEagerGraphLimitStrategies
2345
-
2346
- it "should handle adding and removing entries in array" do
2347
- a = Album.create
2348
- @tag.typecast_on_assignment = false
2349
- a.add_tag(@tag)
2350
- a.remove_tag(@tag)
2351
- end
2352
- end if DB.database_type == :postgres && [:postgres, :jdbc].include?(DB.adapter_scheme) && DB.server_version >= 90300
2353
-
2354
- describe "Sequel::Model Associations with clashing column names" do
2355
- before(:all) do
2356
- @db = DB
2357
- @db.drop_table?(:bars_foos, :bars, :foos)
2358
- @db.create_table(:foos) do
2359
- primary_key :id
2360
- Integer :object_id
2361
- end
2362
- @db.create_table(:bars) do
2363
- primary_key :id
2364
- Integer :object_id
2365
- end
2366
- @db.create_table(:bars_foos) do
2367
- Integer :foo_id
2368
- Integer :object_id
2369
- primary_key [:foo_id, :object_id]
2370
- end
2371
- end
2372
- before do
2373
- [:bars_foos, :bars, :foos].each{|t| @db[t].delete}
2374
- @Foo = Class.new(Sequel::Model(:foos))
2375
- @Bar = Class.new(Sequel::Model(:bars))
2376
- @Foo.def_column_alias(:obj_id, :object_id)
2377
- @Bar.def_column_alias(:obj_id, :object_id)
2378
- @Foo.one_to_many :bars, :primary_key=>:obj_id, :primary_key_column=>:object_id, :key=>:object_id, :key_method=>:obj_id, :class=>@Bar
2379
- @Foo.one_to_one :bar, :primary_key=>:obj_id, :primary_key_column=>:object_id, :key=>:object_id, :key_method=>:obj_id, :class=>@Bar
2380
- @Bar.many_to_one :foo, :key=>:obj_id, :key_column=>:object_id, :primary_key=>:object_id, :primary_key_method=>:obj_id, :class=>@Foo
2381
- @Foo.many_to_many :mtmbars, :join_table=>:bars_foos, :left_primary_key=>:obj_id, :left_primary_key_column=>:object_id, :right_primary_key=>:object_id, :right_primary_key_method=>:obj_id, :left_key=>:foo_id, :right_key=>:object_id, :class=>@Bar
2382
- @Foo.one_through_one :mtmbar, :join_table=>:bars_foos, :left_primary_key=>:obj_id, :left_primary_key_column=>:object_id, :right_primary_key=>:object_id, :right_primary_key_method=>:obj_id, :left_key=>:foo_id, :right_key=>:object_id, :class=>@Bar
2383
- @Bar.many_to_many :mtmfoos, :join_table=>:bars_foos, :left_primary_key=>:obj_id, :left_primary_key_column=>:object_id, :right_primary_key=>:object_id, :right_primary_key_method=>:obj_id, :left_key=>:object_id, :right_key=>:foo_id, :class=>@Foo
2384
- @foo = @Foo.create(:obj_id=>2)
2385
- @bar = @Bar.create(:obj_id=>2)
2386
- @Foo.db[:bars_foos].insert(2, 2)
2387
- end
2388
- after(:all) do
2389
- @db.drop_table?(:bars_foos, :bars, :foos)
2390
- end
2391
-
2392
- it "should have working regular association methods" do
2393
- @Bar.first.foo.must_equal @foo
2394
- @Foo.first.bars.must_equal [@bar]
2395
- @Foo.first.bar.must_equal @bar
2396
- @Foo.first.mtmbars.must_equal [@bar]
2397
- @Foo.first.mtmbar.must_equal @bar
2398
- @Bar.first.mtmfoos.must_equal [@foo]
2399
- end
2400
-
2401
- it "should have working eager loading methods" do
2402
- @Bar.eager(:foo).all.map{|o| [o, o.foo]}.must_equal [[@bar, @foo]]
2403
- @Foo.eager(:bars).all.map{|o| [o, o.bars]}.must_equal [[@foo, [@bar]]]
2404
- @Foo.eager(:bar).all.map{|o| [o, o.bar]}.must_equal [[@foo, @bar]]
2405
- @Foo.eager(:mtmbars).all.map{|o| [o, o.mtmbars]}.must_equal [[@foo, [@bar]]]
2406
- @Foo.eager(:mtmbar).all.map{|o| [o, o.mtmbar]}.must_equal [[@foo, @bar]]
2407
- @Bar.eager(:mtmfoos).all.map{|o| [o, o.mtmfoos]}.must_equal [[@bar, [@foo]]]
2408
- end
2409
-
2410
- it "should have working eager graphing methods" do
2411
- @Bar.eager_graph(:foo).all.map{|o| [o, o.foo]}.must_equal [[@bar, @foo]]
2412
- @Foo.eager_graph(:bars).all.map{|o| [o, o.bars]}.must_equal [[@foo, [@bar]]]
2413
- @Foo.eager_graph(:bar).all.map{|o| [o, o.bar]}.must_equal [[@foo, @bar]]
2414
- @Foo.eager_graph(:mtmbars).all.map{|o| [o, o.mtmbars]}.must_equal [[@foo, [@bar]]]
2415
- @Foo.eager_graph(:mtmbar).all.map{|o| [o, o.mtmbar]}.must_equal [[@foo, @bar]]
2416
- @Bar.eager_graph(:mtmfoos).all.map{|o| [o, o.mtmfoos]}.must_equal [[@bar, [@foo]]]
2417
- end
2418
-
2419
- it "should have working modification methods" do
2420
- b = @Bar.create(:obj_id=>3)
2421
- f = @Foo.create(:obj_id=>3)
2422
-
2423
- @bar.foo = f
2424
- @bar.obj_id.must_equal 3
2425
- @foo.bar = @bar
2426
- @bar.obj_id.must_equal 2
2427
-
2428
- @foo.add_bar(b)
2429
- @foo.bars.sort_by{|x| x.id}.must_equal [@bar, b]
2430
- @foo.remove_bar(b)
2431
- @foo.bars.must_equal [@bar]
2432
- @foo.remove_all_bars
2433
- @foo.bars.must_equal []
2434
-
2435
- @bar.refresh.update(:obj_id=>2)
2436
- b.refresh.update(:obj_id=>3)
2437
- @foo.mtmbars.must_equal [@bar]
2438
- @foo.remove_all_mtmbars
2439
- @foo.mtmbars.must_equal []
2440
- @foo.add_mtmbar(b)
2441
- @foo.mtmbars.must_equal [b]
2442
- @foo.remove_mtmbar(b)
2443
- @foo.mtmbars.must_equal []
2444
-
2445
- @bar.add_mtmfoo(f)
2446
- @bar.mtmfoos.must_equal [f]
2447
- @bar.remove_all_mtmfoos
2448
- @bar.mtmfoos.must_equal []
2449
- @bar.add_mtmfoo(f)
2450
- @bar.mtmfoos.must_equal [f]
2451
- @bar.remove_mtmfoo(f)
2452
- @bar.mtmfoos.must_equal []
2453
- end
2454
- end