aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/collection_proxy.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Updated documentation of CollectionProxy#clear [ci skip]Prathamesh Sonpatki2015-03-061-0/+3
| | | | | | | | - CollectionProxy#clear method calls delete_all so the SQL is directly run into the database. - So the updated_at column of the object on which its run is not updated. - Closes #17161
* Preserve Array#take(n) behaviour of HasManyAssociationAkira Matsuda2015-02-281-2/+2
|
* Merge branch 'rm-take' into 4-1-stableRafael Mendonça França2015-02-201-0/+4
|
* Remove support to activerecord-deprecated_findersRafael Mendonça França2015-01-021-4/+2
|
* Ensure `first!` and friends work on loaded associationsSean Griffin2014-12-291-0/+1
| | | | Fixes #18237
* Inject the `PredicateBuilder` into the `Relation` instanceSean Griffin2014-12-261-1/+1
| | | | | | | Construction of relations can be a hotspot, we don't want to create one of these in the constructor. This also allows us to do more expensive things in the predicate builder's constructor, since it's created once per AR::Base subclass
* [ci skip] Clarify deletion strategies for collection proxieseileencodes2014-10-041-17/+14
| | | | | | | | | | | For detailed testing of behavior see: https://gist.github.com/eileencodes/5b0a2fe011dcff6203fe This shows destroy_all always destroys records and fires callbacks. It will never use nullify or delete_all delete_all's behavior varies greatly based on `hm` vs `hm:t` and deletion strategy.
* [ci skip] Updated documentation syntax of other parameter for rdocTom Kadwill2014-08-271-1/+1
|
* Merge pull request #16705 from tomkadwill/documented_many_block_paramZachary Scott2014-08-261-1/+1
|\ | | | | [ci skip] Updated documentation syntax of block parameter for rdoc
| * [ci skip] Updated documentation syntax of block parameter for rdoc Tom Kadwill2014-08-261-1/+1
| |
* | [ci skip] Updated include to reference record parameter for rdocTom Kadwill2014-08-261-1/+1
|/
* [ci skip] Updated documentation syntax of block parameter for rdocTom Kadwill2014-08-261-1/+1
|
* fix CollectionProxy delete_all documentationeileencodes2014-04-061-6/+1
| | | | | | | This method no longer returns an array of all records that have been removed. Correct documentation to reflect this change. See issue 14546
* CollectionProxy uses the arel of its association's scope.Jefferson Lai2014-04-021-0/+4
| | | | | | CollectionProxy should be able to reuse the behavior (methods) of its parent class, but with its own state. This change allows CollectionProxy to use the arel object corresponding to its association's scope.
* Make CollectionProxy#reset return selfRafael Mendonça França2014-01-221-1/+2
|
* Calling reset on a collection association should unload the assocationKelsey Schlarman2014-01-211-0/+21
| | | | Need to define #reset on CollectionProxy.
* Ensure AR #second, #third, etc. finders work through associationsJason Meller2014-01-211-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* add missing information for `id` field when used with `select` [ci skip]Kuldeep Aggarwal2014-01-221-1/+1
|
* Change all "can not"s to the correct "cannot".T.J. Schuck2014-01-031-1/+1
|
* Merge pull request #10134 from ↵Rafael Mendonça França2014-01-031-3/+3
|\ | | | | | | | | 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-3/+3
| | | | | | | | | | | | arguments. This makes the arguments the same as ActiveRecord::QueryMethods::select.
* | Mark the arguments needed by activerecord-deprecated_finders with a TODORafael Mendonça França2013-12-111-0/+2
| |
* | Revert "Merge pull request #12518 from vipulnsward/remove_count_options"Rafael Mendonça França2013-12-111-2/+2
| | | | | | | | | | | | | | It is needed for activerecord-depecated_finders This reverts commit dcff027a5242b20c0c90eb062dddb22ccf51aed9, reversing changes made to 3a2093984ff49d86db1efeff0c7581e788ecfb9f.
* | Change syntax format for example returned valuesPrem Sichanugrist2013-11-111-4/+4
| | | | | | | | | | | | | | | | | | According to our guideline, we leave 1 space between `#` and `=>`, so we want `# =>` instead of `#=>`. Thanks to @fxn for the suggestion. [ci skip]
* | Fix typo: `has_many :pets`, not `pets :has_many`.Peter Jaros2013-10-241-1/+1
| |
* | `Relation#count` doesn't use options anymore.Vipul A M2013-10-131-2/+2
| |
* | Stray nodoc causes rest of file not parsed [ci skip]edogawaconan2013-08-221-2/+0
| |
* | Removed support for deprecated `counter_sql`Neeraj Singh2013-07-021-1/+1
| |
* | Do not invoke callbacks when delete_all is calledNeeraj Singh2013-06-301-2/+2
| | | | | | | | | | | | | | | | | | | | | | Method `delete_all` should not be invoking callbacks and this feature was deprecated in Rails 4.0. This is being removed. `delete_all` will continue to honor the `:dependent` option. However if `:dependent` value is `:destroy` then the default deletion strategy for that collection will be applied. User can also force a deletion strategy by passing parameter to `delete_all`. For example you can do `@post.comments.delete_all(:nullify)`
* | Simplify/fix implementation of default scopesJon Leighton2013-06-281-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation was necessary in order to support stuff like: class Post < ActiveRecord::Base default_scope where(published: true) scope :ordered, order("created_at") end If we didn't evaluate the default scope at the last possible moment before sending the SQL to the database, it would become impossible to do: Post.unscoped.ordered This is because the default scope would already be bound up in the "ordered" scope, and therefore wouldn't be removed by the "Post.unscoped" part. In 4.0, we have deprecated all "eager" forms of scopes. So now you must write: class Post < ActiveRecord::Base default_scope { where(published: true) } scope :ordered, -> { order("created_at") } end This prevents the default scope getting bound up inside the "ordered" scope, which means we can now have a simpler/better/more natural implementation of default scoping. A knock on effect is that some things that didn't work properly now do. For example it was previously impossible to use #except to remove a part of the default scope, since the default scope was evaluated after the call to #except.
* | `CollectionProxy#include?` returns `true` and `false` as documented.Yves Senn2013-06-181-1/+1
| |
* | emphasize that callbacks are called in destroy_allNeeraj Singh2013-05-131-3/+3
| | | | | | | | | | | | | | Cleaned up rdoc a bit emphasizing that callbacks are called. Also removed the stress on the fact that records are always removed. If callbacks return false then records will not be deleted.
* | Move #proxy_association method to AssociationRelationJon Leighton2013-05-101-3/+1
| |
* | Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-04-111-2/+2
|\ \ | |/ |/| | | | | Conflicts: guides/source/action_mailer_basics.md
| * minor copy editingNeeraj Singh2013-03-301-2/+2
| |
* | Merge pull request #10058 from jamesgolick/masterJon Leighton2013-04-051-4/+2
|\ \ | | | | | | Avoid calling define_method in CollectionProxy#scope
| * | Refactor CollectionProxy#scope to avoid calling #extend.James Golick2013-04-021-4/+2
| |/
* / Move alias method near to the aliased one in collection proxyCarlos Antonio da Silva2013-04-031-2/+1
|/
* rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works.Yves Senn2013-03-151-3/+4
| | | | | | | | The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our Relation API is close to SQL terms I renamed `#uniq` to `#distinct`. There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue to work. I also updated the documentation to promote the use of `#distinct`.
* deal with `#append` and `#prepend` on association collections.Yves Senn2013-03-011-0/+5
| | | | | | | | | | | Closes #7364. Collection associations behave similar to Arrays. However there is no way to prepend records. And to append one should use `<<`. Before this patch `#append` and `#prepend` did not add the record to the loaded association. `#append` now behaves like `<<` and `#prepend` is not defined.
* don't use non-ascii ' chars in documentationYves Senn2013-03-011-4/+4
|
* CollectionProxy should be default scopedJon Leighton2013-01-181-0/+1
| | | | Fixes #8795
* prefer american spelling of 'behavior'Gosha Arinich2013-01-071-2/+2
|
* Replace comments' non-breaking spaces with spacesclaudiob2012-12-041-3/+3
| | | | | | | | | | Sometimes, on Mac OS X, programmers accidentally press Option+Space rather than just Space and don’t see the difference. The problem is that Option+Space writes a non-breaking space (0XA0) rather than a normal space (0x20). This commit removes all the non-breaking spaces inadvertently introduced in the comments of the code.
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-12-011-3/+13
|\ | | | | | | | | Conflicts: guides/source/active_record_validations.md
| * copy edits [ci skip]Vijay Dev2012-12-011-1/+1
| |
| * add documentation to CollectionProxy #length and #size methods [ci skip]Francesco Rodriguez2012-11-291-2/+7
| |
| * add documentation to CollectionProxy#empty?Francesco Rodriguez2012-11-291-1/+6
| |
* | Use separate Relation subclasses for each AR classJon Leighton2012-11-301-2/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | At present, ActiveRecord::Delegation compiles delegation methods on a global basis. The compiled methods apply to all subsequent Relation instances. This creates several problems: 1) After Post.all.recent has been called, User.all.respond_to?(:recent) will be true, even if User.all.recent will actually raise an error due to no User.recent method existing. (See #8080.) 2) Depending on the AR class, the delegation should do different things. For example, if a Post.zip method exists, then Post.all.zip should call it. But this will then result in User.zip being called by a subsequent User.all.zip, even if User.zip does not exist, when in fact User.all.zip should call User.all.to_a.zip. (There are various variants of this problem.) We are creating these compiled delegations in order to avoid method missing and to avoid repeating logic on each invocation. One way of handling these issues is to add additional checks in various places to ensure we're doing the "right thing". However, this makes the compiled methods signficantly slower. In which case, there's almost no point in avoiding method_missing at all. (See #8127 for a proposed solution which takes this approach.) This is an alternative approach which involves creating a subclass of ActiveRecord::Relation for each AR class represented. So, with this patch, Post.all.class != User.all.class. This means that the delegations are compiled for and only apply to a single AR class. A compiled method for Post.all will not be invoked from User.all. This solves the above issues without incurring significant performance penalties. It's designed to be relatively seamless, however the downside is a bit of complexity and potentially confusion for a user who thinks that Post.all and User.all should be instances of the same class. Benchmark --------- require 'active_record' require 'benchmark/ips' class Post < ActiveRecord::Base establish_connection adapter: 'sqlite3', database: ':memory:' connection.create_table :posts def self.omg :omg end end relation = Post.all Benchmark.ips do |r| r.report('delegation') { relation.omg } r.report('constructing') { Post.all } end Before ------ Calculating ------------------------------------- delegation 4392 i/100ms constructing 4780 i/100ms ------------------------------------------------- delegation 144235.9 (±27.7%) i/s - 663192 in 5.038075s constructing 182015.5 (±21.2%) i/s - 850840 in 5.005364s After ----- Calculating ------------------------------------- delegation 6677 i/100ms constructing 6260 i/100ms ------------------------------------------------- delegation 166828.2 (±34.2%) i/s - 754501 in 5.001430s constructing 116575.5 (±18.6%) i/s - 563400 in 5.036690s Comments -------- Bear in mind that the standard deviations in the above are huge, so we can't compare the numbers too directly. However, we can conclude that Relation construction has become a little slower (as we'd expect), but not by a huge huge amount, and we can still construct a large number of Relations quite quickly.
* fix warningsJon Leighton2012-11-091-1/+1
|