Commit Graph

285 Commits

Author SHA1 Message Date
robertomiranda
16f6f2592e Change behaviour with empty array in where clause 2013-02-08 06:37:30 -05:00
robertomiranda
e170014113 Change behaviour with empty hash in where clause 2013-02-08 01:04:32 -05:00
Dylan Smith
a712e08ebe active_record: Quote numeric values compared to string columns. 2013-02-07 04:59:33 -05:00
Carlos Antonio da Silva
7173919af9 Add changelog entry for #9203 about schema dumper with db extensions
[ci skip]
2013-02-06 22:42:29 -02:00
Rafael Mendonça França
adb8fea493 CHANGELOG review 2013-01-31 17:48:59 -02:00
Aaron Stone
4b005fb371 DATABASE_URL parsing should turn numeric strings into numeric types, and
the strings true and false into boolean types, in order to match how
YAML would parse the same values from database.yml and prevent
unexpected type errors in the database adapters.
2013-01-31 09:01:20 -08:00
Carlos Antonio da Silva
2cb576ef36 Refactor to use each_key, remove extra spaces 2013-01-28 23:25:03 -02:00
Jon Leighton
c8d889905d Prevent Relation#merge from collapsing wheres on the RHS
This caused a bug with the new associations implementation, because now
association conditions are represented as Arel nodes internally right up
to when the whole thing gets turned to SQL.

In Rails 3.2, association conditions get turned to raw SQL early on,
which prevents Relation#merge from interfering.

The current implementation was buggy when a default_scope existed on the
target model, since we would basically end up doing:

  default_scope.merge(association_scope)

If default_scope contained a where(foo: 'a') and association_scope
contained a where(foo: 'b').where(foo: 'c') then the merger would see
that the same column is representated on both sides of the merge and
collapse the wheres to all but the last: where(foo: 'c')

Now, the RHS of the merge is left alone.

Fixes #8990
2013-01-27 20:34:52 +00:00
Lilibeth De La Cruz
bc982cbcb3 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
2013-01-26 16:57:33 +00:00
Yves Senn
648def4060 #count in conjunction with #uniq performs distinct count.
closes #6865
2013-01-26 12:16:28 +01:00
bUg
af1ef85ad2 Add postgresql range types support 2013-01-23 13:37:14 +01:00
wangjohn
bbcebb6ab2 Added a changelog entry. 2013-01-20 14:02:12 -05:00
Jon Leighton
5937bd02de Undeprecate the :extend option
Suggested by @dhh.

It doesn't affect the generated SQL, so seems reasonable to continue to
allow it as an association option.
2013-01-18 12:30:47 +00:00
Yves Senn
ec07735641 CollectionAssociation#empty? respects newly builded records 2013-01-13 00:20:38 +01:00
Prem Sichanugrist
ec53106068 Add CHANGELOG entry for YAML parsing removal
This is for commit e80546cdec56a9c3fcaf6217cba08a02d789d2bc.
2013-01-08 16:59:55 -05:00
Tristan Harward
807e176aba Fix error when assigning NaN to an integer column
Also covers any non-castable case by returning nil, which
is in-line with the intention of the former implementation,
but covers the odd cases which respond to to_i but raise
an error when it's called, such as NaN, Infinity and -Infinity.

Fixes #8757
2013-01-06 16:09:40 -05:00
Carlos Antonio da Silva
149b86d97b Move changelog entry in railties to the top
Other minor changelog improvements [ci skip]
2013-01-04 22:49:14 -02:00
Rob Worley
e209107a51 Support for PostgreSQL's ltree data type. 2013-01-04 21:22:34 +00:00
Jason Stirk
8d98c83bbc Fix undefined method `to_i' introduced since 3.2.8
This commit fixes a bug introduced in 96a13fc7 which breaks behaviour of
integer fields.

In 3.2.8, setting the value of an integer field to a non-integer (eg.
Array, Hash, etc.) would default to 1 (true) :

    # 3.2.8
    p = Post.new
    p.category_id = [ 1, 2 ]
    p.category_id # => 1
    p.category_id = { 3 => 4 }
    p.category_id # => 1

In 3.2.9 and above, this will raise a NoMethodError :

    # 3.2.9
    p = Post.new
    p.category_id = [ 1, 2 ]

    NoMethodError: undefined method `to_i' for [1, 2]:Array

