Commit Graph

3538 Commits

Author SHA1 Message Date
Ben Woosley
23c656c1bc Backport a super-simplified version of #6792, fixing
that #exists? and others can produce invalid SQL: "SELECT DISTINCT DISTINCT"

The combination of a :uniq => true association and the #distinct call
in #construct_limited_ids_condition combine to create invalid SQL, because
we're explicitly selecting DISTINCT, and also sending #distinct on to AREL,
via the relation#distinct_value.

Where #6792 was the forever fix, this is the minimal fix. Instead of
properly indicating the distinctness of the query through #uniq_value alone,
we use a literal select statement and set #uniq_value to always be falsey
2013-05-14 16:03:17 +02:00
Andrew Horner
c09829e03d Preserve context for joins while merging relations
This is a backport of #10164, already merged into
master. The issue is described in lengthy detail
in issues #3002 and #5494.
2013-05-11 22:41:47 -05:00
Daniel Schierbeck
ddaa5d5181 Don't try to EXPLAIN select_db calls
Now with a non-broken test.
2013-05-12 00:33:01 +02:00
Xavier Noria
0549ebea22 Revert "Don't try to EXPLAIN select_db calls"
Reason: This was backported, but the test does not pass as is.

This reverts commit a33d320cf4.
2013-05-11 01:28:06 +02:00
Xavier Noria
4fa860728f Merge pull request #10555 from dasch/dasch/3-2-stable
Don't try to EXPLAIN select_db calls
2013-05-10 08:05:54 -07:00
Daniel Schierbeck
a33d320cf4 Don't try to EXPLAIN select_db calls 2013-05-10 16:50:35 +02:00
Arun Agrawal
de5b89ddc9 Fixed pluck to be working with selects.
See #9777 for details.

Previously pluck is not returning what we wanted to
Added a test also to make sure it's working fine.
 
This will also fix the build for 1.8.7 as we 
were doing some sort on hash.

Thanks @pixeltrix for helping me out.

Thanks @linduxed for pairing with me.
2013-05-10 16:05:05 +02:00
Rafael Mendonça França
84c69a1653 Revert "Merge pull request #8209 from senny/backport_8176"
This reverts commit 7240202784, reversing
changes made to e4e2bcce75.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/relation/calculations.rb
	activerecord/test/cases/calculations_test.rb

Reason: This caused a regression since it changed the behavior in a
stable release.

Fixes #9777
2013-05-08 23:34:24 -03:00
Rafael Mendonça França
f8c4a31e0b Merge pull request #10489 from greenriver/ar_counter_cache_multiple_destroy
Confirm a record has not already been destroyed before decrementing counter cache

Conflicts:
	activerecord/CHANGELOG.md

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/associations/builder/belongs_to.rb
2013-05-06 22:44:01 -03:00
Aaron Patterson
9d7a748a51 adding test for the symbol refs 2013-04-26 16:47:27 -07:00
Erik Peterson
a6d9e16e41 Correctly parse bigint defaults in PostgreSQL, Backpost #10098.
Conflicts:

	activerecord/CHANGELOG.md
	activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
	activerecord/test/cases/schema_dumper_test.rb
2013-04-11 10:11:18 +02:00
Aaron Patterson
536f316cd3 Merge branch '3-2-later' into 3-2-stable
* 3-2-later:
  adding test for CVE
2013-04-09 09:22:42 -07:00
Carlos Antonio da Silva
e59f3809ef Merge pull request #7792 from seejee/chained_scopes_preload_properly
Fixes Issue #7490: Chained scopes will preload properly
2013-04-03 15:43:59 -07:00
Chris Geihsler
453c7d6c47 Chained scopes will be preloaded properly. Fixes #7490 2013-04-03 18:41:12 -04:00
Fred Wu
55e2954703 Don't reset inheritance_column when setting explicitly.
This is backported from master (cdfcbc4).
2013-03-27 09:12:31 +11:00
Yves Senn
845cc5c78d use ruby 1.8 Hash syntax [ci skip] 2013-03-22 15:23:57 +01:00
Yves Senn
c8edd4fda4 do not reset associations when preloading twice.
Closes #9806.

As the `through_options` always contained `{:order=>nil}` the second time,
the preloader ran, the association was always reset. This patch only
adds the `:order` to the `through_options` if it is set.
2013-03-22 15:08:09 +01:00
kennyj
dc2bc388bc Wrong exception is occured when raising no translatable exception
Conflicts:
	activerecord/CHANGELOG.md
