Commit Graph

8659 Commits

Author SHA1 Message Date
Vijay Dev
9685019c4a copy edits [ci skip] 2012-12-01 22:59:10 +05:30
Florent Guilleux
daab9bba88 Fix Calculations#pluck doc to mention several attributes can be selected [ci skip] 2012-12-01 11:23:02 -05:00
Francesco Rodriguez
abdfffa213 add documentation to CollectionProxy #length and #size methods [ci skip] 2012-11-29 12:58:31 -05:00
Francesco Rodriguez
61a7a9f38b add documentation to CollectionProxy#empty? 2012-11-29 12:51:31 -05:00
Rafael Mendonça França
b313bcba07 Merge pull request #8291 from senny/8265_build_with_polymorphic_association
prevent mass assignment of polymorphic type when using `build`

Conflicts:
	activerecord/CHANGELOG.md
2012-11-22 11:52:01 -02:00
Yves Senn
053bfa2304 prevent mass assignment of polymorphic type when using build
Closes #8265
2012-11-22 08:58:00 +01:00
Carlos Antonio da Silva
fd1c45761e Remove the #sum method from CollectionAssociation
Since edd94cee9af1688dd036fc58fd405adb30a5e0da, CollectionProxy
delegates all calculation methods - except count - to the scope,
which does basically what this method was doing, but since we're
delegating from the proxy, the association method was never called.
2012-11-21 22:21:04 -02:00
Carlos Antonio da Silva
ad9983f625 Deprecate Relation#sum with a block.
To perform a sum calculation over the array of elements, use to_a.sum(&block).

Please check the discussion in f9cb645dfcb5cc89f59d2f8b58a019486c828c73
for more context.
2012-11-21 22:21:01 -02:00
Carlos Antonio da Silva
76a6bfd6c8 Revert "Yield only one argument instead of splatting."
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
2012-11-21 22:18:51 -02:00
Jon Leighton
ae934aef4a Don't allocate new strings in compiled attribute methods
This improves memory and performance without having to use symbols which
present DoS problems. Thanks @headius and @tenderlove for the
suggestion.

This was originally committed in
f1765019ce9b6292f2264b4601dad5daaffe3a89, and then reverted in
d3494903719682abc0948bef290af0d3d7b5a440 due to it causing problems in a
real application. This second attempt should solve that.

Benchmark
---------

require 'active_record'
require 'benchmark/ips'

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')

class Post < ActiveRecord::Base
  connection.create_table :posts, force: true do |t|
    t.string :name
  end
end

post = Post.create name: 'omg'

Benchmark.ips do |r|
  r.report('Post.new')          { Post.new name: 'omg' }
  r.report('post.name')         { post.name }
  r.report('post.name=')        { post.name = 'omg' }
  r.report('Post.find(1).name') { Post.find(1).name }
end

Before
------

Calculating -------------------------------------
            Post.new      1419 i/100ms
           post.name      7538 i/100ms
          post.name=      3024 i/100ms
   Post.find(1).name       243 i/100ms
-------------------------------------------------
            Post.new    20637.6 (±12.7%) i/s -     102168 in   5.039578s
           post.name  1167897.7 (±18.2%) i/s -    5186144 in   4.983077s
          post.name=    64305.6 (±9.6%) i/s -     317520 in   4.998720s
   Post.find(1).name     2678.8 (±10.8%) i/s -      13365 in   5.051265s

After
-----

Calculating -------------------------------------
            Post.new      1431 i/100ms
           post.name      7790 i/100ms
          post.name=      3181 i/100ms
   Post.find(1).name       245 i/100ms
-------------------------------------------------
            Post.new    21308.8 (±12.2%) i/s -     105894 in   5.053879s
           post.name  1534103.8 (±2.1%) i/s -    7634200 in   4.979405s
          post.name=    67441.0 (±7.5%) i/s -     337186 in   5.037871s
   Post.find(1).name     2681.9 (±10.6%) i/s -      13475 in   5.084511s
2012-11-21 21:59:09 +00:00
Carlos Antonio da Silva
96106a1493 Move migration test together with other join table tests 2012-11-21 19:34:55 -02:00
Rafael Mendonça França
b6793ba110 Merge pull request #7716 from steveklabnik/issue_7715
Coerce strings in create_join_table.
2012-11-21 11:35:49 -08:00
Steve Klabnik
48a035712e Coerce strings in create_join_table.
If you accidentally pass a string and a symbol, this breaks. So
we coerce them both to strings.

