sequel 5.8.0 → 5.38.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 (510) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +409 -1795
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +4 -4
  5. data/bin/sequel +4 -0
  6. data/doc/advanced_associations.rdoc +136 -18
  7. data/doc/association_basics.rdoc +10 -5
  8. data/doc/cheat_sheet.rdoc +1 -0
  9. data/doc/code_order.rdoc +12 -2
  10. data/doc/dataset_filtering.rdoc +17 -2
  11. data/doc/mass_assignment.rdoc +3 -3
  12. data/doc/model_dataset_method_design.rdoc +1 -1
  13. data/doc/model_plugins.rdoc +1 -1
  14. data/doc/opening_databases.rdoc +30 -8
  15. data/doc/postgresql.rdoc +107 -2
  16. data/doc/release_notes/5.10.0.txt +84 -0
  17. data/doc/release_notes/5.11.0.txt +83 -0
  18. data/doc/release_notes/5.12.0.txt +141 -0
  19. data/doc/release_notes/5.13.0.txt +27 -0
  20. data/doc/release_notes/5.14.0.txt +63 -0
  21. data/doc/release_notes/5.15.0.txt +39 -0
  22. data/doc/release_notes/5.16.0.txt +110 -0
  23. data/doc/release_notes/5.17.0.txt +31 -0
  24. data/doc/release_notes/5.18.0.txt +69 -0
  25. data/doc/release_notes/5.19.0.txt +28 -0
  26. data/doc/release_notes/5.20.0.txt +89 -0
  27. data/doc/release_notes/5.21.0.txt +87 -0
  28. data/doc/release_notes/5.22.0.txt +48 -0
  29. data/doc/release_notes/5.23.0.txt +56 -0
  30. data/doc/release_notes/5.24.0.txt +56 -0
  31. data/doc/release_notes/5.25.0.txt +32 -0
  32. data/doc/release_notes/5.26.0.txt +35 -0
  33. data/doc/release_notes/5.27.0.txt +21 -0
  34. data/doc/release_notes/5.28.0.txt +16 -0
  35. data/doc/release_notes/5.29.0.txt +22 -0
  36. data/doc/release_notes/5.30.0.txt +20 -0
  37. data/doc/release_notes/5.31.0.txt +148 -0
  38. data/doc/release_notes/5.32.0.txt +46 -0
  39. data/doc/release_notes/5.33.0.txt +24 -0
  40. data/doc/release_notes/5.34.0.txt +40 -0
  41. data/doc/release_notes/5.35.0.txt +56 -0
  42. data/doc/release_notes/5.36.0.txt +60 -0
  43. data/doc/release_notes/5.37.0.txt +30 -0
  44. data/doc/release_notes/5.38.0.txt +28 -0
  45. data/doc/release_notes/5.9.0.txt +99 -0
  46. data/doc/security.rdoc +10 -0
  47. data/doc/sharding.rdoc +42 -28
  48. data/doc/sql.rdoc +12 -0
  49. data/doc/testing.rdoc +24 -17
  50. data/doc/transactions.rdoc +78 -0
  51. data/doc/validations.rdoc +2 -2
  52. data/lib/sequel/adapters/ado.rb +26 -18
  53. data/lib/sequel/adapters/ado/access.rb +2 -2
  54. data/lib/sequel/adapters/ado/mssql.rb +5 -8
  55. data/lib/sequel/adapters/amalgalite.rb +1 -1
  56. data/lib/sequel/adapters/jdbc.rb +71 -27
  57. data/lib/sequel/adapters/jdbc/mysql.rb +6 -6
  58. data/lib/sequel/adapters/jdbc/oracle.rb +7 -6
  59. data/lib/sequel/adapters/jdbc/postgresql.rb +17 -28
  60. data/lib/sequel/adapters/jdbc/sqlanywhere.rb +5 -6
  61. data/lib/sequel/adapters/jdbc/sqlite.rb +33 -2
  62. data/lib/sequel/adapters/jdbc/sqlserver.rb +4 -3
  63. data/lib/sequel/adapters/jdbc/transactions.rb +14 -28
  64. data/lib/sequel/adapters/mysql.rb +14 -15
  65. data/lib/sequel/adapters/mysql2.rb +5 -3
  66. data/lib/sequel/adapters/odbc.rb +4 -6
  67. data/lib/sequel/adapters/oracle.rb +7 -7
  68. data/lib/sequel/adapters/postgres.rb +52 -16
  69. data/lib/sequel/adapters/shared/access.rb +16 -12
  70. data/lib/sequel/adapters/shared/db2.rb +5 -0
  71. data/lib/sequel/adapters/shared/mssql.rb +41 -18
  72. data/lib/sequel/adapters/shared/mysql.rb +66 -19
  73. data/lib/sequel/adapters/shared/oracle.rb +29 -23
  74. data/lib/sequel/adapters/shared/postgres.rb +341 -95
  75. data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
  76. data/lib/sequel/adapters/shared/sqlite.rb +174 -21
  77. data/lib/sequel/adapters/sqlanywhere.rb +33 -17
  78. data/lib/sequel/adapters/sqlite.rb +78 -68
  79. data/lib/sequel/adapters/tinytds.rb +14 -6
  80. data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +2 -5
  81. data/lib/sequel/adapters/utils/mysql_mysql2.rb +5 -1
  82. data/lib/sequel/connection_pool.rb +2 -6
  83. data/lib/sequel/connection_pool/sharded_single.rb +7 -4
  84. data/lib/sequel/connection_pool/sharded_threaded.rb +32 -21
  85. data/lib/sequel/connection_pool/single.rb +1 -1
  86. data/lib/sequel/connection_pool/threaded.rb +26 -11
  87. data/lib/sequel/core.rb +327 -319
  88. data/lib/sequel/database/connecting.rb +7 -8
  89. data/lib/sequel/database/logging.rb +7 -1
  90. data/lib/sequel/database/misc.rb +68 -34
  91. data/lib/sequel/database/query.rb +6 -4
  92. data/lib/sequel/database/schema_generator.rb +31 -11
  93. data/lib/sequel/database/schema_methods.rb +32 -22
  94. data/lib/sequel/database/transactions.rb +129 -25
  95. data/lib/sequel/dataset.rb +4 -2
  96. data/lib/sequel/dataset/actions.rb +34 -23
  97. data/lib/sequel/dataset/features.rb +34 -0
  98. data/lib/sequel/dataset/graph.rb +27 -11
  99. data/lib/sequel/dataset/misc.rb +17 -3
  100. data/lib/sequel/dataset/placeholder_literalizer.rb +50 -21
  101. data/lib/sequel/dataset/prepared_statements.rb +96 -26
  102. data/lib/sequel/dataset/query.rb +43 -8
  103. data/lib/sequel/dataset/sql.rb +189 -41
  104. data/lib/sequel/deprecated.rb +3 -1
  105. data/lib/sequel/exceptions.rb +2 -0
  106. data/lib/sequel/extensions/_pretty_table.rb +1 -2
  107. data/lib/sequel/extensions/any_not_empty.rb +45 -0
  108. data/lib/sequel/extensions/caller_logging.rb +79 -0
  109. data/lib/sequel/extensions/columns_introspection.rb +1 -2
  110. data/lib/sequel/extensions/connection_expiration.rb +6 -6
  111. data/lib/sequel/extensions/connection_validator.rb +7 -6
  112. data/lib/sequel/extensions/constant_sql_override.rb +65 -0
  113. data/lib/sequel/extensions/constraint_validations.rb +53 -28
  114. data/lib/sequel/extensions/core_refinements.rb +2 -0
  115. data/lib/sequel/extensions/duplicate_columns_handler.rb +2 -0
  116. data/lib/sequel/extensions/escaped_like.rb +100 -0
  117. data/lib/sequel/extensions/eval_inspect.rb +3 -1
  118. data/lib/sequel/extensions/exclude_or_null.rb +68 -0
  119. data/lib/sequel/extensions/fiber_concurrency.rb +24 -0
  120. data/lib/sequel/extensions/index_caching.rb +9 -7
  121. data/lib/sequel/extensions/integer64.rb +3 -1
  122. data/lib/sequel/extensions/looser_typecasting.rb +3 -3
  123. data/lib/sequel/extensions/migration.rb +13 -6
  124. data/lib/sequel/extensions/named_timezones.rb +84 -23
  125. data/lib/sequel/extensions/pg_array.rb +87 -79
  126. data/lib/sequel/extensions/pg_array_ops.rb +14 -6
  127. data/lib/sequel/extensions/pg_enum.rb +34 -18
  128. data/lib/sequel/extensions/pg_extended_date_support.rb +34 -14
  129. data/lib/sequel/extensions/pg_hstore.rb +6 -0
  130. data/lib/sequel/extensions/pg_hstore_ops.rb +2 -0
  131. data/lib/sequel/extensions/pg_inet.rb +15 -5
  132. data/lib/sequel/extensions/pg_interval.rb +2 -0
  133. data/lib/sequel/extensions/pg_json.rb +387 -123
  134. data/lib/sequel/extensions/pg_json_ops.rb +168 -0
  135. data/lib/sequel/extensions/pg_range.rb +20 -10
  136. data/lib/sequel/extensions/pg_range_ops.rb +2 -0
  137. data/lib/sequel/extensions/pg_row.rb +3 -2
  138. data/lib/sequel/extensions/pg_row_ops.rb +24 -0
  139. data/lib/sequel/extensions/pg_static_cache_updater.rb +2 -2
  140. data/lib/sequel/extensions/pg_timestamptz.rb +2 -0
  141. data/lib/sequel/extensions/query.rb +1 -0
  142. data/lib/sequel/extensions/run_transaction_hooks.rb +72 -0
  143. data/lib/sequel/extensions/s.rb +2 -0
  144. data/lib/sequel/extensions/schema_dumper.rb +13 -7
  145. data/lib/sequel/extensions/sequel_4_dataset_methods.rb +4 -2
  146. data/lib/sequel/extensions/server_block.rb +18 -7
  147. data/lib/sequel/extensions/sql_comments.rb +2 -2
  148. data/lib/sequel/extensions/symbol_aref_refinement.rb +2 -0
  149. data/lib/sequel/extensions/symbol_as_refinement.rb +2 -0
  150. data/lib/sequel/extensions/to_dot.rb +9 -3
  151. data/lib/sequel/model.rb +3 -1
  152. data/lib/sequel/model/associations.rb +403 -69
  153. data/lib/sequel/model/base.rb +170 -90
  154. data/lib/sequel/model/plugins.rb +105 -0
  155. data/lib/sequel/plugins/after_initialize.rb +1 -1
  156. data/lib/sequel/plugins/association_dependencies.rb +3 -3
  157. data/lib/sequel/plugins/association_lazy_eager_option.rb +66 -0
  158. data/lib/sequel/plugins/association_multi_add_remove.rb +85 -0
  159. data/lib/sequel/plugins/association_pks.rb +74 -22
  160. data/lib/sequel/plugins/association_proxies.rb +6 -2
  161. data/lib/sequel/plugins/auto_validations.rb +36 -17
  162. data/lib/sequel/plugins/blacklist_security.rb +1 -2
  163. data/lib/sequel/plugins/boolean_subsets.rb +4 -1
  164. data/lib/sequel/plugins/caching.rb +3 -0
  165. data/lib/sequel/plugins/class_table_inheritance.rb +62 -34
  166. data/lib/sequel/plugins/composition.rb +13 -9
  167. data/lib/sequel/plugins/csv_serializer.rb +28 -9
  168. data/lib/sequel/plugins/defaults_setter.rb +2 -2
  169. data/lib/sequel/plugins/dirty.rb +60 -22
  170. data/lib/sequel/plugins/eager_graph_eager.rb +139 -0
  171. data/lib/sequel/plugins/empty_failure_backtraces.rb +38 -0
  172. data/lib/sequel/plugins/finder.rb +2 -2
  173. data/lib/sequel/plugins/forbid_lazy_load.rb +216 -0
  174. data/lib/sequel/plugins/hook_class_methods.rb +17 -5
  175. data/lib/sequel/plugins/insert_conflict.rb +72 -0
  176. data/lib/sequel/plugins/instance_specific_default.rb +113 -0
  177. data/lib/sequel/plugins/inverted_subsets.rb +2 -2
  178. data/lib/sequel/plugins/json_serializer.rb +21 -14
  179. data/lib/sequel/plugins/lazy_attributes.rb +1 -1
  180. data/lib/sequel/plugins/list.rb +22 -10
  181. data/lib/sequel/plugins/many_through_many.rb +1 -1
  182. data/lib/sequel/plugins/nested_attributes.rb +27 -5
  183. data/lib/sequel/plugins/pg_array_associations.rb +12 -9
  184. data/lib/sequel/plugins/pg_auto_constraint_validations.rb +149 -61
  185. data/lib/sequel/plugins/prepared_statements.rb +6 -12
  186. data/lib/sequel/plugins/prepared_statements_safe.rb +1 -3
  187. data/lib/sequel/plugins/rcte_tree.rb +20 -22
  188. data/lib/sequel/plugins/sharding.rb +13 -7
  189. data/lib/sequel/plugins/single_table_inheritance.rb +20 -15
  190. data/lib/sequel/plugins/skip_saving_columns.rb +108 -0
  191. data/lib/sequel/plugins/static_cache.rb +36 -17
  192. data/lib/sequel/plugins/static_cache_cache.rb +53 -0
  193. data/lib/sequel/plugins/string_stripper.rb +1 -1
  194. data/lib/sequel/plugins/subclasses.rb +2 -0
  195. data/lib/sequel/plugins/subset_conditions.rb +2 -2
  196. data/lib/sequel/plugins/tactical_eager_loading.rb +73 -2
  197. data/lib/sequel/plugins/throw_failures.rb +110 -0
  198. data/lib/sequel/plugins/tree.rb +49 -31
  199. data/lib/sequel/plugins/typecast_on_load.rb +3 -2
  200. data/lib/sequel/plugins/validation_class_methods.rb +11 -5
  201. data/lib/sequel/plugins/validation_helpers.rb +2 -2
  202. data/lib/sequel/sql.rb +120 -30
  203. data/lib/sequel/timezones.rb +55 -14
  204. data/lib/sequel/version.rb +6 -1
  205. metadata +101 -361
  206. data/Rakefile +0 -151
  207. data/doc/release_notes/4.0.0.txt +0 -262
  208. data/doc/release_notes/4.1.0.txt +0 -85
  209. data/doc/release_notes/4.10.0.txt +0 -226
  210. data/doc/release_notes/4.11.0.txt +0 -147
  211. data/doc/release_notes/4.12.0.txt +0 -105
  212. data/doc/release_notes/4.13.0.txt +0 -169
  213. data/doc/release_notes/4.14.0.txt +0 -68
  214. data/doc/release_notes/4.15.0.txt +0 -56
  215. data/doc/release_notes/4.16.0.txt +0 -36
  216. data/doc/release_notes/4.17.0.txt +0 -38
  217. data/doc/release_notes/4.18.0.txt +0 -36
  218. data/doc/release_notes/4.19.0.txt +0 -45
  219. data/doc/release_notes/4.2.0.txt +0 -129
  220. data/doc/release_notes/4.20.0.txt +0 -79
  221. data/doc/release_notes/4.21.0.txt +0 -94
  222. data/doc/release_notes/4.22.0.txt +0 -72
  223. data/doc/release_notes/4.23.0.txt +0 -65
  224. data/doc/release_notes/4.24.0.txt +0 -99
  225. data/doc/release_notes/4.25.0.txt +0 -181
  226. data/doc/release_notes/4.26.0.txt +0 -44
  227. data/doc/release_notes/4.27.0.txt +0 -78
  228. data/doc/release_notes/4.28.0.txt +0 -57
  229. data/doc/release_notes/4.29.0.txt +0 -41
  230. data/doc/release_notes/4.3.0.txt +0 -40
  231. data/doc/release_notes/4.30.0.txt +0 -37
  232. data/doc/release_notes/4.31.0.txt +0 -57
  233. data/doc/release_notes/4.32.0.txt +0 -132
  234. data/doc/release_notes/4.33.0.txt +0 -88
  235. data/doc/release_notes/4.34.0.txt +0 -86
  236. data/doc/release_notes/4.35.0.txt +0 -130
  237. data/doc/release_notes/4.36.0.txt +0 -116
  238. data/doc/release_notes/4.37.0.txt +0 -50
  239. data/doc/release_notes/4.38.0.txt +0 -67
  240. data/doc/release_notes/4.39.0.txt +0 -127
  241. data/doc/release_notes/4.4.0.txt +0 -92
  242. data/doc/release_notes/4.40.0.txt +0 -179
  243. data/doc/release_notes/4.41.0.txt +0 -77
  244. data/doc/release_notes/4.42.0.txt +0 -221
  245. data/doc/release_notes/4.43.0.txt +0 -87
  246. data/doc/release_notes/4.44.0.txt +0 -125
  247. data/doc/release_notes/4.45.0.txt +0 -370
  248. data/doc/release_notes/4.46.0.txt +0 -404
  249. data/doc/release_notes/4.47.0.txt +0 -56
  250. data/doc/release_notes/4.48.0.txt +0 -293
  251. data/doc/release_notes/4.49.0.txt +0 -222
  252. data/doc/release_notes/4.5.0.txt +0 -34
  253. data/doc/release_notes/4.6.0.txt +0 -30
  254. data/doc/release_notes/4.7.0.txt +0 -103
  255. data/doc/release_notes/4.8.0.txt +0 -175
  256. data/doc/release_notes/4.9.0.txt +0 -190
  257. data/spec/adapter_spec.rb +0 -4
  258. data/spec/adapters/db2_spec.rb +0 -170
  259. data/spec/adapters/mssql_spec.rb +0 -804
  260. data/spec/adapters/mysql_spec.rb +0 -1041
  261. data/spec/adapters/oracle_spec.rb +0 -327
  262. data/spec/adapters/postgres_spec.rb +0 -4000
  263. data/spec/adapters/spec_helper.rb +0 -43
  264. data/spec/adapters/sqlanywhere_spec.rb +0 -97
  265. data/spec/adapters/sqlite_spec.rb +0 -600
  266. data/spec/bin_spec.rb +0 -269
  267. data/spec/core/connection_pool_spec.rb +0 -1228
  268. data/spec/core/database_spec.rb +0 -2673
  269. data/spec/core/dataset_spec.rb +0 -5419
  270. data/spec/core/deprecated_spec.rb +0 -70
  271. data/spec/core/expression_filters_spec.rb +0 -1344
  272. data/spec/core/mock_adapter_spec.rb +0 -722
  273. data/spec/core/object_graph_spec.rb +0 -306
  274. data/spec/core/placeholder_literalizer_spec.rb +0 -166
  275. data/spec/core/schema_generator_spec.rb +0 -214
  276. data/spec/core/schema_spec.rb +0 -1820
  277. data/spec/core/spec_helper.rb +0 -23
  278. data/spec/core/version_spec.rb +0 -7
  279. data/spec/core_extensions_spec.rb +0 -762
  280. data/spec/core_model_spec.rb +0 -2
  281. data/spec/core_spec.rb +0 -1
  282. data/spec/deprecation_helper.rb +0 -30
  283. data/spec/extensions/accessed_columns_spec.rb +0 -51
  284. data/spec/extensions/active_model_spec.rb +0 -99
  285. data/spec/extensions/after_initialize_spec.rb +0 -24
  286. data/spec/extensions/arbitrary_servers_spec.rb +0 -109
  287. data/spec/extensions/association_dependencies_spec.rb +0 -125
  288. data/spec/extensions/association_pks_spec.rb +0 -423
  289. data/spec/extensions/association_proxies_spec.rb +0 -100
  290. data/spec/extensions/auto_literal_strings_spec.rb +0 -205
  291. data/spec/extensions/auto_validations_spec.rb +0 -202
  292. data/spec/extensions/blacklist_security_spec.rb +0 -95
  293. data/spec/extensions/blank_spec.rb +0 -69
  294. data/spec/extensions/boolean_readers_spec.rb +0 -93
  295. data/spec/extensions/boolean_subsets_spec.rb +0 -47
  296. data/spec/extensions/caching_spec.rb +0 -273
  297. data/spec/extensions/class_table_inheritance_spec.rb +0 -568
  298. data/spec/extensions/column_conflicts_spec.rb +0 -75
  299. data/spec/extensions/column_select_spec.rb +0 -129
  300. data/spec/extensions/columns_introspection_spec.rb +0 -90
  301. data/spec/extensions/columns_updated_spec.rb +0 -35
  302. data/spec/extensions/composition_spec.rb +0 -248
  303. data/spec/extensions/connection_expiration_spec.rb +0 -133
  304. data/spec/extensions/connection_validator_spec.rb +0 -127
  305. data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
  306. data/spec/extensions/constraint_validations_spec.rb +0 -395
  307. data/spec/extensions/core_refinements_spec.rb +0 -528
  308. data/spec/extensions/csv_serializer_spec.rb +0 -183
  309. data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
  310. data/spec/extensions/dataset_associations_spec.rb +0 -365
  311. data/spec/extensions/dataset_source_alias_spec.rb +0 -51
  312. data/spec/extensions/date_arithmetic_spec.rb +0 -181
  313. data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
  314. data/spec/extensions/def_dataset_method_spec.rb +0 -100
  315. data/spec/extensions/defaults_setter_spec.rb +0 -141
  316. data/spec/extensions/delay_add_association_spec.rb +0 -73
  317. data/spec/extensions/dirty_spec.rb +0 -189
  318. data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
  319. data/spec/extensions/eager_each_spec.rb +0 -62
  320. data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
  321. data/spec/extensions/error_splitter_spec.rb +0 -18
  322. data/spec/extensions/error_sql_spec.rb +0 -20
  323. data/spec/extensions/eval_inspect_spec.rb +0 -74
  324. data/spec/extensions/finder_spec.rb +0 -260
  325. data/spec/extensions/force_encoding_spec.rb +0 -126
  326. data/spec/extensions/freeze_datasets_spec.rb +0 -31
  327. data/spec/extensions/graph_each_spec.rb +0 -113
  328. data/spec/extensions/hook_class_methods_spec.rb +0 -380
  329. data/spec/extensions/identifier_mangling_spec.rb +0 -201
  330. data/spec/extensions/implicit_subquery_spec.rb +0 -58
  331. data/spec/extensions/index_caching_spec.rb +0 -66
  332. data/spec/extensions/inflector_spec.rb +0 -183
  333. data/spec/extensions/input_transformer_spec.rb +0 -69
  334. data/spec/extensions/insert_returning_select_spec.rb +0 -72
  335. data/spec/extensions/instance_filters_spec.rb +0 -79
  336. data/spec/extensions/instance_hooks_spec.rb +0 -246
  337. data/spec/extensions/integer64_spec.rb +0 -22
  338. data/spec/extensions/inverted_subsets_spec.rb +0 -33
  339. data/spec/extensions/json_serializer_spec.rb +0 -336
  340. data/spec/extensions/lazy_attributes_spec.rb +0 -183
  341. data/spec/extensions/list_spec.rb +0 -275
  342. data/spec/extensions/looser_typecasting_spec.rb +0 -43
  343. data/spec/extensions/many_through_many_spec.rb +0 -2177
  344. data/spec/extensions/migration_spec.rb +0 -840
  345. data/spec/extensions/modification_detection_spec.rb +0 -93
  346. data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
  347. data/spec/extensions/named_timezones_spec.rb +0 -109
  348. data/spec/extensions/nested_attributes_spec.rb +0 -703
  349. data/spec/extensions/null_dataset_spec.rb +0 -85
  350. data/spec/extensions/optimistic_locking_spec.rb +0 -127
  351. data/spec/extensions/pagination_spec.rb +0 -116
  352. data/spec/extensions/pg_array_associations_spec.rb +0 -802
  353. data/spec/extensions/pg_array_ops_spec.rb +0 -144
  354. data/spec/extensions/pg_array_spec.rb +0 -398
  355. data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -165
  356. data/spec/extensions/pg_enum_spec.rb +0 -113
  357. data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
  358. data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
  359. data/spec/extensions/pg_hstore_spec.rb +0 -219
  360. data/spec/extensions/pg_inet_ops_spec.rb +0 -102
  361. data/spec/extensions/pg_inet_spec.rb +0 -72
  362. data/spec/extensions/pg_interval_spec.rb +0 -103
  363. data/spec/extensions/pg_json_ops_spec.rb +0 -289
  364. data/spec/extensions/pg_json_spec.rb +0 -262
  365. data/spec/extensions/pg_loose_count_spec.rb +0 -23
  366. data/spec/extensions/pg_range_ops_spec.rb +0 -60
  367. data/spec/extensions/pg_range_spec.rb +0 -487
  368. data/spec/extensions/pg_row_ops_spec.rb +0 -61
  369. data/spec/extensions/pg_row_plugin_spec.rb +0 -60
  370. data/spec/extensions/pg_row_spec.rb +0 -363
  371. data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
  372. data/spec/extensions/pg_timestamptz_spec.rb +0 -17
  373. data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
  374. data/spec/extensions/prepared_statements_spec.rb +0 -182
  375. data/spec/extensions/pretty_table_spec.rb +0 -123
  376. data/spec/extensions/query_spec.rb +0 -94
  377. data/spec/extensions/rcte_tree_spec.rb +0 -381
  378. data/spec/extensions/round_timestamps_spec.rb +0 -39
  379. data/spec/extensions/s_spec.rb +0 -60
  380. data/spec/extensions/schema_caching_spec.rb +0 -64
  381. data/spec/extensions/schema_dumper_spec.rb +0 -868
  382. data/spec/extensions/select_remove_spec.rb +0 -38
  383. data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
  384. data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
  385. data/spec/extensions/serialization_spec.rb +0 -365
  386. data/spec/extensions/server_block_spec.rb +0 -97
  387. data/spec/extensions/server_logging_spec.rb +0 -45
  388. data/spec/extensions/sharding_spec.rb +0 -189
  389. data/spec/extensions/shared_caching_spec.rb +0 -151
  390. data/spec/extensions/single_table_inheritance_spec.rb +0 -347
  391. data/spec/extensions/singular_table_names_spec.rb +0 -22
  392. data/spec/extensions/skip_create_refresh_spec.rb +0 -18
  393. data/spec/extensions/spec_helper.rb +0 -61
  394. data/spec/extensions/split_array_nil_spec.rb +0 -24
  395. data/spec/extensions/split_values_spec.rb +0 -57
  396. data/spec/extensions/sql_comments_spec.rb +0 -33
  397. data/spec/extensions/sql_expr_spec.rb +0 -59
  398. data/spec/extensions/static_cache_spec.rb +0 -410
  399. data/spec/extensions/string_agg_spec.rb +0 -90
  400. data/spec/extensions/string_date_time_spec.rb +0 -95
  401. data/spec/extensions/string_stripper_spec.rb +0 -68
  402. data/spec/extensions/subclasses_spec.rb +0 -79
  403. data/spec/extensions/subset_conditions_spec.rb +0 -38
  404. data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
  405. data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
  406. data/spec/extensions/synchronize_sql_spec.rb +0 -124
  407. data/spec/extensions/table_select_spec.rb +0 -83
  408. data/spec/extensions/tactical_eager_loading_spec.rb +0 -141
  409. data/spec/extensions/thread_local_timezones_spec.rb +0 -67
  410. data/spec/extensions/timestamps_spec.rb +0 -209
  411. data/spec/extensions/to_dot_spec.rb +0 -153
  412. data/spec/extensions/touch_spec.rb +0 -226
  413. data/spec/extensions/tree_spec.rb +0 -284
  414. data/spec/extensions/typecast_on_load_spec.rb +0 -86
  415. data/spec/extensions/unlimited_update_spec.rb +0 -21
  416. data/spec/extensions/update_or_create_spec.rb +0 -83
  417. data/spec/extensions/update_primary_key_spec.rb +0 -105
  418. data/spec/extensions/update_refresh_spec.rb +0 -59
  419. data/spec/extensions/uuid_spec.rb +0 -101
  420. data/spec/extensions/validate_associated_spec.rb +0 -52
  421. data/spec/extensions/validation_class_methods_spec.rb +0 -1040
  422. data/spec/extensions/validation_contexts_spec.rb +0 -31
  423. data/spec/extensions/validation_helpers_spec.rb +0 -525
  424. data/spec/extensions/whitelist_security_spec.rb +0 -157
  425. data/spec/extensions/xml_serializer_spec.rb +0 -213
  426. data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
  427. data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
  428. data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  429. data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  430. data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
  431. data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
  432. data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
  433. data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
  434. data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
  435. data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
  436. data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
  437. data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
  438. data/spec/files/double_migration/001_create_sessions.rb +0 -9
  439. data/spec/files/double_migration/002_create_nodes.rb +0 -19
  440. data/spec/files/double_migration/003_3_create_users.rb +0 -4
  441. data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
  442. data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
  443. data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  444. data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
  445. data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
  446. data/spec/files/empty_migration/001_create_sessions.rb +0 -9
  447. data/spec/files/empty_migration/002_create_nodes.rb +0 -0
  448. data/spec/files/empty_migration/003_3_create_users.rb +0 -4
  449. data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
  450. data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
  451. data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
  452. data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  453. data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
  454. data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
  455. data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
  456. data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  457. data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
  458. data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
  459. data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
  460. data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
  461. data/spec/files/reversible_migrations/001_reversible.rb +0 -5
  462. data/spec/files/reversible_migrations/002_reversible.rb +0 -5
  463. data/spec/files/reversible_migrations/003_reversible.rb +0 -5
  464. data/spec/files/reversible_migrations/004_reversible.rb +0 -5
  465. data/spec/files/reversible_migrations/005_reversible.rb +0 -10
  466. data/spec/files/reversible_migrations/006_reversible.rb +0 -10
  467. data/spec/files/reversible_migrations/007_reversible.rb +0 -10
  468. data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
  469. data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
  470. data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
  471. data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
  472. data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
  473. data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
  474. data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
  475. data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
  476. data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
  477. data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
  478. data/spec/guards_helper.rb +0 -58
  479. data/spec/integration/associations_test.rb +0 -2513
  480. data/spec/integration/database_test.rb +0 -113
  481. data/spec/integration/dataset_test.rb +0 -1880
  482. data/spec/integration/eager_loader_test.rb +0 -687
  483. data/spec/integration/migrator_test.rb +0 -262
  484. data/spec/integration/model_test.rb +0 -203
  485. data/spec/integration/plugin_test.rb +0 -2302
  486. data/spec/integration/prepared_statement_test.rb +0 -398
  487. data/spec/integration/schema_test.rb +0 -869
  488. data/spec/integration/spec_helper.rb +0 -64
  489. data/spec/integration/timezone_test.rb +0 -86
  490. data/spec/integration/transaction_test.rb +0 -354
  491. data/spec/integration/type_test.rb +0 -127
  492. data/spec/model/association_reflection_spec.rb +0 -803
  493. data/spec/model/associations_spec.rb +0 -4538
  494. data/spec/model/base_spec.rb +0 -817
  495. data/spec/model/class_dataset_methods_spec.rb +0 -146
  496. data/spec/model/dataset_methods_spec.rb +0 -198
  497. data/spec/model/eager_loading_spec.rb +0 -2262
  498. data/spec/model/hooks_spec.rb +0 -370
  499. data/spec/model/inflector_spec.rb +0 -26
  500. data/spec/model/model_spec.rb +0 -953
  501. data/spec/model/plugins_spec.rb +0 -318
  502. data/spec/model/record_spec.rb +0 -2107
  503. data/spec/model/spec_helper.rb +0 -45
  504. data/spec/model/validations_spec.rb +0 -193
  505. data/spec/model_no_assoc_spec.rb +0 -1
  506. data/spec/model_spec.rb +0 -1
  507. data/spec/plugin_spec.rb +0 -1
  508. data/spec/sequel_coverage.rb +0 -15
  509. data/spec/sequel_warning.rb +0 -4
  510. data/spec/spec_config.rb +0 -12