2013-03-20 10:11:07 +00:00
Carlos Antonio da Silva
167b645a2a Bring back test and changelog entry from #pluck method and select clause 2013-03-18 18:28:07 -03:00
Aaron Patterson
afcd01bf25 Merge branch '3-2-13' into 3-2-stable
* 3-2-13:
  bumping to 3.2.13
  fix protocol checking in sanitization [CVE-2013-1857]
  JDOM XXE Protection [CVE-2013-1856]
  fix incorrect ^$ usage leading to XSS in sanitize_css [CVE-2013-1855]
  stop calling to_sym when building arel nodes [CVE-2013-1854]
  Merge pull request #9616 from exviva/multiple_select_name_double_square_brackets
  bumping to rc2
  Revert "Merge pull request #8209 from senny/backport_8176"
  Freeze columns only once per Result
  Preparing for 3.2.13.rc1 release
  Update CHANGELOGs for 3.2.13 release.

Conflicts:
	actionmailer/CHANGELOG.md
	actionpack/CHANGELOG.md
	activemodel/CHANGELOG.md
	activeresource/CHANGELOG.md
	activesupport/CHANGELOG.md
	railties/CHANGELOG.md
2013-03-18 10:17:04 -07:00
Aaron Patterson
f980289fd2 stop calling to_sym when building arel nodes [CVE-2013-1854] 2013-03-15 17:47:28 -07:00
Andrew White
3d4d7420ae Fix ar:mysql2 build on Ruby 1.8.7
The `skip` method is a no-op on Ruby 1.8.7 so we still need to
force skip by returning early from each test.
2013-03-13 07:24:21 +00:00
Carlos Antonio da Silva
348d693c6a Merge pull request #9613 from arunagw/remove_fixme
Removing FIXME
2013-03-08 07:43:24 -08:00
Arun Agrawal
c8918c6972 Removing FIXME
As we did in master.
2013-03-08 16:08:43 +01:00
Rafael Mendonça França
9bd5c86c3b Merge pull request #9549 from larrylv/reload-stable-target-before-saving
Fix issue #7526. Reload the association target if it's stale.
2013-03-07 08:23:23 -08:00
Yasuo Honda
5d57b821d0 Use shorter prefix and suffix as in Oracle database identifier
cannot be larger than 30 characters
2013-03-07 22:34:54 +09:00
Aaron Patterson
1b699fc8ad Revert "Merge pull request #8209 from senny/backport_8176"
This reverts commit 7240202784, reversing
changes made to e4e2bcce75.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/relation/calculations.rb
	activerecord/test/cases/calculations_test.rb
2013-03-05 11:33:16 -08:00
larrylv
939b896a06 Fix issue #7526. Reload the target if it's stale.
* This has been fixed at master via `365b8b6`, but not at 3-2-stable branch.

* @stale_state should be nil when a model isn't saved. via `0f3901e`.

* set @stale_state to nil when reset the target.
2013-03-05 12:43:05 +08:00
Yasuo Honda
c27da1fbcc Revert "Skip test_remove_column_with_array_as_an_argument_is_deprecated with Oracle adapter."
This reverts commit 7544c7a9f2.

Oracle enhanced adapter is supporting remove_column with Array.
2013-02-28 05:46:56 +09:00
Yasuo Honda
97df33d818 Fix ORA-00972 error at test_rename_table_with_prefix_and_suffix
backport pull request#5837 to 3-2-stable
2013-02-28 05:22:08 +09:00
Steve Klabnik
ee291b9b41 Revert "Merge pull request #9208 from dylanahsmith/3-2-mysql-quote-numeric"
This reverts commit 921a296a33.
2013-02-26 16:57:18 -08:00
Hiroshige Umino
55a1765942 Do not override attributes on dup by default scopes 2013-02-26 11:08:50 -08:00
Narihiro Nakamura
905b7df1fa Backported #7072 to 3-2-stable. Use database value for uniqueness validation scope. 2013-02-26 14:39:26 +09:00
Yves Senn
8f6fa345e5 Sqlite preserves primary keys when copying/altering tables.
Backport #2312.
Fixes #9367.

I also added a test-case to make sure that renaming or removing
a column preserves the primary key.
2013-02-23 15:23:28 +01:00
Rafael Mendonça França
a0d84227c2 Use order to get the first record since postgresql returns in the
desired order
2013-02-20 22:31:02 -03:00
Yves Senn
9be7f63db9 keep the build 💚, #first on 1.8.7 and pg is different
The build only failed for ruby-1.8.7 and pg. The problem was that the statement:

