aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
Commit message (Collapse)AuthorAgeFilesLines
* Fix issue with collection associations and first(n)/last(n)Carlos Antonio da Silva2012-11-011-0/+13
| | | | | | | | | | | | | | | | | | | | | | | When calling first(n) or last(n) in a collection, Active Record was improperly trying to set the inverse of instance in case that option existed. This change was introduced by fdf4eae506fa9895e831f569bed3c4aa6a999a22. In such cases we don't need to do that "manually", since the way collection will be loaded will already handle that, so we just skip setting the inverse association when any argument is given to first(n)/last(n). The test included ensures that these scenarios will have the inverse of instance set properly. Fixes #8087, Closes #8094. Squashed cherry-pick from d37d40b and c368b66. Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/collection_association.rb
* Merge pull request #7887 from senny/remove_unused_requires_in_ar_testsVijay Dev2012-10-101-1/+0
|\ | | | | remove duplicated require statements in AR test cases
| * remove duplicated require statements in AR test casesYves Senn2012-10-091-1/+0
| |
* | Fix has_many assocation w/select load after createErnie Miller2012-10-051-0/+8
|/ | | | | | | | | | | | | | If you create a new record via a collection association proxy that has not loaded its target, and which selects additional attributes through the association, then when the proxy loads its target, it will inadvertently trigger an ActiveModel::MissingAttributeError during attribute writing when CollectionAssociation#merge_target_lists attempts to do its thing, since the newly loaded records will possess attributes the created record does not. This error also raises a bogus/confusing deprecation warning when accessing the association in Rails 3.2.x, so cherry-pick would be appreciated!
* Revert "Use flat_map { } instead of map {}.flatten"Santiago Pastorino2012-10-052-2/+2
| | | | | | | | | | | This reverts commit abf8de85519141496a6773310964ec03f6106f3f. We should take a deeper look to those cases flat_map doesn't do deep flattening. irb(main):002:0> [[[1,3], [1,2]]].map{|i| i}.flatten => [1, 3, 1, 2] irb(main):003:0> [[[1,3], [1,2]]].flat_map{|i| i} => [[1, 3], [1, 2]]
* Use flat_map { } instead of map {}.flattenSantiago Pastorino2012-10-052-2/+2
|
* Count returns 0 without querying if parent is not savedFrancesco Rodriguez2012-10-033-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | Patches `CollectionAssociation#count` to return 0 without querying if the parent record is new. Consider the following code: class Account has_many :dossiers end class Dossier belongs_to :account end a = Account.new a.dossiers.build # before patch a.dossiers.count # SELECT COUNT(*) FROM "dossiers" WHERE "dossiers"."account_id" IS NULL # => 0 # after a.dosiers.count # fires without sql query # => 0 Fixes #1856.
* Fix destructive side effects from marshaling an association caused by ↵Jeremy Kemper2012-09-251-2/+5
| | | | 65843e1acc0c8d285ff79f8c9c49d4d1215440be
* Merge pull request #7251 from rails/integrate-strong_parametersDavid Heinemeier Hansson2012-09-183-82/+0
|\ | | | | Integrate strong_parameters in Rails 4
| * Remove mass_assignment_options from ActiveRecordGuillermo Iguaran2012-09-162-29/+0
| |
| * Remove mass assignment security from ActiveRecordGuillermo Iguaran2012-09-163-53/+0
| |
* | Merge pull request #7661 from ernie/build-join-records-on-unsaved-hmtRafael Mendonça França2012-09-171-0/+5
|\ \ | | | | | | Fix collection= on hm:t join models when unsaved
| * | Fix collection= on hm:t join models when unsavedErnie Miller2012-09-171-0/+5
| | | | | | | | | | | | | | | | | | If assigning to a has_many :through collection against an unsaved object using the collection=[<array_of_items>] syntax, the join models were not properly created, previously.
* | | Fix warning: method redefine. Testcase name are duplicated.kennyj2012-09-171-1/+1
| |/ |/|
* | Don't preserve SELECT columns on COUNTSteve Klabnik2012-09-161-1/+31
|/ | | | | | | | | | | | | | | | | | The COUNT clause of a finder_sql relationship is being rewritten from COUNT(*) to COUNT(table_name.*). This does not appear to be valid syntax in MySQL: ``` mysql> SELECT COUNT( table_name.* ) FROM `table_name`; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* ) FROM `table_name`' at line 1 ``` This fixes the bug, as well as adding tests so we don't re-introduce it in the future. Fixes #3956.
* Merge pull request #4976 from kreynolds/fix_eager_without_pkeyJon Leighton2012-09-071-0/+8
|\ | | | | Fix eagerly loading associations without primary keys
| * Change JoinPart test from an integration to a unit testKelley Reynolds2012-07-052-13/+8
| |
| * Fix eagerly loading associations without primary keysKelley Reynolds2012-02-091-0/+13
| |
* | Add a test to make sure preloading properly merges association and default ↵Pratik Naik2012-08-281-0/+12
| | | | | | | | scope conditions
* | Use inversed parent for first and last child of has_many associationbrainopia2012-08-181-0/+6
| |
* | Use method compilation for association methodsJon Leighton2012-08-102-3/+3
| | | | | | | | | | | | | | | | | | Method compilation provides better performance and I think the code comes out cleaner as well. A knock on effect is that methods that get redefined produce warnings. I think this is a good thing. I had to deal with a bunch of warnings coming from our tests, though.
* | Remove the dependent_restrict_raises option.Jon Leighton2012-08-102-67/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's not really a good idea to have this as a global config option. We should allow people to specify the behaviour per association. There will now be two new values: * :dependent => :restrict_with_exception implements the current behaviour of :restrict. :restrict itself is deprecated in favour of :restrict_with_exception. * :dependent => :restrict_with_error implements the new behaviour - it adds an error to the owner if there are dependent records present See #4727 for the original discussion of this.
* | Fix #7191. Remove unnecessary transaction when assigning has_one associations.kennyj2012-08-081-0/+13
| |
* | removes usage of Object#in? from the code base (the method remains defined ↵Xavier Noria2012-08-061-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | by Active Support) Selecting which key extensions to include in active_support/rails made apparent the systematic usage of Object#in? in the code base. After some discussion in https://github.com/rails/rails/commit/5ea6b0df9a36d033f21b52049426257a4637028d we decided to remove it and use plain Ruby, which seems enough for this particular idiom. In this commit the refactor has been made case by case. Sometimes include? is the natural alternative, others a simple || is the way you actually spell the condition in your head, others a case statement seems more appropriate. I have chosen the one I liked the most in each case.
* | Remove ActiveRecord::Base.to_aJon Leighton2012-08-032-3/+3
| | | | | | | | | | On reflection, it seems like a bit of a weird method to have on ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
* | load active_support/core_ext/object/inclusion in active_support/railsXavier Noria2012-08-021-1/+0
| |
* | s/scoped/scope/Jon Leighton2012-08-011-1/+1
| |
* | Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-08-012-18/+49
| |
* | Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."Jon Leighton2012-08-012-0/+171
| | | | | | | | | | | | | | | | | | This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370. Conflicts: activerecord/CHANGELOG.md It will be deprecated only in 4.0, and removed properly in 4.1.
* | AR::Relation#order: make new order prepend old oneBogdan Gusiev2012-07-312-4/+4
| | | | | | | | | | | | | | User.order("name asc").order("created_at desc") # SELECT * FROM users ORDER BY created_at desc, name asc This also affects order defined in `default_scope` or any kind of associations.
* | Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-2713-247/+247
| | | | | | | | | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* | ActiveRecord::Base.all returns a Relation.Jon Leighton2012-07-2711-152/+152
| | | | | | | | | | | | | | | | | | | | | | Previously it returned an Array. If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This is more explicit. In most cases this should not break existing code, since Relations use method_missing to delegate unknown methods to #to_a anyway.
* | Deprecate update_column in favor of update_columns.Rafael Mendonça França2012-07-246-16/+16
| | | | | | | | Closes #1190
* | rm unnecessary testJon Leighton2012-07-201-7/+0
| | | | | | | | | | interpolation is no longer a thing separate from "normal" assoc conditions.
* | rm redundant testJon Leighton2012-07-201-7/+0
| | | | | | | | now everything is converted to the new style, this is not needed
* | Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-07-202-171/+0
| |
* | Fix class_eval without __FILE__ and __LINE__.kennyj2012-07-181-2/+2
| |
* | fix association :extend optionJon Leighton2012-07-131-1/+1
| |
* | Represent association scope options as AR::Relations insternally.Jon Leighton2012-07-131-0/+15
| |
* | fix assertion arguments orderJon Leighton2012-07-131-2/+2
| |
* | Allow associations to take a lambda which builds the scopeJon Leighton2012-07-132-1/+8
| |
* | Remove ActiveRelation#inspectBrian Cardarella2012-06-291-1/+1
| |
* | Improve the derivation of HABTM assocation join table namesAndrew White2012-06-221-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improve the derivation of HABTM join table name to take account of nesting. It now takes the table names of the two models, sorts them lexically and then joins them, stripping any common prefix from the second table name. Some examples: Top level models (Category <=> Product) Old: categories_products New: categories_products Top level models with a global table_name_prefix (Category <=> Product) Old: site_categories_products New: site_categories_products Nested models in a module without a table_name_prefix method (Admin::Category <=> Admin::Product) Old: categories_products New: categories_products Nested models in a module with a table_name_prefix method (Admin::Category <=> Admin::Product) Old: categories_products New: admin_categories_products Nested models in a parent model (Catalog::Category <=> Catalog::Product) Old: categories_products New: catalog_categories_products Nested models in different parent models (Catalog::Category <=> Content::Page) Old: categories_pages New: catalog_categories_content_pages Also as part of this commit the validity checks for HABTM assocations have been moved to ActiveRecord::Reflection One side effect of this is to move when the exceptions are raised from the point of declaration to when the association is built. This is consistant with other association validity checks.
* | No need to cache table metadata in advance now that #6683 was merged.Rafael Mendonça França2012-06-112-16/+0
| |
* | Merge pull request #6492 from pmahoney/fair-connection-pool2Rafael Mendonça França2012-06-112-0/+7
|\ \ | | | | | | | | | | | | | | | | | | Fair connection pool2 Conflicts: activerecord/test/cases/associations/eager_test.rb
| * | Make connection pool fair with respect to waiting threads.Patrick Mahoney2012-05-251-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The core of this fix is a threadsafe, fair Queue class. It is very similar to Queue in stdlib except that it supports waiting with a timeout. The issue this solves is that if several threads are contending for database connections, an unfair queue makes is possible that a thread will timeout even while other threads successfully acquire and release connections. A fair queue means the thread that has been waiting the longest will get the next available connection. This includes a few test fixes to avoid test ordering issues that cropped up during development of this patch.
| * | Cache metadata in advance to avoid extra sql statements while testing.Yasuo Honda2012-05-251-0/+7
| | | | | | | | | | | | | | | Reason: If metadata is not cached extra sql statements will be executed, which causes failures tests with assert_queries().
* | | Fix fragile #assert_queries implementation and usages.Steve Jorgensen2012-06-092-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | Several tests that passed when run in the order they are loaded by rake test were failing when run in different sequences due to problems with the implementation of assert_queries and assert_no_queries as well as incorrect assumptions made about how many queries might be executed by a database adapter in various cases.
* | | Add tests to delete by fixnum or string id with has many through associationsFrancesco Rodriguez2012-05-281-0/+20
| | |
* | | Fix failing build related to change in CollectionAssociation#deleteCarlos Antonio da Silva2012-05-291-1/+1
| | | | | | | | | | | | Merge commit 6f1d9d00ffd9d411b2bd488da4eb92b7e2fd972e