Whilst at first blush this appear to be sensible, it combines in bad
ways with scoping.

For example, it is common to use scopes to control access to data :

    @collection = Posts.where(:category_id => [ 1, 2 ])
    @new_post = @collection.new

In 3.2.8, this would work as expected, creating a new Post object
(albeit with @new_post.category_id = 1). However, in 3.2.9 this will
cause the NoMethodError to be raised as above.

It is difficult to avoid triggering this error without descoping before
calling .new, breaking any apps running on 3.2.8 that rely on this
behaviour.

This patch deviates from 3.2.8 in that it does not retain the somewhat
spurious behaviour of setting the attribute to 1. Instead, it explicitly
sets these invalid values to nil :

    p = Post.new
    p.category_id = [ 1, 2 ]
    p.category_id # => nil

This also fixes the situation where a scope using an array will
"pollute" any newly instantiated records.

    @new_post = @collection.new
    @new_post.category_id # => nil

Finally, 3.2.8 exhibited a behaviour where setting an object to an
integer field caused it to be coerced to "1". This has not been
retained, as it is spurious and surprising in the same way that setting
Arrays and Heshes was :

    c = Category.find(6)
    p = Post.new

    # 3.2.8
    p.category_id = c
    p.category_id # => 1

    # This patch
    p.category_id = c
    p.category_id # => nil

This commit includes explicit test cases that expose the original issue
with calling new on a scope that uses an Array. As this is a common
situation, an explicit test case is the best way to prevent regressions
in the future.