@@ -1,9 +0,0 @@
1
- class CreateAlbums < Sequel::Migration
2
- def up
3
- create_table(:sm2233){Integer :smc23}
4
- end
5
-
6
- def down
7
- drop_table(:sm2233)
8
- end
9
- 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,19 +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
10
-
11
- Class.new(Sequel::Migration) do
12
- def up
13
- create_table(:sm2443){Integer :smc2}
14
- end
15
-
16
- def down
17
- drop_table(:sm2443)
18
- end
19
- 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
- up{create_table(:sm33333){Integer :smc3}}
3
- down{drop_table(:sm33333)}
4
- end
@@ -1,4 +0,0 @@
1
- Sequel.migration do
2
- up{create_table(:sm11111){Integer :smc1}}
3
- down{drop_table(:sm11111)}
4
- 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,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,4 +0,0 @@
1
- Sequel.migration do
2
- up{create_table(:sm3333){Integer :smc3}}
3
- down{drop_table(:sm3333)}
4
- 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,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 CreateArtists < Sequel::Migration
2
- def up
3
- create_table(:sm1122){Integer :smc12}
4
- end
5
-
6
- def down
7
- drop_table(:sm1122)
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,9 +0,0 @@
1
- class CreateAlbums < Sequel::Migration
2
- def up
3
- create_table(:sm2233){Integer :smc23}
4
- end
5
-
6
- def down
7
- drop_table(:sm2233)
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
- up{create_table(:sm11111){Integer :smc1}}
3
- down{drop_table(:sm11111)}
4
- end
@@ -1,4 +0,0 @@
1
- Sequel.migration do
2
- up{create_table(:sm33333){Integer :smc3}}
3
- down{drop_table(:sm33333)}
4
- 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,4 +0,0 @@
1
- Sequel.migration do
2
- up{create_table(:sm3333){Integer :smc3}}
3
- down{drop_table(:sm3333)}
4
- end
@@ -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,10 +0,0 @@
1
- Sequel.migration do
2
- change do
3
- create_table(:c) do
4
- primary_key :id
5
- end
6
- alter_table(:b) do
7
- add_foreign_key :f, :c
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- Sequel.migration do
2
- change do
3
- create_table(:d) do
4
- primary_key :id
5
- end
6
- alter_table(:b) do
7
- add_foreign_key :g, :d, :foreign_key_constraint_name=>:b_f_foo
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,58 +0,0 @@
1
- gem 'minitest'
2
- require 'minitest/autorun'
3
- require 'minitest/hooks/default'
4
- require 'minitest/shared_description'
5
-
6
- require_relative "deprecation_helper"
7
-
8
- def Sequel.guarded?(*checked)
9
- unless ENV['SEQUEL_NO_PENDING']
10
- checked.each do |c|
11
- case c
12
- when DB.database_type
13
- return c
14
- when Array
15
- case c.length
16
- when 1
17
- return c if c.first == DB.adapter_scheme
18
- when 2
19
- if c.first.is_a?(Proc)
20
- return c if c.last == DB.database_type && c.first.call(DB)
21
- elsif c.last.is_a?(Proc)
22
- return c if c.first == DB.adapter_scheme && c.last.call(DB)
23
- else
24
- return c if c.first == DB.adapter_scheme && c.last == DB.database_type
25
- end
26
- when 3
27
- return c if c[0] == DB.adapter_scheme && c[1] == DB.database_type && c[2].call(DB)
28
- end
29
- end
30
- end
31
- end
32
- false
33
- end
34
-
35
- module Minitest::Spec::DSL
36
- def cspecify(message, *checked, &block)
37
- if pending = Sequel.guarded?(*checked)
38
- it(message) do
39
- proc{instance_exec(&block)}.must_raise(Exception) if ENV['SEQUEL_CHECK_PENDING']
40
- skip "Not yet working on #{Array(pending).map{|x| x.is_a?(Proc) ? :proc : x}.join(', ')}"
41
- end
42
- else
43
- it(message, &block)
44
- end
45
- end
46
- end
47
-
48
- class Minitest::HooksSpec
49
- def log
50
- begin
51
- DB.loggers << Logger.new(STDOUT)
52
- yield
53
- ensure
54
- DB.loggers.pop
55
- end
56
- end
57
- end
58
-
@@ -1,2513 +0,0 @@
1
- require_relative "spec_helper"
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_be_nil
18
- a.last.last_album.must_be_nil
19
- a.last.second_album.must_be_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_be_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(Sequel[: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_be_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_be_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_be_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_be_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(Sequel[: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_be_nil
153
- als.last.second_tag.must_be_nil
154
- als.last.last_tag.must_be_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(Sequel[: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_be_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_be_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_be_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(Sequel[: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(Sequel[: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_be_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(Sequel[: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_be_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).select(Sequel.qualify(@Artist.first_source, @Artist.columns.first)).all.must_equal []
397
- @Artist.association_join(:first_album).select(Sequel.qualify(@Artist.first_source, @Artist.columns.first)).all.must_equal []
398
- @Album.association_join(:artist).select(Sequel.qualify(@Album.first_source, @Album.columns.first)).all.must_equal []
399
- @Album.association_join(:tags).select(Sequel.qualify(@Album.first_source, @Album.columns.first)).all.must_equal []
400
- @Album.association_join(:alias_tags).select(Sequel.qualify(@Album.first_source, @Album.columns.first)).all.must_equal []
401
- @Tag.association_join(:albums).select(Sequel.qualify(@Tag.first_source, @Tag.columns.first)).all.must_equal []
402
- unless @no_many_through_many
403
- @Artist.association_join(:tags).select(Sequel.qualify(@Artist.first_source, @Artist.columns.first)).all.must_equal []
404
- @Artist.association_join(:first_tag).select(Sequel.qualify(@Artist.first_source, @Artist.columns.first)).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(Sequel[: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(Sequel[: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(Sequel[:tags][:name]=>tu.name) end
1126
- Album.one_through_one :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[: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(Sequel[:tags][:name]=>tu.name) end
1153
- Album.one_through_one :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[: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(Sequel[:tags][:name]=>tu.name) end
1200
- Artist.one_through_many :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[: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(Sequel[:tags][:name]=>tu.name) end
1229
- Artist.one_through_many :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[: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(Sequel[: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(Sequel[: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(Sequel[:tags][:name]=>tu.name) end
1354
- Album.many_to_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(Sequel[: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(Sequel[:tags][:name]=>tu.name) end
1384
- Album.many_to_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(Sequel[: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(Sequel[:tags][:name]=>tu.name) end
1439
- Artist.many_through_many :second_two_tags, :clone=>:first_tag do |ads| ads.where(Sequel[: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(Sequel[:tags][:name]=>tu.name) end
1471
- Artist.many_through_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(Sequel[: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_be_nil
1499
- @album.artist_dataset.first.must_be_nil
1500
- @artist.first_album.must_be_nil
1501
- @artist.first_album_dataset.first.must_be_nil
1502
- @artist.albums.must_equal []
1503
- @artist.albums_dataset.all.must_equal []
1504
- @album.tags.must_equal []
1505
- @album.tags_dataset.all.must_equal []
1506
- @album.alias_tags.must_equal []
1507
- @album.alias_tags_dataset.all.must_equal []
1508
- @tag.albums.must_equal []
1509
- @tag.albums_dataset.all.must_equal []
1510
- unless @no_many_through_many
1511
- @album.first_tag.must_be_nil
1512
- @album.first_tag_dataset.first.must_be_nil
1513
- end
1514
- end
1515
-
1516
- it "should have set methods work" do
1517
- # many to one
1518
- @album.update(:artist => @artist)
1519
- @album.reload.artist.must_equal @artist
1520
- @album.update(:artist => nil)
1521
- @album.reload.artist.must_be_nil
1522
-
1523
- # one to one
1524
- @artist.update(:first_album => @album)
1525
- @artist.reload.first_album.must_equal @album
1526
- @artist.update(:first_album => nil)
1527
- @artist.reload.first_album.must_be_nil
1528
-
1529
- unless @no_many_through_many
1530
- tag = @pr.call.last
1531
- # one through one
1532
- @album.update(:first_tag => @tag)
1533
- @album.reload.first_tag.must_equal @tag
1534
- @album.update(:first_tag => @tag)
1535
- @album.reload.first_tag.must_equal @tag
1536
- @album.update(:first_tag => tag)
1537
- @album.reload.first_tag.must_equal tag
1538
- @album.update(:first_tag => nil)
1539
- @album.reload.first_tag.must_be_nil
1540
- @album.update(:first_tag => nil)
1541
- @album.reload.first_tag.must_be_nil
1542
-
1543
- # one through one with alias
1544
- @album.update(:alias_t_tag => @tag)
1545
- @album.reload.alias_t_tag.must_equal @tag
1546
- @album.update(:alias_t_tag => nil)
1547
- @album.reload.alias_t_tag.must_be_nil
1548
- end
1549
- end
1550
-
1551
- it "should have add and remove methods work" do
1552
- # one to many
1553
- @artist.add_album(@album)
1554
- @artist.reload.albums.must_equal [@album]
1555
- @artist.remove_album(@album)
1556
- @artist.reload.albums.must_equal []
1557
-
1558
- # many to many
1559
- @album.add_tag(@tag)
1560
- @album.reload.tags.must_equal [@tag]
1561
- @tag.reload.albums.must_equal [@album]
1562
- @album.alias_tags.must_equal [@tag]
1563
- @album.remove_tag(@tag)
1564
- @album.reload.tags.must_equal []
1565
-
1566
- # many to many with alias
1567
- @album.add_alias_tag(@tag)
1568
- @album.reload.alias_tags.must_equal [@tag]
1569
- @album.remove_alias_tag(@tag)
1570
- @album.reload.alias_tags.must_equal []
1571
- end
1572
-
1573
- it "should have remove_all methods work" do
1574
- # one to many
1575
- @artist.add_album(@album)
1576
- @artist.remove_all_albums
1577
- @artist.reload.albums.must_equal []
1578
-
1579
- # many to many
1580
- @album.add_tag(@tag)
1581
- @album.remove_all_tags
1582
- @album.reload.tags.must_equal []
1583
-
1584
- # many to many with alias
1585
- @album.add_alias_tag(@tag)
1586
- @album.remove_all_alias_tags
1587
- @album.reload.alias_tags.must_equal []
1588
- end
1589
-
1590
- it "should have working dataset associations" do
1591
- album, artist, tag = @pr.call
1592
-
1593
- Tag.albums.all.must_equal []
1594
- Album.artists.all.must_equal []
1595
- Album.tags.all.must_equal []
1596
- Album.alias_tags.all.must_equal []
1597
- Artist.albums.all.must_equal []
1598
- unless @no_many_through_many
1599
- Album.first_tags.all.must_equal []
1600
- Artist.tags.all.must_equal []
1601
- Artist.first_tags.all.must_equal []
1602
- Tag.tags.all.must_equal []
1603
- end
1604
- Artist.albums.tags.all.must_equal []
1605
-
1606
- @album.update(:artist => @artist)
1607
- @album.add_tag(@tag)
1608
-
1609
- Tag.albums.all.must_equal [@album]
1610
- Album.artists.all.must_equal [@artist]
1611
- Album.tags.all.must_equal [@tag]
1612
- Album.alias_tags.all.must_equal [@tag]
1613
- Artist.albums.all.must_equal [@album]
1614
- unless @no_many_through_many
1615
- Album.mthm_tags.all.must_equal [@tag]
1616
- Album.first_tags.all.must_equal [@tag]
1617
- Artist.tags.all.must_equal [@tag]
1618
- Artist.first_tags.all.must_equal [@tag]
1619
- Tag.tags.all.must_equal [@tag]
1620
- end
1621
- Artist.albums.tags.all.must_equal [@tag]
1622
-
1623
- album.add_tag(tag)
1624
- album.update(:artist => artist)
1625
-
1626
- Tag.albums.order(:name).all.must_equal [@album, album]
1627
- Album.artists.order(:name).all.must_equal [@artist, artist]
1628
- Album.tags.order(:name).all.must_equal [@tag, tag]
1629
- Album.alias_tags.order(:name).all.must_equal [@tag, tag]
1630
- Artist.albums.order(:name).all.must_equal [@album, album]
1631
- unless @no_many_through_many
1632
- Album.first_tags.order(:name).all.must_equal [@tag, tag]
1633
- Artist.tags.order(:name).all.must_equal [@tag, tag]
1634
- Artist.first_tags.order(:name).all.must_equal [@tag, tag]
1635
- Tag.tags.order(:name).all.must_equal [@tag, tag]
1636
- end
1637
- Artist.albums.tags.order(:name).all.must_equal [@tag, tag]
1638
-
1639
- Tag.filter(Tag.qualified_primary_key_hash(tag.pk)).albums.all.must_equal [album]
1640
- Album.filter(Album.qualified_primary_key_hash(album.pk)).artists.all.must_equal [artist]
1641
- Album.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.must_equal [tag]
1642
- Album.filter(Album.qualified_primary_key_hash(album.pk)).alias_tags.all.must_equal [tag]
1643
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.all.must_equal [album]
1644
- unless @no_many_through_many
1645
- Album.filter(Album.qualified_primary_key_hash(album.pk)).first_tags.all.must_equal [tag]
1646
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).tags.all.must_equal [tag]
1647
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).first_tags.all.must_equal [tag]
1648
- Tag.filter(Tag.qualified_primary_key_hash(tag.pk)).tags.all.must_equal [tag]
1649
- end
1650
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.tags.all.must_equal [tag]
1651
-
1652
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.must_equal [tag]
1653
- Artist.filter(Artist.qualified_primary_key_hash(@artist.pk)).albums.filter(Album.qualified_primary_key_hash(@album.pk)).tags.all.must_equal [@tag]
1654
- Artist.filter(Artist.qualified_primary_key_hash(@artist.pk)).albums.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.must_equal []
1655
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.filter(Album.qualified_primary_key_hash(@album.pk)).tags.all.must_equal []
1656
- end
1657
-
1658
- it "should eager load via eager correctly" do
1659
- @album.update(:artist => @artist)
1660
- @album.add_tag(@tag)
1661
-
1662
- a = Artist.eager(:albums=>[:tags, :alias_tags]).eager(:first_album).all
1663
- a.must_equal [@artist]
1664
- a.first.albums.must_equal [@album]
1665
- a.first.first_album.must_equal @album
1666
- a.first.albums.first.tags.must_equal [@tag]
1667
- a.first.albums.first.alias_tags.must_equal [@tag]
1668
-
1669
- a = Tag.eager(:albums=>:artist).all
1670
- a.must_equal [@tag]
1671
- a.first.albums.must_equal [@album]
1672
- a.first.albums.first.artist.must_equal @artist
1673
- end
1674
-
1675
- it "should eager load via eager_graph correctly" do
1676
- @album.update(:artist => @artist)
1677
- @album.add_tag(@tag)
1678
-
1679
- a = Artist.eager_graph(:albums=>[:tags, :alias_tags]).eager_graph(:first_album).all
1680
- a.must_equal [@artist]
1681
- a.first.albums.must_equal [@album]
1682
- a.first.first_album.must_equal @album
1683
- a.first.albums.first.tags.must_equal [@tag]
1684
- a.first.albums.first.alias_tags.must_equal [@tag]
1685
-
1686
- a = Tag.eager_graph(:albums=>:artist).all
1687
- a.must_equal [@tag]
1688
- a.first.albums.must_equal [@album]
1689
- a.first.albums.first.artist.must_equal @artist
1690
- end
1691
- end
1692
-
1693
- RegularAndCompositeKeyAssociations = shared_description do
1694
- describe "when filtering/excluding by associations when joining" do
1695
- def self_join(c)
1696
- c.join(Sequel.as(c.table_name, :b), Array(c.primary_key).zip(Array(c.primary_key))).select_all(c.table_name)
1697
- end
1698
-
1699
- before do
1700
- @Artist = self_join(Artist)
1701
- @Album = self_join(Album)
1702
- @Tag = self_join(Tag)
1703
- end
1704
-
1705
- include FilterByAssociations
1706
- end
1707
-
1708
- describe "with default/union :eager_limit_strategy" do
1709
- before do
1710
- @els = {}
1711
- end
1712
- include EagerLimitStrategies
1713
- end
1714
-
1715
- describe "with :eager_limit_strategy=>:ruby" do
1716
- before do
1717
- @els = {:eager_limit_strategy=>:ruby}
1718
- end
1719
- include EagerLimitStrategies
1720
- include EagerGraphLimitStrategies
1721
- end
1722
-
1723
- describe "with :eager_limit_strategy=>:distinct_on" do
1724
- before do
1725
- @els = {:eager_limit_strategy=>:distinct_on}
1726
- end
1727
-
1728
- include OneToOneEagerLimitStrategies
1729
- include OneThroughOneEagerLimitStrategies
1730
- include OneThroughManyEagerLimitStrategies
1731
- include OneToOneEagerGraphLimitStrategies
1732
- include OneThroughOneEagerGraphLimitStrategies
1733
- include OneThroughManyEagerGraphLimitStrategies
1734
- include FilterByAssociationsSingularLimitStrategies
1735
- end if DB.dataset.supports_ordered_distinct_on?
1736
-
1737
- describe "with :eager_limit_strategy=>:window_function" do
1738
- before do
1739
- @els = {:eager_limit_strategy=>:window_function}
1740
- end
1741
- include EagerLimitStrategies
1742
- include EagerGraphLimitStrategies
1743
- include FilterByAssociationsLimitStrategies
1744
- end if DB.dataset.supports_window_functions?
1745
-
1746
- it "should work with a many_through_many association" do
1747
- @album.update(:artist => @artist)
1748
- @album.add_tag(@tag)
1749
-
1750
- @album.reload
1751
- @artist.reload
1752
- @tag.reload
1753
-
1754
- @album.tags.must_equal [@tag]
1755
-
1756
- a = Artist.eager(:tags).all
1757
- a.must_equal [@artist]
1758
- a.first.tags.must_equal [@tag]
1759
-
1760
- a = Artist.eager_graph(:tags).all
1761
- a.must_equal [@artist]
1762
- a.first.tags.must_equal [@tag]
1763
-
1764
- a = Album.eager(:artist=>:tags).all
1765
- a.must_equal [@album]
1766
- a.first.artist.must_equal @artist
1767
- a.first.artist.tags.must_equal [@tag]
1768
-
1769
- a = Album.eager_graph(:artist=>:tags).all
1770
- a.must_equal [@album]
1771
- a.first.artist.must_equal @artist
1772
- a.first.artist.tags.must_equal [@tag]
1773
- end
1774
-
1775
- it "should work with a one_through_many association" do
1776
- @album.update(:artist => @artist)
1777
- @album.add_tag(@tag)
1778
-
1779
- @album.reload
1780
- @artist.reload
1781
- @tag.reload
1782
-
1783
- @album.tags.must_equal [@tag]
1784
-
1785
- a = Artist.eager(:first_tag).all
1786
- a.must_equal [@artist]
1787
- a.first.first_tag.must_equal @tag
1788
-
1789
- a = Artist.eager_graph(:first_tag).all
1790
- a.must_equal [@artist]
1791
- a.first.first_tag.must_equal @tag
1792
-
1793
- a = Album.eager(: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
-
1798
- a = Album.eager_graph(:artist=>:first_tag).all
1799
- a.must_equal [@album]
1800
- a.first.artist.must_equal @artist
1801
- a.first.artist.first_tag.must_equal @tag
1802
- end
1803
- end
1804
-
1805
- describe "Sequel::Model Simple Associations" do
1806
- before(:all) do
1807
- @db = DB
1808
- @db.drop_table?(:albums_tags, :tags, :albums, :artists)
1809
- @db.create_table(:artists) do
1810
- primary_key :id
1811
- String :name
1812
- end
1813
- @db.create_table(:albums) do
1814
- primary_key :id
1815
- String :name
1816
- foreign_key :artist_id, :artists
1817
- end
1818
- @db.create_table(:tags) do
1819
- primary_key :id
1820
- String :name
1821
- end
1822
- @db.create_table(:albums_tags) do
1823
- foreign_key :album_id, :albums
1824
- foreign_key :tag_id, :tags
1825
- end
1826
- end
1827
- before do
1828
- [:albums_tags, :tags, :albums, :artists].each{|t| @db[t].delete}
1829
- class ::Artist < Sequel::Model(@db)
1830
- plugin :dataset_associations
1831
- one_to_many :albums, :order=>:name
1832
- one_to_one :first_album, :clone=>:albums
1833
- one_to_one :second_album, :clone=>:albums, :limit=>[nil, 1]
1834
- one_to_one :last_album, :class=>:Album, :order=>Sequel.desc(:name)
1835
- one_to_many :first_two_albums, :clone=>:albums, :limit=>2
1836
- one_to_many :second_two_albums, :clone=>:albums, :limit=>[2, 1]
1837
- one_to_many :not_first_albums, :clone=>:albums, :limit=>[nil, 1]
1838
- one_to_many :last_two_albums, :class=>:Album, :order=>Sequel.desc(:name), :limit=>2
1839
- one_to_many :a_albums, :clone=>:albums, :conditions=>{:name=>'Al'}
1840
- one_to_one :first_a_album, :clone=>:a_albums
1841
- plugin :many_through_many
1842
- many_through_many :tags, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]]
1843
- many_through_many :first_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>2, :graph_order=>:name
1844
- many_through_many :second_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[2, 1], :graph_order=>:name
1845
- many_through_many :not_first_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[nil, 1], :graph_order=>:name
1846
- many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(Sequel[:tags][:name]), :limit=>2, :graph_order=>Sequel.desc(:name)
1847
- many_through_many :t_tags, :clone=>:tags, :conditions=>{Sequel[:tags][:name]=>'T'}
1848
- one_through_many :first_tag, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :order=>Sequel[:tags][:name], :graph_order=>:name, :class=>:Tag
1849
- one_through_many :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
1850
- one_through_many :last_tag, :clone=>:first_tag, :order=>Sequel.desc(Sequel[:tags][:name]), :graph_order=>Sequel.desc(:name)
1851
- one_through_many :t_tag, :clone=>:first_tag, :conditions=>{Sequel[:tags][:name]=>'T'}
1852
- end
1853
- class ::Album < Sequel::Model(@db)
1854
- plugin :dataset_associations
1855
- many_to_one :artist, :reciprocal=>nil
1856
- many_to_one :a_artist, :clone=>:artist, :conditions=>{:name=>'Ar'}, :key=>:artist_id
1857
- many_to_many :tags, :right_key=>:tag_id
1858
- plugin :many_through_many
1859
- many_through_many :mthm_tags, [[:albums_tags, :album_id, :tag_id]], :class=>:Tag
1860
- many_to_many :alias_tags, :clone=>:tags, :join_table=>Sequel[:albums_tags].as(:at)
1861
- many_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
1862
- many_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
1863
- many_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
1864
- many_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
1865
- many_to_many :t_tags, :clone=>:tags, :conditions=>{:name=>'T'}
1866
- many_to_many :alias_t_tags, :clone=>:t_tags, :join_table=>Sequel[:albums_tags].as(:at)
1867
- one_through_one :first_tag, :clone=>:tags, :order=>:name
1868
- one_through_one :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
1869
- one_through_one :last_tag, :clone=>:tags, :order=>Sequel.desc(:name)
1870
- one_through_one :t_tag, :clone=>:t_tags
1871
- one_through_one :alias_t_tag, :clone=>:alias_t_tags
1872
- end
1873
- class ::Tag < Sequel::Model(@db)
1874
- plugin :dataset_associations
1875
- many_to_many :albums
1876
- plugin :many_through_many
1877
- many_through_many :tags, [[:albums_tags, :tag_id, :album_id], [:albums, :id, :artist_id], [:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :class=>:Tag
1878
- end
1879
- @album = Album.create(:name=>'Al')
1880
- @artist = Artist.create(:name=>'Ar')
1881
- @tag = Tag.create(:name=>'T')
1882
- @same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
1883
- @diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
1884
- @middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
1885
- @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}
1886
- @pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
1887
- @ins = lambda{@db[:albums_tags].insert(:tag_id=>@tag.id)}
1888
- end
1889
- after do
1890
- [:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
1891
- end
1892
- after(:all) do
1893
- @db.drop_table?(:albums_tags, :tags, :albums, :artists)
1894
- end
1895
-
1896
- include BasicRegularAndCompositeKeyAssociations
1897
- include RegularAndCompositeKeyAssociations
1898
-
1899
- describe "with :correlated_subquery limit strategy" do
1900
- before do
1901
- @els = {:eager_limit_strategy=>:correlated_subquery}
1902
- end
1903
-
1904
- include OneToOneEagerGraphLimitStrategies
1905
- include OneToManyEagerGraphLimitStrategies
1906
- include FilterByAssociationsOneToOneLimitStrategies
1907
- include FilterByAssociationsOneToManyLimitStrategies
1908
- end if DB.dataset.supports_limits_in_correlated_subqueries?
1909
-
1910
- it "should handle eager loading limited associations for many objects" do
1911
- @db[:artists].import([:name], (1..99).map{|i| [i.to_s]})
1912
- artists = Artist.eager(:albums).all
1913
- artists.length.must_equal 100
1914
- artists.each{|a| a.albums.must_equal []}
1915
- artists = Artist.eager(:first_two_albums).all
1916
- artists.length.must_equal 100
1917
- artists.each{|a| a.first_two_albums.must_equal []}
1918
- @db[:albums].insert([:artist_id], @db[:artists].select(:id))
1919
- artists = Artist.eager(:albums).all
1920
- artists.length.must_equal 100
1921
- artists.each{|a| a.albums.length.must_equal 1}
1922
- artists = Artist.eager(:first_two_albums).all
1923
- artists.length.must_equal 100
1924
- artists.each{|a| a.first_two_albums.length.must_equal 1}
1925
- end
1926
-
1927
- it "should handle the :eager_limit option in eager-loading callbacks" do
1928
- @db[:artists].import([:name], (1..4).map{|i| ['test']})
1929
- artist_ids = @db[:artists].where(:name => 'test').select_map([:id])
1930
- @db[:albums].import([:artist_id], artist_ids * 3)
1931
- ads = Artist.where(:id => artist_ids)
1932
-
1933
- artists = ads.eager(:albums => proc{|ds| ds.clone(:eager_limit => 1)}).all
1934
- artists.length.must_equal 4
1935
- artists.each{|a| a.albums.length.must_equal 1}
1936
-
1937
- artists = ads.eager(:albums => proc{|ds| ds.clone(:eager_limit => 2)}).all
1938
- artists.length.must_equal 4
1939
- artists.each{|a| a.albums.length.must_equal 2}
1940
-
1941
- artists = ads.eager(:albums => proc{|ds| ds.clone(:eager_limit => 3)}).all
1942
- artists.length.must_equal 4
1943
- artists.each{|a| a.albums.length.must_equal 3}
1944
-
1945
- artists = ads.eager(:albums => proc{|ds| ds.clone(:eager_limit => 4)}).all
1946
- artists.length.must_equal 4
1947
- artists.each{|a| a.albums.length.must_equal 3}
1948
- end
1949
-
1950
- it "should handle many_to_one associations with same name as :key" do
1951
- Album.def_column_alias(:artist_id_id, :artist_id)
1952
- Album.many_to_one :artist_id, :key_column =>:artist_id, :class=>Artist
1953
- @album.update(:artist_id_id => @artist.id)
1954
- @album.artist_id.must_equal @artist
1955
-
1956
- as = Album.eager(:artist_id).all
1957
- as.must_equal [@album]
1958
- as.map{|a| a.artist_id}.must_equal [@artist]
1959
-
1960
- as = Album.eager_graph(:artist_id).all
1961
- as.must_equal [@album]
1962
- as.map{|a| a.artist_id}.must_equal [@artist]
1963
- end
1964
-
1965
- it "should handle aliased tables when eager_graphing" do
1966
- @album.update(:artist => @artist)
1967
- @album.add_tag(@tag)
1968
-
1969
- Artist.set_dataset(Sequel[:artists].as(:ar))
1970
- Album.set_dataset(Sequel[:albums].as(:a))
1971
- Tag.set_dataset(Sequel[:tags].as(:t))
1972
- Artist.one_to_many :balbums, :class=>Album, :key=>:artist_id, :reciprocal=>nil
1973
- Album.many_to_many :btags, :class=>Tag, :join_table=>:albums_tags, :right_key=>:tag_id
1974
- Album.many_to_one :bartist, :class=>Artist, :key=>:artist_id
1975
- Tag.many_to_many :balbums, :class=>Album, :join_table=>:albums_tags, :right_key=>:album_id
1976
-
1977
- a = Artist.eager_graph(:balbums=>:btags).all
1978
- a.must_equal [@artist]
1979
- a.first.balbums.must_equal [@album]
1980
- a.first.balbums.first.btags.must_equal [@tag]
1981
-
1982
- a = Tag.eager_graph(:balbums=>:bartist).all
1983
- a.must_equal [@tag]
1984
- a.first.balbums.must_equal [@album]
1985
- a.first.balbums.first.bartist.must_equal @artist
1986
- end
1987
-
1988
- it "should have add method accept hashes and create new records" do
1989
- @artist.remove_all_albums
1990
- Album.dataset.delete
1991
- @album = @artist.add_album(:name=>'Al2')
1992
- Album.first[:name].must_equal 'Al2'
1993
- @artist.albums_dataset.first[:name].must_equal 'Al2'
1994
-
1995
- @album.remove_all_tags
1996
- Tag.dataset.delete
1997
- @album.add_tag(:name=>'T2')
1998
- Tag.first[:name].must_equal 'T2'
1999
- @album.tags_dataset.first[:name].must_equal 'T2'
2000
- end
2001
-
2002
- it "should have add method accept primary key and add related records" do
2003
- @artist.remove_all_albums
2004
- @artist.add_album(@album.id)
2005
- @artist.albums_dataset.first[:id].must_equal @album.id
2006
-
2007
- @album.remove_all_tags
2008
- @album.add_tag(@tag.id)
2009
- @album.tags_dataset.first[:id].must_equal @tag.id
2010
- end
2011
-
2012
- it "should have remove method accept primary key and remove related album" do
2013
- @artist.add_album(@album)
2014
- @artist.reload.remove_album(@album.id)
2015
- @artist.reload.albums.must_equal []
2016
-
2017
- @album.add_tag(@tag)
2018
- @album.reload.remove_tag(@tag.id)
2019
- @tag.reload.albums.must_equal []
2020
- end
2021
-
2022
- it "should handle dynamic callbacks for regular loading" do
2023
- @artist.add_album(@album)
2024
-
2025
- @artist.albums.must_equal [@album]
2026
- @artist.albums{|ds| ds.exclude(:id=>@album.id)}.must_equal []
2027
- @artist.albums{|ds| ds.filter(:id=>@album.id)}.must_equal [@album]
2028
-
2029
- @album.artist.must_equal @artist
2030
- @album.artist{|ds| ds.exclude(:id=>@artist.id)}.must_be_nil
2031
- @album.artist{|ds| ds.filter(:id=>@artist.id)}.must_equal @artist
2032
-
2033
- @artist.albums{|ds| ds.exclude(:id=>@album.id)}.must_equal []
2034
- @artist.albums{|ds| ds.filter(:id=>@album.id)}.must_equal [@album]
2035
- @album.artist{|ds| ds.exclude(:id=>@artist.id)}.must_be_nil
2036
- @album.artist{|ds| ds.filter(:id=>@artist.id)}.must_equal @artist
2037
- end
2038
-
2039
- it "should handle dynamic callbacks for eager loading via eager and eager_graph" do
2040
- @artist.add_album(@album)
2041
- @album.add_tag(@tag)
2042
- album2 = @artist.add_album(:name=>'Foo')
2043
- tag2 = album2.add_tag(:name=>'T2')
2044
-
2045
- artist = Artist.eager(:albums=>:tags).all.first
2046
- artist.albums.must_equal [@album, album2]
2047
- artist.albums.map{|x| x.tags}.must_equal [[@tag], [tag2]]
2048
-
2049
- artist = Artist.eager_graph(:albums=>:tags).all.first
2050
- artist.albums.must_equal [@album, album2]
2051
- artist.albums.map{|x| x.tags}.must_equal [[@tag], [tag2]]
2052
-
2053
- artist = Artist.eager(:albums=>{proc{|ds| ds.where(:id=>album2.id)}=>:tags}).all.first
2054
- artist.albums.must_equal [album2]
2055
- artist.albums.first.tags.must_equal [tag2]
2056
-
2057
- artist = Artist.eager_graph(:albums=>{proc{|ds| ds.where(:id=>album2.id)}=>:tags}).all.first
2058
- artist.albums.must_equal [album2]
2059
- artist.albums.first.tags.must_equal [tag2]
2060
- end
2061
-
2062
- it "should have remove method raise an error for one_to_many records if the object isn't already associated" do
2063
- proc{@artist.remove_album(@album.id)}.must_raise(Sequel::Error)
2064
- proc{@artist.remove_album(@album)}.must_raise(Sequel::Error)
2065
- end
2066
-
2067
- it "should handle dataset associations with :dataset_associations_join options" do
2068
- Album.many_to_many :tags, :right_key=>:tag_id, :select=>[Sequel.expr(:tags).*, Sequel[:albums_tags][:tag_id].as(:atid)], :dataset_associations_join=>true
2069
- Artist.many_through_many :tags, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :select=>[Sequel.expr(:tags).*, Sequel[:albums_tags][:tag_id].as(:atid), Sequel[:albums][:artist_id].as(:aid)], :dataset_associations_join=>true
2070
-
2071
- Album.tags.order(Sequel[:tags][:name]).first.must_be_nil
2072
- Artist.tags.order(Sequel[:tags][:name]).first.must_be_nil
2073
-
2074
- @album.add_tag(@tag)
2075
- @artist.add_album(@album)
2076
-
2077
- Album.tags.order(Sequel[:tags][:name]).first.must_equal Tag.load(:id=>@tag.id, :name=>"T", :atid=>@tag.id)
2078
- Artist.tags.order(Sequel[:tags][:name]).first.must_equal Tag.load(:id=>@tag.id, :name=>"T", :atid=>@tag.id, :aid=>@artist.id)
2079
- end
2080
- end
2081
-
2082
- describe "Sequel::Model Composite Key Associations" do
2083
- before(:all) do
2084
- @db = DB
2085
- @db.drop_table?(:albums_tags, :tags, :albums, :artists)
2086
- @db.create_table(:artists) do
2087
- Integer :id1
2088
- Integer :id2
2089
- String :name
2090
- primary_key [:id1, :id2]
2091
- end
2092
- @db.create_table(:albums) do
2093
- Integer :id1
2094
- Integer :id2
2095
- String :name
2096
- Integer :artist_id1
2097
- Integer :artist_id2
2098
- foreign_key [:artist_id1, :artist_id2], :artists
2099
- primary_key [:id1, :id2]
2100
- end
2101
- @db.create_table(:tags) do
2102
- Integer :id1
2103
- Integer :id2
2104
- String :name
2105
- primary_key [:id1, :id2]
2106
- end
2107
- @db.create_table(:albums_tags) do
2108
- Integer :album_id1
2109
- Integer :album_id2
2110
- Integer :tag_id1
2111
- Integer :tag_id2
2112
- foreign_key [:album_id1, :album_id2], :albums
2113
- foreign_key [:tag_id1, :tag_id2], :tags
2114
- end
2115
- end
2116
- before do
2117
- [:albums_tags, :tags, :albums, :artists].each{|t| @db[t].delete}
2118
- class ::Artist < Sequel::Model(@db)
2119
- plugin :dataset_associations
2120
- set_primary_key [:id1, :id2]
2121
- unrestrict_primary_key
2122
- one_to_many :albums, :key=>[:artist_id1, :artist_id2], :order=>:name
2123
- one_to_one :first_album, :clone=>:albums
2124
- one_to_one :last_album, :clone=>:albums, :order=>Sequel.desc(:name)
2125
- one_to_one :second_album, :clone=>:albums, :limit=>[nil, 1]
2126
- one_to_many :first_two_albums, :clone=>:albums, :order=>:name, :limit=>2
2127
- one_to_many :second_two_albums, :clone=>:albums, :order=>:name, :limit=>[2, 1]
2128
- one_to_many :not_first_albums, :clone=>:albums, :order=>:name, :limit=>[nil, 1]
2129
- one_to_many :last_two_albums, :clone=>:albums, :order=>Sequel.desc(:name), :limit=>2
2130
- one_to_many :a_albums, :clone=>:albums do |ds| ds.where(:name=>'Al') end
2131
- one_to_one :first_a_album, :clone=>:a_albums
2132
- plugin :many_through_many
2133
- many_through_many :tags, [[:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]]
2134
- many_through_many :first_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>2, :graph_order=>:name
2135
- many_through_many :second_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[2, 1], :graph_order=>:name
2136
- many_through_many :not_first_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[nil, 1], :graph_order=>:name
2137
- many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(Sequel[:tags][:name]), :limit=>2, :graph_order=>Sequel.desc(:name)
2138
- many_through_many :t_tags, :clone=>:tags do |ds| ds.where(Sequel[:tags][:name]=>'T') end
2139
- one_through_many :first_tag, [[:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :order=>Sequel[:tags][:name], :graph_order=>:name, :class=>:Tag
2140
- one_through_many :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
2141
- one_through_many :last_tag, :clone=>:first_tag, :order=>Sequel.desc(Sequel[:tags][:name]), :graph_order=>Sequel.desc(:name)
2142
- one_through_many :t_tag, :clone=>:first_tag do |ds| ds.where(Sequel[:tags][:name]=>'T') end
2143
- end
2144
- class ::Album < Sequel::Model(@db)
2145
- plugin :dataset_associations
2146
- set_primary_key [:id1, :id2]
2147
- unrestrict_primary_key
2148
- many_to_one :artist, :key=>[:artist_id1, :artist_id2], :reciprocal=>nil
2149
- many_to_one(:a_artist, :clone=>:artist){|ds| ds.where(:name=>'Ar')}
2150
- many_to_many :tags, :left_key=>[:album_id1, :album_id2], :right_key=>[:tag_id1, :tag_id2]
2151
- plugin :many_through_many
2152
- many_through_many :mthm_tags, [[:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :class=>:Tag
2153
- many_to_many :alias_tags, :clone=>:tags, :join_table=>Sequel[:albums_tags].as(:at)
2154
- many_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
2155
- many_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
2156
- many_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
2157
- many_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
2158
- many_to_many :t_tags, :clone=>:tags do |ds| ds.where(:name=>'T') end
2159
- many_to_many :alias_t_tags, :clone=>:t_tags, :join_table=>Sequel[:albums_tags].as(:at)
2160
- one_through_one :first_tag, :clone=>:tags, :order=>:name
2161
- one_through_one :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
2162
- one_through_one :last_tag, :clone=>:tags, :order=>Sequel.desc(:name)
2163
- one_through_one :t_tag, :clone=>:t_tags
2164
- one_through_one :alias_t_tag, :clone=>:alias_t_tags
2165
- end
2166
- class ::Tag < Sequel::Model(@db)
2167
- plugin :dataset_associations
2168
- set_primary_key [:id1, :id2]
2169
- unrestrict_primary_key
2170
- many_to_many :albums, :right_key=>[:album_id1, :album_id2], :left_key=>[:tag_id1, :tag_id2]
2171
- plugin :many_through_many
2172
- many_through_many :tags, [[:albums_tags, [:tag_id1, :tag_id2], [:album_id1, :album_id2]], [:albums, [:id1, :id2], [:artist_id1, :artist_id2]], [:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :class=>:Tag
2173
- end
2174
- @album = Album.create(:name=>'Al', :id1=>1, :id2=>2)
2175
- @artist = Artist.create(:name=>'Ar', :id1=>3, :id2=>4)
2176
- @tag = Tag.create(:name=>'T', :id1=>5, :id2=>6)
2177
- @same_album = lambda{Album.create(:name=>'Al', :id1=>7, :id2=>8, :artist_id1=>3, :artist_id2=>4)}
2178
- @diff_album = lambda{Album.create(:name=>'lA', :id1=>9, :id2=>10, :artist_id1=>3, :artist_id2=>4)}
2179
- @middle_album = lambda{Album.create(:name=>'Bl', :id1=>13, :id2=>14, :artist_id1=>3, :artist_id2=>4)}
2180
- @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}
2181
- @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)]}
2182
- @ins = lambda{@db[:albums_tags].insert(:tag_id1=>@tag.id1, :tag_id2=>@tag.id2)}
2183
- end
2184
- after do
2185
- [:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
2186
- end
2187
- after(:all) do
2188
- @db.drop_table?(:albums_tags, :tags, :albums, :artists)
2189
- end
2190
-
2191
- include BasicRegularAndCompositeKeyAssociations
2192
- include RegularAndCompositeKeyAssociations
2193
-
2194
- describe "with :correlated_subquery limit strategy" do
2195
- before do
2196
- @els = {:eager_limit_strategy=>:correlated_subquery}
2197
- end
2198
-
2199
- include OneToOneEagerGraphLimitStrategies
2200
- include OneToManyEagerGraphLimitStrategies
2201
- include FilterByAssociationsOneToOneLimitStrategies
2202
- include FilterByAssociationsOneToManyLimitStrategies
2203
- end if DB.dataset.supports_limits_in_correlated_subqueries? && DB.dataset.supports_multiple_column_in?
2204
-
2205
- it "should have add method accept hashes and create new records" do
2206
- @artist.remove_all_albums
2207
- Album.dataset.delete
2208
- @artist.add_album(:id1=>1, :id2=>2, :name=>'Al2')
2209
- Album.first[:name].must_equal 'Al2'
2210
- @artist.albums_dataset.first[:name].must_equal 'Al2'
2211
-
2212
- @album.remove_all_tags
2213
- Tag.dataset.delete
2214
- @album.add_tag(:id1=>1, :id2=>2, :name=>'T2')
2215
- Tag.first[:name].must_equal 'T2'
2216
- @album.tags_dataset.first[:name].must_equal 'T2'
2217
- end
2218
-
2219
- it "should have add method accept primary key and add related records" do
2220
- @artist.remove_all_albums
2221
- @artist.add_album([@album.id1, @album.id2])
2222
- @artist.albums_dataset.first.pk.must_equal [@album.id1, @album.id2]
2223
-
2224
- @album.remove_all_tags
2225
- @album.add_tag([@tag.id1, @tag.id2])
2226
- @album.tags_dataset.first.pk.must_equal [@tag.id1, @tag.id2]
2227
- end
2228
-
2229
- it "should have remove method accept primary key and remove related album" do
2230
- @artist.add_album(@album)
2231
- @artist.reload.remove_album([@album.id1, @album.id2])
2232
- @artist.reload.albums.must_equal []
2233
-
2234
- @album.add_tag(@tag)
2235
- @album.reload.remove_tag([@tag.id1, @tag.id2])
2236
- @tag.reload.albums.must_equal []
2237
- end
2238
-
2239
- it "should have remove method raise an error for one_to_many records if the object isn't already associated" do
2240
- proc{@artist.remove_album([@album.id1, @album.id2])}.must_raise(Sequel::Error)
2241
- proc{@artist.remove_album(@album)}.must_raise(Sequel::Error)
2242
- end
2243
-
2244
- it "should not have association method or dataset method return rows with NULL keys" do
2245
- Album.one_to_many :other_albums, :class=>Album, :key=>[:artist_id1, :artist_id2], :primary_key=>[:artist_id1, :artist_id2]
2246
- @album.update(:artist_id1=>1)
2247
- @album.other_albums.must_equal []
2248
- @album.other_albums_dataset.all.must_equal []
2249
- end
2250
- end
2251
-
2252
- describe "Sequel::Model pg_array_to_many" do
2253
- before(:all) do
2254
- db = @db = DB
2255
- @db.extension :pg_array unless @db.frozen?
2256
- Sequel.extension :pg_array_ops
2257
- @db.drop_table?(:tags, :albums, :artists)
2258
- @db.create_table(:artists) do
2259
- primary_key :id
2260
- String :name
2261
- end
2262
- @db.create_table(:albums) do
2263
- primary_key :id
2264
- String :name
2265
- foreign_key :artist_id, :artists
2266
- column :tag_ids, "#{db.send(:type_literal, :type=>Integer)}[]"
2267
- end
2268
- @db.create_table(:tags) do
2269
- primary_key :id
2270
- String :name
2271
- end
2272
- end
2273
- before do
2274
- [:tags, :albums, :artists].each{|t| @db[t].delete}
2275
- class ::Artist < Sequel::Model(@db)
2276
- plugin :dataset_associations
2277
- one_to_many :albums, :order=>:name
2278
- one_to_one :first_album, :clone=>:albums
2279
- one_to_many :a_albums, :clone=>:albums do |ds| ds.where(:name=>'Al') end
2280
- one_to_one :first_a_album, :clone=>:a_albums
2281
- end
2282
- class ::Album < Sequel::Model(@db)
2283
- plugin :dataset_associations
2284
- plugin :pg_array_associations
2285
- many_to_one :artist, :reciprocal=>nil
2286
- many_to_one :a_artist, :clone=>:artist, :key=>:artist_id do |ds| ds.where(:name=>'Ar') end
2287
- pg_array_to_many :tags, :key=>:tag_ids, :save_after_modify=>true
2288
- pg_array_to_many :alias_tags, :clone=>:tags
2289
- pg_array_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
2290
- pg_array_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
2291
- pg_array_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
2292
- pg_array_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
2293
- pg_array_to_many :t_tags, :clone=>:tags do |ds| ds.where(Sequel[:tags][:name]=>'T') end
2294
- pg_array_to_many :alias_t_tags, :clone=>:t_tags
2295
- end
2296
- class ::Tag < Sequel::Model(@db)
2297
- plugin :dataset_associations
2298
- plugin :pg_array_associations
2299
- many_to_pg_array :albums
2300
- end
2301
- @album = Album.create(:name=>'Al')
2302
- @artist = Artist.create(:name=>'Ar')
2303
- @tag = Tag.create(:name=>'T')
2304
- @many_to_many_method = :pg_array_to_many
2305
- @no_many_through_many = true
2306
- @same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
2307
- @diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
2308
- @middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
2309
- @other_tags = lambda{t = [Tag.create(:name=>'U'), Tag.create(:name=>'V')]; Tag.all{|x| @album.add_tag(x)}; t}
2310
- @pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
2311
- @ins = lambda{}
2312
- end
2313
- after do
2314
- [:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
2315
- end
2316
- after(:all) do
2317
- @db.drop_table?(:tags, :albums, :artists)
2318
- end
2319
-
2320
- include BasicRegularAndCompositeKeyAssociations
2321
- include ManyToManyEagerLimitStrategies
2322
- include ManyToManyEagerGraphLimitStrategies
2323
-
2324
- it "should handle adding and removing entries in array" do
2325
- a = Album.create
2326
- a.typecast_on_assignment = false
2327
- a.add_tag(@tag)
2328
- a.remove_tag(@tag)
2329
- a.save
2330
- end
2331
- end if DB.database_type == :postgres && [:postgres, :jdbc].include?(DB.adapter_scheme) && DB.server_version >= 90300
2332
-
2333
- describe "Sequel::Model many_to_pg_array" do
2334
- before(:all) do
2335
- db = @db = DB
2336
- @db.extension :pg_array unless @db.frozen?
2337
- Sequel.extension :pg_array_ops
2338
- @db.drop_table?(:tags, :albums, :artists)
2339
- @db.create_table(:artists) do
2340
- primary_key :id
2341
- String :name
2342
- end
2343
- @db.create_table(:albums) do
2344
- primary_key :id
2345
- String :name
2346
- foreign_key :artist_id, :artists
2347
- end
2348
- @db.create_table(:tags) do
2349
- primary_key :id
2350
- String :name
2351
- column :album_ids, "#{db.send(:type_literal, :type=>Integer)}[]"
2352
- end
2353
- end
2354
- before do
2355
- [:tags, :albums, :artists].each{|t| @db[t].delete}
2356
- class ::Artist < Sequel::Model(@db)
2357
- plugin :dataset_associations
2358
- one_to_many :albums, :order=>:name
2359
- one_to_one :first_album, :class=>:Album, :order=>:name
2360
- one_to_many :a_albums, :clone=>:albums do |ds| ds.where(:name=>'Al') end
2361
- one_to_one :first_a_album, :clone=>:a_albums
2362
- end
2363
- class ::Album < Sequel::Model(@db)
2364
- plugin :dataset_associations
2365
- plugin :pg_array_associations
2366
- many_to_one :artist, :reciprocal=>nil
2367
- many_to_one :a_artist, :clone=>:artist, :key=>:artist_id do |ds| ds.where(:name=>'Ar') end
2368
- many_to_pg_array :tags
2369
- many_to_pg_array :alias_tags, :clone=>:tags
2370
- many_to_pg_array :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
2371
- many_to_pg_array :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
2372
- many_to_pg_array :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
2373
- many_to_pg_array :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
2374
- many_to_pg_array :t_tags, :clone=>:tags do |ds| ds.where(Sequel[:tags][:name]=>'T') end
2375
- many_to_pg_array :alias_t_tags, :clone=>:t_tags
2376
- end
2377
- class ::Tag < Sequel::Model(@db)
2378
- plugin :dataset_associations
2379
- plugin :pg_array_associations
2380
- pg_array_to_many :albums, :save_after_modify=>true
2381
- end
2382
- @album = Album.create(:name=>'Al')
2383
- @artist = Artist.create(:name=>'Ar')
2384
- @tag = Tag.create(:name=>'T')
2385
- @many_to_many_method = :pg_array_to_many
2386
- @no_many_through_many = true
2387
- @same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
2388
- @diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
2389
- @middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
2390
- @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}
2391
- @pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
2392
- @ins = lambda{}
2393
- end
2394
- after do
2395
- [:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
2396
- end
2397
- after(:all) do
2398
- @db.drop_table?(:tags, :albums, :artists)
2399
- end
2400
-
2401
- include BasicRegularAndCompositeKeyAssociations
2402
- include ManyToManyEagerLimitStrategies
2403
- include ManyToManyEagerGraphLimitStrategies
2404
-
2405
- it "should handle adding and removing entries in array" do
2406
- a = Album.create
2407
- @tag.typecast_on_assignment = false
2408
- a.add_tag(@tag)
2409
- a.remove_tag(@tag)
2410
- end
2411
- end if DB.database_type == :postgres && [:postgres, :jdbc].include?(DB.adapter_scheme) && DB.server_version >= 90300
2412
-
2413
- describe "Sequel::Model Associations with clashing column names" do
2414
- before(:all) do
2415
- @db = DB
2416
- @db.drop_table?(:bars_foos, :bars, :foos)
2417
- @db.create_table(:foos) do
2418
- primary_key :id
2419
- Integer :object_id
2420
- end
2421
- @db.create_table(:bars) do
2422
- primary_key :id
2423
- Integer :object_id
2424
- end
2425
- @db.create_table(:bars_foos) do
2426
- Integer :foo_id
2427
- Integer :object_id
2428
- primary_key [:foo_id, :object_id]
2429
- end
2430
- end
2431
- before do
2432
- [:bars_foos, :bars, :foos].each{|t| @db[t].delete}
2433
- @Foo = Class.new(Sequel::Model(:foos))
2434
- @Bar = Class.new(Sequel::Model(:bars))
2435
- @Foo.def_column_alias(:obj_id, :object_id)
2436
- @Bar.def_column_alias(:obj_id, :object_id)
2437
- @Foo.one_to_many :bars, :primary_key=>:obj_id, :primary_key_column=>:object_id, :key=>:object_id, :key_method=>:obj_id, :class=>@Bar
2438
- @Foo.one_to_one :bar, :primary_key=>:obj_id, :primary_key_column=>:object_id, :key=>:object_id, :key_method=>:obj_id, :class=>@Bar
2439
- @Bar.many_to_one :foo, :key=>:obj_id, :key_column=>:object_id, :primary_key=>:object_id, :primary_key_method=>:obj_id, :class=>@Foo
2440
- @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
2441
- @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
2442
- @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
2443
- @foo = @Foo.create(:obj_id=>2)
2444
- @bar = @Bar.create(:obj_id=>2)
2445
- @Foo.db[:bars_foos].insert(2, 2)
2446
- end
2447
- after(:all) do
2448
- @db.drop_table?(:bars_foos, :bars, :foos)
2449
- end
2450
-
2451
- it "should have working regular association methods" do
2452
- @Bar.first.foo.must_equal @foo
2453
- @Foo.first.bars.must_equal [@bar]
2454
- @Foo.first.bar.must_equal @bar
2455
- @Foo.first.mtmbars.must_equal [@bar]
2456
- @Foo.first.mtmbar.must_equal @bar
2457
- @Bar.first.mtmfoos.must_equal [@foo]
2458
- end
2459
-
2460
- it "should have working eager loading methods" do
2461
- @Bar.eager(:foo).all.map{|o| [o, o.foo]}.must_equal [[@bar, @foo]]
2462
- @Foo.eager(:bars).all.map{|o| [o, o.bars]}.must_equal [[@foo, [@bar]]]
2463
- @Foo.eager(:bar).all.map{|o| [o, o.bar]}.must_equal [[@foo, @bar]]
2464
- @Foo.eager(:mtmbars).all.map{|o| [o, o.mtmbars]}.must_equal [[@foo, [@bar]]]
2465
- @Foo.eager(:mtmbar).all.map{|o| [o, o.mtmbar]}.must_equal [[@foo, @bar]]
2466
- @Bar.eager(:mtmfoos).all.map{|o| [o, o.mtmfoos]}.must_equal [[@bar, [@foo]]]
2467
- end
2468
-
2469
- it "should have working eager graphing methods" do
2470
- @Bar.eager_graph(:foo).all.map{|o| [o, o.foo]}.must_equal [[@bar, @foo]]
2471
- @Foo.eager_graph(:bars).all.map{|o| [o, o.bars]}.must_equal [[@foo, [@bar]]]
2472
- @Foo.eager_graph(:bar).all.map{|o| [o, o.bar]}.must_equal [[@foo, @bar]]
2473
- @Foo.eager_graph(:mtmbars).all.map{|o| [o, o.mtmbars]}.must_equal [[@foo, [@bar]]]
2474
- @Foo.eager_graph(:mtmbar).all.map{|o| [o, o.mtmbar]}.must_equal [[@foo, @bar]]
2475
- @Bar.eager_graph(:mtmfoos).all.map{|o| [o, o.mtmfoos]}.must_equal [[@bar, [@foo]]]
2476
- end
2477
-
2478
- it "should have working modification methods" do
2479
- b = @Bar.create(:obj_id=>3)
2480
- f = @Foo.create(:obj_id=>3)
2481
-
2482
- @bar.foo = f
2483
- @bar.obj_id.must_equal 3
2484
- @foo.bar = @bar
2485
- @bar.obj_id.must_equal 2
2486
-
2487
- @foo.add_bar(b)
2488
- @foo.bars.sort_by{|x| x.id}.must_equal [@bar, b]
2489
- @foo.remove_bar(b)
2490
- @foo.bars.must_equal [@bar]
2491
- @foo.remove_all_bars
2492
- @foo.bars.must_equal []
2493
-
2494
- @bar.refresh.update(:obj_id=>2)
2495
- b.refresh.update(:obj_id=>3)
2496
- @foo.mtmbars.must_equal [@bar]
2497
- @foo.remove_all_mtmbars
2498
- @foo.mtmbars.must_equal []
2499
- @foo.add_mtmbar(b)
2500
- @foo.mtmbars.must_equal [b]
2501
- @foo.remove_mtmbar(b)
2502
- @foo.mtmbars.must_equal []
2503
-
2504
- @bar.add_mtmfoo(f)
2505
- @bar.mtmfoos.must_equal [f]
2506
- @bar.remove_all_mtmfoos
2507
- @bar.mtmfoos.must_equal []
2508
- @bar.add_mtmfoo(f)
2509
- @bar.mtmfoos.must_equal [f]
2510
- @bar.remove_mtmfoo(f)
2511
- @bar.mtmfoos.must_equal []
2512
- end
2513
- end