aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
Commit message (Collapse)AuthorAgeFilesLines
* These are already required through AS/railsAkira Matsuda2013-01-072-3/+0
| | | | | | * dependencies/autoload * concern * deprecation
* refatctoring of some code repetition in spawn_methodsAngelo capilleri2012-12-311-8/+10
|
* warning removed: shadowing outer local variableArun Agrawal2012-12-301-2/+2
|
* fix time typcasting on group counts in PGAaron Patterson2012-12-281-2/+5
|
* mysql does not return alias names, so fall backAaron Patterson2012-12-281-4/+10
|
* fix PG typecasting errorsAaron Patterson2012-12-281-2/+5
|
* Replace some global Hash usages with the new thread safe cache.thedarkone2012-12-141-22/+16
| | | | | | | | | | | | | | | | Summary of the changes: * Add thread_safe gem. * Use thread safe cache for digestor caching. * Replace manual synchronization with ThreadSafe::Cache in Relation::Delegation. * Replace @attribute_method_matchers_cache Hash with ThreadSafe::Cache. * Use TS::Cache to avoid the synchronisation overhead on listener retrieval. * Replace synchronisation with TS::Cache usage. * Use a preallocated array for performance/memory reasons. * Update the controllers cache to the new AS::Dependencies::ClassCache API. The original @controllers cache no longer makes much sense after @tenderlove's changes in 7b6bfe84f3 and f345e2380c. * Use TS::Cache in the connection pool to avoid locking overhead. * Use TS::Cache in ConnectionHandler.
* Improve where.not docs [ci skip]Carlos Antonio da Silva2012-12-081-14/+8
| | | | | | | * Fix example queries * Remove doc entries of where.like/not_like. * Remove :chain from where.not related docs. To me that's an implementation detail and we don't expect people to use where(:chain).not.
* Rollback where.like and where.not_likeCarlos Antonio da Silva2012-12-071-26/+0
| | | | | | | | | | | | | | | | | | | The real win with these chain methods is where.not, that takes care of different scenarios in a graceful way, for instance when the given value is nil. where("author.id != ?", author_to_ignore.id) where.not("author.id", author_to_ignore.id) Both where.like and where.not_like compared to the SQL versions doesn't seem to give us that much: Post.where("title LIKE 'ruby on%'") Post.where.like(title: 'ruby on%'") Post.where("title NOT LIKE 'ruby on%'") Post.where.not_like(title: 'ruby on%'") Thus Rails is adding where.not, but not where.like/not_like and others.
* Document the types of arguments accepted by AR#notclaudiob2012-12-071-2/+11
| | | | | | | | This commit stems from https://github.com/rails/rails/pull/8332#issuecomment-11127957 Since the formats in which conditions can be passed to `not` differ from the formats in which conditions can be passed to `like` and `not_like`, then I think it's worth adding rdoc and tests to show this behavior
* Fix where.not with in clauseCarlos Antonio da Silva2012-12-071-3/+3
| | | | | | Arel::Nodes::In inherits from Arel::Nodes::Equality, so the case statement was always using the Equality operator for both scenarios, resulting in a not equal query instead.
* Update #where rdoc to match 6ba0f97 [ci skip]claudiob2012-12-071-4/+4
| | | | | | | | This commit updates the rdoc of AR#where to match the changes applied in https://github.com/rails/rails/commit/6ba0f97 that is: * `where(nil)` has the same effect of `where('')`: a no op * `where` (no args) has the same effect of `where(:chain)`: to create a WhereChain
* Ensure there won't be any regression with where(nil) callsCarlos Antonio da Silva2012-12-071-4/+4
| | | | | | | | | | | | | | | | | | | Consider this scenario: if params[:foo] conditions = { foo: true } end foos = Foo.where(conditions).order(:id) When params[:foo] is nil, this would call: foos = Foo.where(nil).order(:id) In this scenario, we want Foo.where(conditions) to be the same as calling Foo.all, otherwise we'd get a "NoMethodError order for WhereChain". Related to #8332.
* Merge pull request #8332 from amatsuda/ar_where_chainCarlos Antonio da Silva2012-12-071-7/+98
|\ | | | | | | | | | | | | | | Relation.where with no args can be chained with not, like, and not_like Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/relation/query_methods.rb
| * Relation.where with no args can be chained with not, like, and not_likeAkira Matsuda2012-11-301-7/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | examples: Model.where.not field: nil #=> "SELECT * FROM models WHERE field IS NOT NULL Model.where.like name: 'Jeremy%' #=> "SELECT * FROM models WHERE name LIKE 'Jeremy%' this feature was originally suggested by Jeremy Kemper https://github.com/rails/rails/pull/5950#issuecomment-5591330 Closes #5950
* | Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-12-042-17/+2
|\ \ | | | | | | | | | | | | Conflicts: guides/source/migrations.md
| * | Cleans and removes useless 'Examples' tag [ci skip]Alvaro Pereyra2012-12-011-7/+2
| | |
| * | remove unneeded Examples tag [ci skip]Carlos Duclos2012-12-011-10/+0
| | |
* | | Do not instantiate intermediate AR objects when eager loading.Yves Senn2012-12-041-2/+4
|/ / | | | | | | Closes #3313
* | Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-12-011-3/+3
|\ \ | | | | | | | | | | | | Conflicts: guides/source/active_record_validations.md
| * | copy edits [ci skip]Vijay Dev2012-12-011-1/+1
| | |
| * | Fix Calculations#pluck doc to mention several attributes can be selected [ci ↵Florent Guilleux2012-12-011-3/+3
| |/ | | | | | | skip]
* | Use separate Relation subclasses for each AR classJon Leighton2012-11-301-32/+100
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Mark Relation mutators as :nodoc:Jon Leighton2012-11-302-48/+23
|/ | | | | These are for internal use only and cannot be relied on as part of the public API. See discussion on 8c2c60511beaad05a218e73c4918ab89fb1804f0.
* Deprecate Relation#sum with a block.Carlos Antonio da Silva2012-11-211-0/+6
| | | | | | | To perform a sum calculation over the array of elements, use to_a.sum(&block). Please check the discussion in f9cb645dfcb5cc89f59d2f8b58a019486c828c73 for more context.
* Revert "Yield only one argument instead of splatting."Carlos Antonio da Silva2012-11-211-14/+3
| | | | | | | | | | | | | | This reverts commit f9cb645dfcb5cc89f59d2f8b58a019486c828c73. Conflicts: activerecord/CHANGELOG.md Revert "Allow blocks for count with ActiveRecord::Relation. Document and test that sum allows blocks" This reverts commit 9cc2bf69ce296b7351dc612a8366193390a305f3. Conflicts: activerecord/lib/active_record/relation/calculations.rb
* Remove not used require and some useless test commentsCarlos Antonio da Silva2012-11-171-2/+0
|
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2012-11-175-15/+15
|\ | | | | | | | | Conflicts: actionpack/lib/action_dispatch/routing/redirection.rb
| * 1.9 Syntax related changesAvnerCohen2012-11-105-15/+15
| |
* | arel columns can be used for grouping so that "weird" column names are usableAaron Patterson2012-11-151-0/+4
| |
* | stop hardcoding FrontBase adapter conditionalsAaron Patterson2012-11-151-1/+1
| |
* | stop passing *args to generate aliasesAaron Patterson2012-11-151-4/+2
| |
* | create fewer relation objectsAaron Patterson2012-11-151-3/+6
| |
* | `#pluck` can be used on a relation with `select` clause.Yves Senn2012-11-121-1/+3
| | | | | | | | Closes #7551
* | Make ActiveRecord::Delegation#method_missing threadsafeJon Leighton2012-11-101-3/+21
| | | | | | | | | | | | | | | | | | | | | | | | Two threads may be in method_missing at the same time. If so, they might both try to define the same delegator method. Such a situation probably wouldn't result in a particularly spectacular bug as one method would probably just be overridden by an identical method, but it could cause warnings to pop up. (It could be worse if method definition is non-atomic in a particular implementation.) (We will also need this mutex shortly anyway, see #8127.)
* | Remove not used indifferent_access requires from Base and FinderMethodsCarlos Antonio da Silva2012-11-071-2/+0
| |
* | Use cached quoted_table_name instead of going through the connectionCarlos Antonio da Silva2012-11-071-1/+1
| |
* | Remove block given check from private find_with_idsCarlos Antonio da Silva2012-11-071-2/+0
| | | | | | | | | | This is already handled by #find, it's a duplicate check, since find_with_ids is not called from anywhere else.
* | Use flat_map when building AR orderCarlos Antonio da Silva2012-11-041-6/+4
|/
* Fix find_in_batches against string IDs when start option is not specified.Alexis Bernard2012-10-311-2/+2
|
* ActiveRecord::Relation#none! method.Juanjo Bazán2012-10-281-0/+5
|
* Remove ActiveRecord::ModelJon Leighton2012-10-262-4/+4
| | | | | | | | | | In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
* use columns hash to look up the column for the count fieldAaron Patterson2012-10-171-1/+1
|
* ActiveRecord: sum expression returns string '0' for no records, fixedTim Macfarlane2012-10-151-1/+1
|
* buckets hash isn't public, so use symbol keys to avoid stringAaron Patterson2012-10-151-8/+8
| | | | allocations
* performance improvements to joins!Aaron Patterson2012-10-122-5/+13
| | | | | | | | | | | | | | | | | | Before: Calculating ------------------------------------- ar 87 i/100ms ------------------------------------------------- ar 823.4 (±11.8%) i/s - 4089 in 5.070234s After: Calculating ------------------------------------- ar 88 i/100ms ------------------------------------------------- ar 894.1 (±3.9%) i/s - 4488 in 5.028161s Same test as 3a6dfca7f5f5bd45cea2f6ac348178e72423e1d5
* Speed up relation merging by reducing calls to Array#-Aaron Patterson2012-10-121-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | before: Calculating ------------------------------------- ar 83 i/100ms ------------------------------------------------- ar 832.1 (±4.0%) i/s - 4233 in 5.096611s after: Calculating ------------------------------------- ar 87 i/100ms ------------------------------------------------- ar 839.0 (±9.3%) i/s - 4176 in 5.032782s Benchmark: require 'config/environment' require 'benchmark/ips' GC.disable unless User.find_by_login('tater') u = User.new u.login = 'tater' u.save! end def active_record user = User.find_by_login('tater') starred = user.starred_items.count end active_record Benchmark.ips do |x| x.report("ar") { active_record } end
* trailling whitespace cleanup in query_methods.rbYves Senn2012-10-121-12/+12
|
* learn ActiveRecord::QueryMethods#order work with hash argumentsTima Maslyuchenko2012-10-121-4/+47
|
* Fix typo: 'this also mean' -> 'this also means'Jeffrey Hardy2012-10-081-1/+1
|