It also updates and separates existing tests to be explicit about the
situation that is being tested (eg. AR objects vs. other objects vs.
non-integers)
2013-01-04 10:34:08 +11:00
Guillermo Iguaran
cb2bd4aa61 Merge pull request #8705 from amparo-luna/change_update_attributes_to_update
Rename update_attributes method to update
2013-01-03 09:09:59 -08:00
Amparo Luna + Guillermo Iguaran
d826f14443 Add Changelog entry regarding update_attibutes being renamed to update 2013-01-03 12:04:25 -05:00
Carlos Antonio da Silva
9f200fb296 Changelog improvements [ci skip] 2013-01-02 21:11:11 -02:00
Rafael Mendonça França
5d80da812b Fix CHANGELOG style [ci skip] 2012-12-26 12:19:09 -03:00
Pascal Friederich
5a3dc8092d validate :on option on after_commit and after_rollback callbacks 2012-12-26 11:37:37 +01:00
Marc-Andre Lafortune
a81845f268 Update Migration and 4.0 Release Guides, Changelogs [#8267] 2012-12-21 13:56:16 -05:00
Rafael Mendonça França
f2e0925ab7 Serialized attribute can be serialized in an integer column
Fix #8575
2012-12-21 14:41:13 -03:00
Carlos Antonio da Silva
42b555dcf3 Fix Action Mailer changelog indenation to match other changelogs
Also some minor improvements to other changelogs. [ci skip]
2012-12-19 23:09:04 -02:00
Yves Senn
d01f913f8d Keep index names when using with sqlite3 2012-12-19 09:07:09 +01:00
Gary S. Weaver
9bb27f7ffe #5523 Add ability for postgresql adapter to disable user triggers in disable_referential_integrity. 2012-12-18 10:46:16 -05:00
Pedro Padron
ba98dad113 Added support for validates_uniqueness_of in PostgreSQL array columns. Fixes: #8075. 2012-12-18 08:35:03 -02:00
Alexey
9a4a095ed7 AR supporting new intrange data type on PostgreSQL >= 9.2 2012-12-16 13:11:10 +02:00
Carlos Antonio da Silva
df9f9b7f3e Convert changelogs to 1.9 hash style and fix some formatting [ci skip] 2012-12-14 20:25:22 -02:00
Matthew M. Boedicker
8f59ffce67 Do not log the binding values for binary columns.
They tend to be large and not very useful in the log.
2012-12-14 12:19:17 -08:00
Matthew Robertson
a765c8426f Fix for has_many_through counter_cache bug
This commit fixes reported issue #7630 in which counter
caches were not being updated properly when replacing
has_many_through relationships
2012-12-14 10:03:05 -08:00
Yves Senn
349d460600 recognize migrations, in folders containing numbers and 'rb'.
Closes #8492
2012-12-13 09:08:32 +01:00
Carlos Antonio da Silva
2d3b1dabc9 Remove changelog entry from #8441 [ci skip]
This issue only happens on master due to internal AR refactorings, so
there is no need for a changelog entry.

The test was backported to 3-2-stable to ensure there won't be any regressions.
2012-12-11 08:33:58 -02:00
Rafael Mendonça França
d668544785 Add CHANGELOG entry for #6376.
Conflicts:
	activerecord/CHANGELOG.md
2012-12-10 17:48:31 -03:00
Rafael Mendonça França
9cce1ea2fd Allow users to choose the timestamp format in the cache key
This can be done using the class attribute cache_timestamp_format

Conflicts:
	railties/guides/source/configuring.textile
2012-12-10 17:48:26 -03:00
itzki
7efcc5d72f Fix decorating columns for serialized attributes 2012-12-10 14:44:24 +09:00
Jeremy Kemper
cff747d304 Move to the schema-migrations-metadata branch.
Pending work on graceful app upgrades.

Revert "Merge pull request #8439 from joshsusser/fixes"

This reverts commit ce8ac39338f86388e70356b3a470b3ea443802ae, reversing
changes made to b0e7b6f67c984d4b1502e801781ed75fad681633.

Revert "Merge pull request #8431 from joshsusser/schemadump"

This reverts commit 036d3e1c2b65c4b8cbd23de2e20ad67b9b756182, reversing
changes made to 0c692f4d121792117b6a71e5ed590a31c3b9d12e.

Revert "Merge branch 'joshsusser-master' into merge"

This reverts commit 0c692f4d121792117b6a71e5ed590a31c3b9d12e, reversing
changes made to 2e299fca715b083a60222a85e48f9d3b8dd8ce93.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
	activerecord/test/cases/schema_dumper_test.rb
2012-12-09 15:57:34 -07:00
Aaron Stone
97d06e8c4b Session variables for mysql, mysql2, and postgresql adapters can be set
in the new 'variables:' hash in each database config section in database.yml.
The key-value pairs of this hash will be sent in a 'SET key = value, ...'
query on new database connections.

The configure_connection methods from mysql and mysql2 into are
consolidated into the abstract_mysql base class.
2012-12-08 10:11:10 -08:00
Caike Souza
ad59260f70 Update AR Changelog with correct example using includes
These queries don't seem to work without the includes clause. [ci skip]
2012-12-08 08:16:13 -02:00
Carlos Antonio da Silva
8d02afeaee Rollback where.like and where.not_like
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.
2012-12-07 16:52:55 -02:00
Carlos Antonio da Silva
23b9cc8423 Merge pull request #8332 from amatsuda/ar_where_chain
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
2012-12-07 00:46:06 -02:00
Carlos Antonio da Silva
0e67f793cd Unscope update_column(s) query to ignore default scope
When applying default_scope to a class with a where clause, using
update_column(s) could generate a query that would not properly update
the record due to the where clause from the default_scope being applied
to the update query.

    class User < ActiveRecord::Base
      default_scope where(active: true)
    end

    user = User.first
    user.active = false
    user.save!

    user.update_column(:active, true) # => false

In this situation we want to skip the default_scope clause and just
update the record based on the primary key. With this change:

    user.update_column(:active, true) # => true

Fixes #8436.
2012-12-06 23:17:56 -02:00
Carlos Antonio da Silva
1eaf3db804 Improve AR changelog 2012-12-06 22:24:00 -02:00
Steve Klabnik
b27f27d38d CHANGELOG for 78d5d6f.
It was pointed out by @giner that the CHANGELOG entry for 78d5d6f868
wasn't included. Here it is.
2012-12-06 10:43:33 -08:00
Aaron Patterson
0c692f4d12 Merge branch 'joshsusser-master' into merge
* joshsusser-master:
  style cleanup
  Add migration history to schema.rb dump
  Add metadata to schema_migrations

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/schema.rb
2012-12-05 12:13:49 -08:00
claudiob
019df98875 Replace comments' non-breaking spaces with spaces
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.
2012-12-04 22:11:54 -08:00
kennyj
634d28e6cf Fix #8414. Performance problem with postgresql adapter primary_key function. 2012-12-05 02:19:03 +09:00