Fixes #7715
2012-11-21 13:21:18 -06:00
Chris Patuzzo
104f4fde1d Typo 2012-11-21 18:04:08 +00:00
Rafael Mendonça França
1c0e7ab2f8 Merge pull request #6245 from bogdan/bc_timestamp
Postgresql adapter: fix handling of BC timestamps
2012-11-21 09:34:55 -08:00
Semyon Perepelitsa
2197e1f365 Refactoring, testing and documenting pg_connection.distinct 2012-11-21 23:51:32 +08:00
Bogdan Gusiev
fa73cf7275 Fix postgresql adapter to handle bc timestamps correctly 2012-11-21 16:11:14 +02:00
Rafael Mendonça França
f058e565c1 Remove return guard and use code convetions 2012-11-20 22:44:33 -02:00
Victor Costan
a8a60e9240 Postgresql doesn't accepts limits on text columns. 2012-11-20 10:59:40 -05:00
Carlos Antonio da Silva
14620eae34 Be a bit less conservative with mysql in adapter 2012-11-19 20:59:27 -02:00
Carlos Antonio da Silva
3b99653587 Remove not needed begin..end from AR#save 2012-11-19 12:52:20 -02:00
Carlos Antonio da Silva
7e10f38880 Initialize accessors to remove some warnings in Ruby 2.0 2012-11-19 12:52:19 -02:00
Rafael Mendonça França
0cc9c1255d Merge pull request #3023 from Tho85/preserve_sti_type
AR::Base.becomes should not change the STI type

Conflicts:
	activerecord/CHANGELOG.md
2012-11-18 23:25:13 -02:00
Jarek Radosz
1a782b2b63 Add rename_index to change_table. 2012-11-19 02:10:28 +01:00
Carlos Antonio da Silva
a739340d3c Ensure ordering to make the test pass with postgresql 2012-11-18 16:27:50 -02:00
Dieter Komendera
22ed92dbae Add test to ensure preloading works as expected with "select" and "includes".
This didn't work in rails 3.1. See #2303 for more information and original pull request.
2012-11-18 13:17:11 +01:00
Carlos Antonio da Silva
4525b97605 Remove not used require and some useless test comments 2012-11-17 23:00:16 -02:00
Carlos Antonio da Silva
af43e719ac Bump mysql gem version to the newly 2.9.0, fix build. 2012-11-17 22:50:58 -02:00
Carlos Antonio da Silva
6c5bd10dc4 Fix typo in module name and make #in_time_zone private 2012-11-17 14:01:35 -02:00
Carlos Antonio da Silva
d4bf1c97ce Extract #in_time_zone helper method duplication to a module 2012-11-17 13:55:42 -02:00
Carlos Antonio da Silva
6d2aadef9d Simplify helper method in attribute methods test 2012-11-17 13:55:42 -02:00
Carlos Antonio da Silva
b6a68737fb Remove return guard 2012-11-17 13:55:42 -02:00
Thomas Hollstegge
70fa756ddb AR::Base.becomes should not change the STI type
If you want to change the STI type too, use AR::Base.becomes! instead
2012-11-17 16:45:23 +01:00
Alexey Muranov
506b9f215f Add a deprecation before removing find_table_name
The `ActiveRecord::Fixtures::find_table_name` method was removed from "master" almost a year ago, but it was never deprecated.  Here it comes back, more dead than alive.
2012-11-17 15:28:55 +01:00
Carlos Antonio da Silva
7411970398 Fix some AR changelog entries [ci skip] 2012-11-16 21:37:53 -02:00
George Brocklehurst
3e64859938 Test for has_many bug on unsaved records
See issue #7950.
2012-11-16 21:34:31 -02:00
Vijay Dev
7b70eeed43 Merge branch 'master' of github.com:lifo/docrails
Conflicts:
	actionpack/lib/action_dispatch/routing/redirection.rb
2012-11-17 01:50:49 +05:30
Aaron Patterson
0803d7a93b arel columns can be used for grouping so that "weird" column names are usable 2012-11-15 13:42:50 -08:00
Aaron Patterson
ca71bb8c99 stop hardcoding FrontBase adapter conditionals 2012-11-15 13:42:50 -08:00
Aaron Patterson
f77beac8a6 stop passing *args to generate aliases 2012-11-15 13:42:50 -08:00
Aaron Patterson
d5a8bdb2e2 create fewer relation objects 2012-11-15 13:42:50 -08:00
Carlos Antonio da Silva
9ad8d670ec Assert the query result instead of checking for nothing raised
Nothing should be raised anyway 😄

Thanks @spastorino ❤️
https://github.com/rails/rails/pull/8202/files#r2112067
2012-11-13 14:54:47 -02:00
Carlos Antonio da Silva
087150d9b7 Merge pull request #8202 from nikitug/regression_test_on_dynamic_finder_result
Regression test for #7238
2012-11-13 06:59:17 -08:00
Nikita Afanasenko
8424d0dda3 Regression test for #7238 2012-11-13 18:39:07 +04:00
Rafael Mendonça França
3a335720db Merge pull request #8176 from senny/7551_pluck_with_select
`#pluck` can be used on a relation with `select` clause (#7551)
2012-11-13 06:27:42 -08:00
Nikita Afanasenko
ff2973a09a Add a regression test on #8195 2012-11-13 13:33:45 +04:00
Aaron Patterson
85cc7122ba only clear caches if we are actually connected to the database 2012-11-12 17:24:10 -08:00
Yves Senn
663d9ef670 #pluck can be used on a relation with select clause.
Closes #7551
2012-11-12 16:27:44 +01:00
Yves Senn
d5ac2801d9 cleanup, removed whitespace from CHANGELOG 2012-11-12 16:06:58 +01:00
Vipul A M
5359ad9ed1 Merge and add tests related to 5215 2012-11-12 18:13:20 +05:30