Commit Graph

228 Commits

Author SHA1 Message Date
Rafael Mendonça França
f3aaf6d7d1 Use assert_nil instead of assert_equal 2012-11-28 12:02:11 -02:00
Alisdair McDiarmid
fc4e387d7a Don't call will_change! for datetime nil->"".
Setting a nil datetime attribute to a blank string should not cause the
attribute to be dirty.

Fix #8310
2012-11-25 11:24:27 +00:00
Carlos Antonio da Silva
d23c761f5a Fix changelog entry about fast_string_to_time fix
Introduced in 53ca22f2e11cd3050d75385bc31b6bb5055a2738.
Thanks @rochefort. [ci skip]
2012-11-24 09:30:18 -02: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
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
Bogdan Gusiev
fa73cf7275 Fix postgresql adapter to handle bc timestamps correctly 2012-11-21 16:11:14 +02:00
Victor Costan
a8a60e9240 Postgresql doesn't accepts limits on text columns. 2012-11-20 10:59:40 -05: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
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
Carlos Antonio da Silva
7411970398 Fix some AR changelog entries [ci skip] 2012-11-16 21:37:53 -02: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
Bogdan Gusiev
3cb0f3feed Do not create useless database transaction when building has_one association. 2012-11-10 15:30:20 +02:00
Yves Senn
710e371081 :counter_cache option for to support custom named counter caches. Closes #7993 2012-11-04 17:09:25 +01:00
Rafael Mendonça França
7042fe2f84 Deprecate passing a string as third argument of add_index
This was there due historical reasons since
7dc45818dc43c163700efc9896a0f3feafa31138 to give the user the
possibility to create unique indexes passing "UNIQUE" as the third
argument
2012-11-02 20:03:26 -02:00
Rafael Mendonça França
8fc52706c3 Raise an ArgumentError when passing an invalid option to add_index
Closes #8104
2012-11-02 19:00:58 -02:00
Alexis Bernard
a58cafeb3a Fix find_in_batches against string IDs when start option is not specified. 2012-10-31 15:39:24 +01:00
Nikita Afanasenko
e7e59a75aa Fix attributes_before_type_cast for serialised attributes.
Public method `attributes_before_type_cast` used to return internal AR structure (ActiveRecord::AttributeMethods::Serialization::Attribute), patch fixes this. Now behaves like `read_attribute_before_type_cast` and returns unserialised values.
2012-10-31 13:16:44 +04:00
kennyj
a7c3c90250 Fix #6951. Use query cache/uncache, when using not only database.yml but also DATABASE_URL. 2012-10-31 10:04:10 +09:00
Juanjo Bazán
300d080ada ActiveRecord::Relation#none! method. 2012-10-28 22:18:45 +01:00
Henrik N
1849665f73 Enable update_column(s) for the primary key attribute.
Didn't work before because it updated the model-in-memory first, so the DB query couldn't find the record.
2012-10-28 21:28:54 +01:00
Yves Senn
e4790a2c5b raise ArgumentError when redefining the primary key column. Closes #6378 2012-10-28 20:40:37 +01:00
Francesco Rodriguez
10f6f90d9d AR::AttributeMethods#[] raises AM::AttributeMissingError for missing attributes.
This fixes the following behaviour:

    class Person < ActiveRecord::Base
      belongs_to :company
    end

    # Before:
    person = Person.select('id').first
    person[:name]       # => nil
    person.name         # => ActiveModel::MissingAttributeError: missing_attribute: name
    person[:company_id] # => nil
    person.company      # => nil

    # After:
    person = Person.select('id').first
    person[:name]       # => ActiveModel::MissingAttributeError: missing_attribute: name
    person.name         # => ActiveModel::MissingAttributeError: missing_attribute: name
    person[:company_id] # => ActiveModel::MissingAttributeError: missing_attribute: company_id
    person.company      # => ActiveModel::MissingAttributeError: missing_attribute: company_id

Fixes #5433.
2012-10-28 14:18:31 -05:00
Victor Costan
5d30e44390 Use the MySQL varbinary type when appropriate in migrations. 2012-10-27 13:41:27 -04:00
Shawn Veader
f96b410bc7 Decode attributes pulled from URI.parse
The RFC indicates that username and passwords may be encoded.
http://tools.ietf.org/html/rfc2396#section-3.2.2

