aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
Commit message (Collapse)AuthorAgeFilesLines
* Don't skip tests if they are not broken. Just don't define theyRafael Mendonça França2014-02-161-2/+2
|
* make a singleton for AssociationScopeAaron Patterson2014-02-141-2/+1
| | | | | AssociationScope no longer maintains state, so we're safe to keep a singleton and save on GC time
* pass the association and connection to the scope methodAaron Patterson2014-02-141-2/+4
|
* context in validation goes through has many relationshipKevin Casey2014-02-081-0/+10
|
* fix HABTM w/out primary key errors on destructionKevin Casey2014-02-021-0/+10
|
* Associations now raise `ArgumentError` on name conflicts.Lauro Caetano2014-01-313-0/+30
| | | | | Dangerous association names conflicts include instance or class methods already defined by `ActiveRecord::Base`.
* Fix indent on test case [ci skip]Carlos Antonio da Silva2014-01-281-2/+2
|
* Ensure AR #second, #third, etc. finders work through associationsJason Meller2014-01-211-61/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes two regressions introduced in cafe31a078 where newly created finder methods #second, #third, #forth, and #fifth caused a NoMethodError error on reload associations and where we were pulling the wrong element out of cached associations. Examples: some_book.authors.reload.second # Before # => NoMethodError: undefined method 'first' for nil:NilClass # After # => #<Author id: 2, name: "Sally Second", ...> some_book.first.authors.first some_book.first.authors.second # Before # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 1, name: "Freddy First", ...> # After # => #<Author id: 1, name: "Freddy First", ...> # => #<Author id: 2, name: "Sally Second", ...> Fixes #13783.
* `has_one` and `belongs_to` accessors don't add ORDER BY to the queries anymore.Rafael Mendonça França2014-01-212-0/+14
| | | | | | | | | | Since Rails 4.0, we add an ORDER BY in the `first` method to ensure consistent results among different database engines. But for singular associations this behavior is not needed since we will have one record to return. As this ORDER BY option can lead some performance issues we are removing it for singular associations accessors. Fixes #12623.
* Extract a method to simplify setup codeCarlos Antonio da Silva2014-01-161-23/+27
|
* Use minitest's skip rather than conditionals + early returnsCarlos Antonio da Silva2014-01-161-47/+38
|
* Move AR test classes inside the test caseCarlos Antonio da Silva2014-01-161-38/+46
|
* Remove method redefined warnings for test suiteMatthias Zirnstein2014-01-051-1/+1
| | | | | | | | | | | | | | | | | has_many definitions with "name" as singular and as plural e.g. has_many :welcome_posts_with_comment has_many :welcome_posts_with_comments Ruby mentions it with: lib/active_record/associations/builder/collection_association.rb:65: warning: method redefined; discarding old welcome_posts_with_comment_ids lib/active_record/associations/builder/collection_association.rb:65: warning: previous definition of welcome_posts_with_comment_ids was here lib/active_record/associations/builder/collection_association.rb:75: warning: method redefined; discarding old welcome_posts_with_comment_ids= lib/active_record/associations/builder/collection_association.rb:75: warning: previous definition of welcome_posts_with_comment_ids= was here
* Merge pull request #10134 from ↵Rafael Mendonça França2014-01-031-1/+5
|\ | | | | | | | | derikson/collection_proxy_select_with_multiple_args Change CollectionProxy#select to take the same arguments as ActiveRecord::select
| * Changed ActiveRecord::Associations::CollectionProxy#select to take multiple ↵Dan Erikson2013-04-081-1/+5
| | | | | | | | | | | | arguments. This makes the arguments the same as ActiveRecord::QueryMethods::select.
* | Improve the tests to not call assert_nothing_raisedRafael Mendonça França2014-01-011-4/+1
| |
* | https://github.com/rails/rails/commit/2075f39d726cef361170218fd16421fc52bed5 ↵Vipul A M2013-12-311-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | a8 introduced a regression in includes/preloades by calling `read_attribute` on an association when preloading takes places, instead of using loaded records in `association.target`. tl;dr Records are not made properly available via `read_attribute` when preloding in simultaneous, but value of `@loaded` is already set true, and records concatenated in `association.target` on an association object. When `@loaded` is true we return an object of `AlreadyLoaded` in preload_for. In `AlreadyLoaded` to return preloaded records we make wrong use of `read_attribute`, instead of `target` records. The regression is fixed by making use of the loaded records in `association.target` when the preloading takes place. Fixes #13437
* | On destroying do not touch destroyed belongs to association.Paul Nikitochkin2013-12-231-0/+8
| | | | | | | | Fixes: #13445
* | Prefer assert_raise instead of flunk + rescue to test for exceptionsCarlos Antonio da Silva2013-12-191-5/+3
| | | | | | | | | | | | Change most tests to make use of assert_raise returning the raised exception rather than relying on a combination of flunk + rescue to check for exception types/messages.
* | Add a failing test for assigning nil to a polymorphic belongs_to not ↵Jeremy Kemper2013-12-171-0/+13
| | | | | | | | nullifying its _type column
* | make sure cached table name is a string. fixes #12582Aaron Patterson2013-12-121-0/+7
| |
* | Revert the whole refactoring in the association builder classes.Rafael Mendonça França2013-12-111-1/+2
| | | | | | | | This is to get activerecord-deprecated_finders work again
* | Raise `ArgumentError` when `has_one` is used with `counter_cache`Godfrey Chan2013-11-292-0/+16
| | | | | | | | | | | | | | | | | | Previously, the `has_one` macro incorrectly accepts the `counter_cache` option due to a bug, although that options was never supported nor functional on `has_one` and `has_one ... through` relationships. It now correctly raises an `ArgumentError` when passed that option. For reference, this bug was introduced in 52f8e4b9.
* | updating options documentation for associationsKuldeep Aggarwal2013-11-291-8/+3
| | | | | | | | removed unnecessary test case and improved test case for belongs_to having invalid options
* | changed update counter to act on unscoped modelheruku2013-11-261-0/+8
| |
* | Raise `RecordNotDestroyed` when children can't be replacedBrian Thomas Storti2013-11-251-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #12812 Raise `ActiveRecord::RecordNotDestroyed` when a child marked with `dependent: destroy` can't be destroyed. The following code: ```ruby class Post < ActiveRecord::Base has_many :comments, dependent: :destroy end class Comment < ActiveRecord::Base before_destroy do return false end end post = Post.create!(comments: [Comment.create!]) post.comments = [Comment.create!] ```` would result in a `post` with two `comments`. With this commit, the same code would raise a `RecordNotDestroyed` exception, keeping the `post` with the same `comment`.
* | Fix some minor typos [ci skip]Vipul A M2013-11-261-1/+1
| |
* | Fix ActiveRecord::Relation#unscopeJon Leighton2013-11-201-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm pretty confused about the addition of this method. The documentation says that it was intended to allow the removal of values from the default scope (in contrast to #except). However it behaves exactly the same as except: https://gist.github.com/jonleighton/7537008 (other than having a slightly enhanced syntax). The removal of the default scope is allowed by 94924dc32baf78f13e289172534c2e71c9c8cade, which was not a change we could make until 4.1 due to the need to deprecate things. However after that change #unscope still gives us nothing that #except doesn't already give us. However there *is* a desire to be able to unscope stuff in a way that persists across merges, which would allow associations to be defined which unscope stuff from the default scope of the associated model. E.g. has_many :comments, -> { unscope where: :trashed } So that's what this change implements. I've also corrected the documentation. I removed the guide references to #except as I think unscope really supercedes #except now. While we're here, there's also a potential desire to be able to write this: has_many :comments, -> { unscoped } However, it doesn't make sense and would not be straightforward to implement. While with #unscope we're specifying exactly what we want to be removed from the relation, with "unscoped" we're just saying that we want it to not have some things which were added earlier on by the default scope. However in the case of an association, we surely don't want *all* conditions to be removed, otherwise the above would just become "SELECT * FROM comments" with no foreign key constraint. To make the above work, we'd have to somehow tag the relation values which get added when evaluating the default scope in order to differentiate them from other relation values. Which is way too much complexity and therefore not worth it when most use cases can be satisfied with unscope. Closes #10643, #11061.
* | Merge pull request #12918 from versioncontrol/rails-12866Rafael Mendonça França2013-11-161-0/+4
|\ \ | | | | | | | | | | | | | | | | | | Checks to see if the record contains the foreign_key to set the inverse automatically Conflicts: activerecord/CHANGELOG.md
| * | Checks to see if the record contains the foreign_key to set the inverse ↵Edo Balvers2013-11-161-0/+4
| | | | | | | | | | | | automatically
* | | Fix test name [ci skip]Carlos Antonio da Silva2013-11-141-1/+1
| | |
* | | Fix that eager loading of polymorphic associations did not work with ↵David Heinemeier Hansson2013-11-142-3/+1
| | | | | | | | | | | | association empty?/any? predicates any more (there is still a problem when select is applied to a relation, or if you try association#exists? -- but its easier to work around)
* | | Prevent the counter cache from being decremented twicedm1try2013-11-111-0/+9
| | | | | | | | | | | | | | | when destroying a record on a has_many :through association. :destroy method has own counter_cache callbacks.
* | | Fixes problem with replacing has_one association record with itselfDenis Redozubov2013-11-111-2/+16
| | |
* | | Mark broken test as pendingRafael Mendonça França2013-11-081-0/+2
|/ / | | | | | | This will avoid the broken window effect in our test suite
* | Fix wrong behavior where associations with dependent: :destroy optionsRafael Mendonça França2013-11-011-4/+3
| | | | | | | | | | | | | | | | | | was using nullify strategy This caused a regression in applications trying to upgrade. Also if the user set the dependent option as destroy he expects to get the records removed from the database.
* | Test with the right associationRafael Mendonça França2013-11-011-3/+3
| |
* | :cut: whitespaceAaron Patterson2013-10-301-2/+2
| |
* | Fix broken delete_all test, which will now be failing since #delete_all is ↵David Heinemeier Hansson2013-10-281-4/+4
| | | | | | | | broken
* | Add failing test for preloading with a polymorphic association and using the ↵David Heinemeier Hansson2013-10-281-1/+10
| | | | | | | | existential predicate
* | Assert the return value in the testRafael Mendonça França2013-10-271-1/+1
| |
* | Skip `include_values` from through associations chains for building target scopePaul Nikitochkin2013-10-271-0/+4
| | | | | | | | Fixes: #12242, #9517, #10240
* | Merge pull request #12621 from ↵Rafael Mendonça França2013-10-241-0/+11
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | laurocaetano/fix_has_one_association_with_primary_key_set Save association when primary key is manually set Conflicts: activerecord/CHANGELOG.md
| * | Save association when primary key is manually setlaurocaetano2013-10-241-0/+11
| | |
* | | Merge branch 'master' into joindepAaron Patterson2013-10-151-0/+12
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (44 commits) grammar fix (reverted in e9a1ecd) Revert "fixed a doc bug in the CHANGELOG.md s/does no longer depend on/no longer depends on/" Add missed require making `enable_warnings` available Prepare generated Gemfile for Capistrano 3 Added --model-name option scaffold_controller_generator. read the association instead of sending we should have unique sponsorable ids in the fixtures at least simplify populating the ordering hash the preloader for the RHS has all the preloaded records, so ask it only calculate offset index once. #12537 Remove size alias for length validation Fix `singleton_class?` Minor Refactoring to `NumberHelper#number_to_human` `$SAFE = 4;` has been removed with Ruby 2.1 scope_chain should not be mutated for other reflections Remove `default_primary_key_type` and extract contains of `native_database_types` to a constant since they aren't conditional now in SQLite3Adapter. Makes it more like other adapters. cleanup changelog entry format. [ci skip] Extract a function to determine if the default value is a function Push default_function to superclass to avoid method check Dump the default function when the primary key is uuid ... Conflicts: activerecord/lib/active_record/relation/finder_methods.rb
| * | inversed instance should not be reloaded after stale state was changedDmitry Polushkin2013-10-131-0/+12
| | | | | | | | | check at association reader that record is inverted and should not be reloaded because of stale was changed at target record
* | | this method does not exist anymoreAaron Patterson2013-10-141-8/+0
|/ /
* | Merge branch 'builder-instances'Rafael Mendonça França2013-10-091-2/+1
|\ \
| * | Define the association extensions without need to have a builderRafael Mendonça França2013-10-091-2/+1
| | | | | | | | | | | | instance
* | | Using flat_map instead of map and flattenArun Agrawal2013-10-091-1/+1
|/ / | | | | | | | | | | original commit 8998441967a8cfc6e4302c29664ab9d0acd77704 Reverted here ec8ef1e1055c4e1598da13f49d30261f07f4a9b4