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