```ruby
author = Author.includes(:comments_with_order_and_conditions, :posts).first
```

resulted in Author with ID 2 where on all other rubies / db-engines Author with ID 1
was retunred. Of course this breaks the assertions.
2013-02-19 14:42:45 +01:00
Yves Senn
587f563c40 don't cache invalid subsets when preloading hmt associations.
Backport #9252.

Conflicts:

	activerecord/CHANGELOG.md
	activerecord/test/cases/associations/eager_test.rb

The preloader code on 3-2-stable is not based on relations but on option hashes.
I had to modify the original patch and comparing the option hashes could be more
fuzzy than comparing the relations. All the tests passed though.
2013-02-19 11:11:27 +01:00
Lilibeth De La Cruz
3c5f631caa Fix handling of dirty time zone aware attributes
Previously, when `time_zone_aware_attributes` were enabled, after
changing a datetime or timestamp attribute and then changing it back
to the original value, `changed_attributes` still tracked the
attribute as changed. This caused `[attribute]_changed?` and
`changed?` methods to return true incorrectly.

Example:

    in_time_zone 'Paris' do
      order = Order.new
      original_time = Time.local(2012, 10, 10)
      order.shipped_at = original_time
      order.save
      order.changed? # => false

      # changing value
      order.shipped_at = Time.local(2013, 1, 1)
      order.changed? # => true

      # reverting to original value
      order.shipped_at = original_time
      order.changed? # => false, used to return true
    end

(cherry picked from commit bc982cbcb34129ea2cfe8aa1f8e0b40e444e68db)

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb

Backport of #9073
Fixes #8898
2013-02-17 16:19:09 +00:00
Rafael Mendonça França
7f4975ffc6 Revert "Merge pull request #9252 from senny/8423_hmt_preloading_bug"
This reverts commit c5451777b0.

Conflicts:
	activerecord/CHANGELOG.md
2013-02-15 13:00:53 -02:00
Rafael Mendonça França
c5451777b0 Merge pull request #9252 from senny/8423_hmt_preloading_bug
don't cache invalid subsets when preloading hmt associations
Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/associations/eager_test.rb
2013-02-14 15:33:30 -02:00
Matthew Robertson
18ffe50581 backport of fix for issue #7630 2013-02-13 16:01:58 -08:00
Aaron Patterson
c35d913524 adding test for CVE 2013-02-09 17:00:59 -08:00
Guillermo Iguaran
b00fe01d6e Merge pull request #9224 from dylanahsmith/bigdecimal-takes-string
[3.2] Fix test failure for ruby 1.8.
2013-02-09 16:58:55 -08:00
Guillermo Iguaran
921a296a33 Merge pull request #9208 from dylanahsmith/3-2-mysql-quote-numeric
[3.2] active_record: Quote numeric values compared to string columns.
Conflicts:
	activerecord/CHANGELOG.md
2013-02-09 16:58:50 -08:00
Dylan Smith
cbdfaf2e29 Fix test failure for ruby 1.8.
BigDecimal.new needs to take a string rather than an integer in ruby 1.8.
2013-02-08 09:44:15 -05:00
Dylan Smith
04c2d2e2e4 active_record: Quote numeric values compared to string columns. 2013-02-07 05:02:38 -05:00
Yasuo Honda
e8357935ac This pull requests addresses ORA-01400 errors and also supports #6115 issue tested.
Issue #6115 has been fixed and tested with
the attribute `:null => false, :default => ""`
However `:null => false` attribute is not necessary to test this issue,
which causes many ORA-01400 errors with Oracle enhanced adapter.
2013-02-03 15:27:49 +04:00
Piotr Sarnacki
6a0a5f3032 Duplicate column_defaults properly
Backport c517602 to fix #6115

Deleted:
    activerecord/lib/active_record/core.rb

Conflicts:
    activerecord/test/cases/base_test.rb
2013-02-03 15:27:42 +04:00
Rafael Mendonça França
bf794bb36f Merge pull request #9078 from senny/6865_ar_count_with_uniq
`#count` in conjunction with `#uniq` performs distinct count.
Conflicts:
	activerecord/CHANGELOG.md
2013-02-02 10:19:23 -02:00
Ian Lesperance
b6d4931292 Fix pluck when columns/tables are reserved words.
Backport #7536 to fix #8968.

Conflicts:

	activerecord/CHANGELOG.md
	activerecord/lib/active_record/relation/calculations.rb
2013-01-23 15:17:33 +01:00