Found this trying to use the mysql://username:password@host:port/db and having special characters in the password which needed to be URI encoded.
2012-10-26 15:43:07 -04:00
Jon Leighton
9e4c41c903 Remove ActiveRecord::Model
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.
2012-10-26 15:51:02 +01:00
Uģis Ozols
1a6b082808 Fix incorrect markdown by removing extra space. 2012-10-24 16:15:48 +03:00
Jeremy Kemper
4ed156336f Revert "Get rid of the ActiveRecord::Model::DeprecationProxy thing."
This reverts commit 83846838252397b3781eed165ca301e05db39293.
2012-10-20 11:35:16 -07:00
Jon Leighton
8384683825 Get rid of the ActiveRecord::Model::DeprecationProxy thing.
I think it's going to be too much pain to try to transition the
:active_record load hook from executing against Base to executing
against Model.

For example, after Model is included in Base, and modules included in
Model will no longer get added to the ancestors of Base.

So plugins which wish to be compatible with both Model and Base should
use the :active_record_model load hook which executes *before* Base gets
loaded.

In general, ActiveRecord::Model is an advanced feature at the moment and
probably most people will continue to inherit from ActiveRecord::Base
for the time being.
2012-10-19 18:12:54 +01:00
Jon Leighton
7efb1feaa3 Rename the partial_updates config to partial_writes
This reflects the fact that it now impact inserts as well as updates.
2012-10-19 16:45:41 +01:00
Jon Leighton
0096f53b25 nodoc the first_or_create methods and document alternatives 2012-10-19 15:56:18 +01:00
Jon Leighton
eb72e62c30 Add Relation#find_or_create_by and friends
This is similar to #first_or_create, but slightly different and a nicer
API. See the CHANGELOG/docs in the commit.

Fixes #7853
2012-10-19 13:18:47 +01:00
Scott Willson
25262bc280 Fix bug with presence validation of associations.
Would incorrectly add duplicated errors when the association was blank. Bug introduced in 1fab518c6a75dac5773654646eb724a59741bc13.
2012-10-16 19:04:40 -07:00
Santiago Pastorino
c432c74cd3 Merge pull request #7371 from csmuc/fix_dup_validation_errors
Dup'ed ActiveRecord objects may not share the errors object
2012-10-16 09:46:44 -07:00
Christian Seiler
fb66521772 Call super to nullify the reference to the original errors object in the dup'ed object (call ActiveModel::Validations#initialize_dup). Closes #7291 2012-10-16 15:09:23 +02:00
Carlos Antonio da Silva
d207a33e00 Move changelog entry from #7439 to the top [ci skip] 2012-10-15 19:19:34 -03:00
Tim Macfarlane
51d6e21c96 ActiveRecord: sum expression returns string '0' for no records, fixed 2012-10-15 22:31:05 +01:00
Arturo Pie
54b3f41741 #7914 Add change of previous commit to CHANGELOG.md 2012-10-13 22:18:50 -04:00
Tima Maslyuchenko
633ea6a826 learn ActiveRecord::QueryMethods#order work with hash arguments 2012-10-12 17:57:24 +03:00
Alexey Muranov
bf4d6a2353 Add CHANGELOG entry for "Fixtures" -> "FixtureSet" 2012-10-07 20:43:18 +02:00
Yves Senn
16e4a53b78 PostgreSQL, quote table names when fetching the primary key. Closes #5920 2012-10-05 08:54:38 +02:00
Rafael Mendonça França
d7d228402e Fix CHANGELOG entry [ci skip] 2012-10-04 10:23:27 -03:00
Francesco Rodriguez
aa202adf6c Count returns 0 without querying if parent is not saved
Patches `CollectionAssociation#count` to return 0 without querying
if the parent record is new. Consider the following code:

    class Account
      has_many :dossiers
    end

    class Dossier
      belongs_to :account
    end

    a = Account.new
    a.dossiers.build

    # before patch
    a.dossiers.count
    # SELECT COUNT(*) FROM "dossiers" WHERE "dossiers"."account_id" IS NULL
    # => 0

    # after
    a.dosiers.count # fires without sql query
    # => 0

Fixes #1856.
2012-10-03 18:02:14 -05:00
lulalala
6e56a03f83 Fix reset_counters() crashing on has_many :through associations.
The counter column name in the intermediate model need to be access
via the through reflection.
2012-10-02 23:49:32 +08:00
Rafael Mendonça França
77fbe1c019 Add missing CHANGELOG entry removed by mistake at 7f3b475 [ci skip] 2012-09-28 14:12:17 -03:00
Jon Leighton
144e8691cb Support for partial inserts.
When inserting new records, only the fields which have been changed
from the defaults will actually be included in the INSERT statement.
The other fields will be populated by the database.

This is more efficient, and also means that it will be safe to
remove database columns without getting subsequent errors in running
app processes (so long as the code in those processes doesn't
contain any references to the removed column).
2012-09-28 18:08:14 +01:00
Sebastian Martinez
bca66a3547 Add #update_columns entry to AR Changelog. 2012-09-28 13:58:07 -03:00