Commit Graph

1130 Commits

Author SHA1 Message Date
Sean Griffin
96e504ec8a Errors raised in type_cast_for_database no longer raise on assignment
Fixes #18580.
2015-01-23 12:50:01 -07:00
Sean Griffin
b9d668f8cb Don't remove join dependencies in Relation#exists?
Fixes #18632
2015-01-23 12:05:14 -07:00
Sean Griffin
e8460f8bbe Don't error when invalid json is assigned to a JSON column
Keeping with our behavior elsewhere in the system, invalid input is
assumed to be `nil`.

Fixes #18629.
2015-01-21 11:48:32 -07:00
Sean Griffin
be9b68038e Introduce ActiveRecord::Base#accessed_fields
This method can be used to see all of the fields on a model which have
been read. This can be useful during development mode to quickly find
out which fields need to be selected. For performance critical pages, if
you are not using all of the fields of a database, an easy performance
win is only selecting the fields which you need. By calling this method
at the end of a controller action, it's easy to determine which fields
need to be selected.

While writing this, I also noticed a place for an easy performance win
internally which I had been wanting to introduce. You cannot mutate a
field which you have not read. Therefore, we can skip the calculation of
in place changes if we have never read from the field. This can
significantly speed up methods like `#changed?` if any of the fields
have an expensive mutable type (like `serialize`)

```
Calculating -------------------------------------
 #changed? with serialized column (before)
                       391.000  i/100ms
 #changed? with serialized column (after)
                         1.514k i/100ms
-------------------------------------------------
 #changed? with serialized column (before)
                          4.243k (± 3.7%) i/s -     21.505k
 #changed? with serialized column (after)
                         16.789k (± 3.2%) i/s -     84.784k
```
2015-01-20 14:42:15 -07:00
Jeremy Kemper
b477ad54e5 Merge pull request #18458 from brainopia/fix_after_commit_for_fixtures
Support after_commit callbacks in transactional fixtures
2015-01-20 09:53:15 -07:00
Yves Senn
6b2be718f6 Merge pull request #18597 from kamipo/add-if-exists-to-drop-table
Add an `:if_exists` option to `drop_table`
2015-01-20 13:14:24 +01:00
Stefan Kanev
48e99a4531 Add an :if_exists option to drop_table
If set to `if_exists: true`, it generates a statement like:

    DROP TABLE IF EXISTS posts

This syntax is supported in the popular SQL servers, that is (at least)
SQLite, PostgreSQL, MySQL, Oracle and MS SQL Sever.

Closes #16366.
2015-01-19 13:40:13 +09:00
Prathamesh Sonpatki
3faa223541 Fix wording in AR CHANGELOG about time columns change [ci skip] 2015-01-19 08:57:22 +05:30
Prathamesh Sonpatki
0fcd4cf5c2 Run SQL only if attribute changed for update_attribute method
- This is based on https://github.com/rails/rails/issues/18400 but
   tackling same issue with update_attribute method instead of update method.
2015-01-18 20:00:57 +05:30
Sean Griffin
b74c3565cb Specify correct version in the changelog [ci skip] 2015-01-16 10:40:58 -07:00
brainopia
eb72e349b2 after_commit runs after transactions with non-joinable parents
after_commit callbacks run after committing a transaction whose parent
is not `joinable?`: un-nested transactions, transactions within test
cases, and transactions in `console --sandbox`.
2015-01-16 03:50:29 +03:00
Sean Griffin
5cd3bbbb83 Time columns should support time zone aware attributes
The types that are affected by `time_zone_aware_attributes` (which is on
by default) have been made configurable, in case this is a breaking
change for existing applications.
2015-01-15 08:04:43 -07:00
Sean Griffin
7a09fc55c0 Stop special casing null binary data in logging
There's very little value in logging "<NULL binary data>" instead of
just "nil". I'd like to remove the column from the equation entirely,
and this case is preventing us from doing so.
2015-01-10 12:26:51 -07:00
Sean Griffin
4d5e660789 Don't attempt to save dirty attributes which are not persistable
This sets a precident for how we handle `attribute` calls, which aren't
backed by a database column. We should not take this as a conscious
decision on how to handle them, and this can change when we make
`attribute` public if we have better ideas in the future.

As the composed attributes API gets fleshed out, I expect the
`persistable_attributes` method to change to
`@attributes.select(&:persistable).keys`, or some more performant
variant there-of. This can probably go away completely once we fully
move dirty checking into the attribute objects once it gets moved up to
Active Model.

Fixes #18407
2015-01-10 12:07:46 -07:00
Yves Senn
a7621d7d53 formatting pass over CHANGELOGs. [ci skip] 2015-01-10 12:17:57 +01:00
Carlos Antonio da Silva
f4fbc03010 Remove support for the protected attributes gem
Related to #10690.
2015-01-09 22:42:29 -02:00
Prathamesh Sonpatki
0e3eca8a93 Fixed typos and wording in ActiveRecord CHANGELOG [ci skip] 2015-01-06 18:39:58 +05:30
Yves Senn
dd54b518ce Merge pull request #18358 from prathamesh-sonpatki/add-test-for-non-string-labeled-fixtures
Fix lookup of fixtures with non-string(like Fixnum) label
2015-01-06 13:31:50 +01:00
Prathamesh Sonpatki
8da936a5d3 Fix lookup of fixtures with non-string label
- Fixtures with non-string labels such as integers should be accessed
   using integer label as key. For eg. pirates(1) or pirates(42).
 - But this results in NotFound error because the label is converted into string before
   looking up into the fixtures hash.
 - After this commit, the label is converted into string only if its a
   symbol.
 - This issue was fount out while adding a test case for
   https://github.com/rails/rails/commit/7b910917.
2015-01-06 17:15:39 +05:30
Carlos Antonio da Silva
e50064c130 Fix typo in changelog [ci skip] 2015-01-05 08:49:02 -02:00
Yves Senn
4ed97979d1 remove deprecated support to preload instance-dependent associaitons.
Addresses ed56e596a0 (commitcomment-9145960)
2015-01-05 11:44:14 +01:00
Yves Senn
a076256d63 remove deprecated support for PG ranges with exclusive lower bounds.
addresses 91949e48cf (commitcomment-9144563)
2015-01-05 11:09:29 +01:00
Yves Senn
3ae9818143 remove deprecation warning when modifying a Relation with cached arel.
This adresses 1b7aa62b18 (commitcomment-9147803)
2015-01-05 10:08:56 +01:00
Yves Senn
65520c29f7 add punctuation. [ci skip] 2015-01-05 09:16:40 +01:00
robertomiranda
5a58ba3366 Add has_secure_token to Active Record
Update SecureToken Docs

Add Changelog entry for has_secure_token [ci skip]
2015-01-04 11:31:37 -05:00
Rafael Mendonça França
a502703c3d Change the behavior of boolean columns to be closer to Ruby's semantics.
Before this change we had a small set of "truthy", and all others
are "falsy".

Now, we have a small set of "falsy" values and all others are
"truthy" matching Ruby's semantics.
2015-01-04 11:58:44 -03:00
Rafael Mendonça França
07d3d40234 Change transaction callbacks to not swallowing errors.
Before this change any error raised inside a transaction callback
are rescued and printed in the logs.

Now these errors are not rescue anymore and just bubble up,
as the other callbacks.
2015-01-04 11:58:44 -03:00
Rafael Mendonça França
3a59dd2123 Remove deprecated sanitize_sql_hash_for_conditions 2015-01-04 11:58:44 -03:00
Rafael Mendonça França
ede8c199a8 Remove deprecated Reflection#source_macro 2015-01-04 11:58:44 -03:00
Rafael Mendonça França
9013e28e52 Remove deprecated symbolized_base_class and symbolized_sti_name 2015-01-04 11:58:44 -03:00
Rafael Mendonça França
0fbd1fc888 Remove deprecated ActiveRecord::Base.disable_implicit_join_references= 2015-01-04 11:58:44 -03:00
Rafael Mendonça França
efdc20f36c Remove deprecated access to connection specification using a string acessor.
Now all strings will be handled as a URL.
2015-01-04 11:58:43 -03:00
Rafael Mendonça França
a939506f29 Change the default null value for timestamps to false 2015-01-04 11:58:43 -03:00
Rafael Mendonça França
94c87156fd Return an array of pools from connection_pools 2015-01-04 11:58:43 -03:00
Rafael Mendonça França
634ecdbf1b Return a null column from column_for_attribute when no column exists.
This reverts commit ae96f229f6501d8635811d6b22d75d43cdb880a4.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/attribute_methods.rb
2015-01-04 11:58:43 -03:00
Rafael Mendonça França
82043ab53c Remove deprecated serialized_attributes 2015-01-04 11:58:43 -03:00
Rafael Mendonça França
87c8ce340c Remove deprecated automatic counter caches on has_many :through 2015-01-04 11:58:43 -03:00
claudiob
9c65c539e2 Add config to halt callback chain on return false
This stems from [a comment](rails#17227 (comment)) by @dhh.
In summary:

* New Rails 5.0 apps will not accept `return false` as a way to halt callback chains, and will not display a deprecation warning.
* Existing apps ported to Rails 5.0 will still accept `return false` as a way to halt callback chains, albeit with a deprecation warning.

For this purpose, this commit introduces a Rails configuration option:

```ruby
config.active_support.halt_callback_chains_on_return_false
```

For new Rails 5.0 apps, this option will be set to `false` by a new initializer
`config/initializers/callback_terminator.rb`:

```ruby
Rails.application.config.active_support.halt_callback_chains_on_return_false = false
```

For existing apps ported to Rails 5.0, the initializers above will not exist.
Even running `rake rails:update` will not create this initializer.

Since the default value of `halt_callback_chains_on_return_false` is set to
`true`, these apps will still accept `return true` as a way to halt callback
chains, displaying a deprecation warning.

Developers will be able to switch to the new behavior (and stop the warning)
by manually adding the line above to their `config/application.rb`.

A gist with the suggested release notes to add to Rails 5.0 after this
commit is available at https://gist.github.com/claudiob/614c59409fb7d11f2931
2015-01-02 15:31:56 -08:00
claudiob
bb78af73ab Deprecate false as the way to halt AR callbacks
Before this commit, returning `false` in an ActiveRecord `before_` callback
such as `before_create` would halt the callback chain.

After this commit, the behavior is deprecated: will still work until
the next release of Rails but will also display a deprecation warning.

The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
2015-01-02 15:31:56 -08:00
Rafael Mendonça França
dbe7fe289c Merge pull request #17820 from fw42/restore_query_cache_on_rollback
Clear query cache on rollback
2015-01-02 14:36:23 -03:00
Rafael Mendonça França
ecdae459d2 Merge pull request #15309 from iantropov/issue_12698_build_through
Add setting of FK for throgh associations while building

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/associations/has_many_through_associations_test.rb
2015-01-02 14:29:07 -03:00
Rafael Mendonça França
a908e01ac0 Merge pull request #18228 from kamipo/correctly_dump_primary_key
Improve a dump of the primary key support.

Conflicts:
	activerecord/CHANGELOG.md
2015-01-02 13:37:26 -03:00
Rafael Mendonça França
acb1991910 Merge pull request #18067 from kamipo/format_datetime_string_according_to_precision
Format the datetime string according to the precision of the datetime field.

Conflicts:
	activerecord/CHANGELOG.md
2015-01-02 11:17:55 -03:00
Rafael Mendonça França
bed2bdb17c Merge pull request #15746 from amccloud/auto-inverse_of-in-module
Fixed automatic inverse_of for models nested in module

Conflicts:
	activerecord/CHANGELOG.md
2015-01-02 11:06:17 -03:00
Rafael Mendonça França
9598c9655f Merge pull request #11898 from prathamesh-sonpatki/patch-update
Changed ActiveRecord::Relation#update behavior so that it will work on Relation objects without giving id

Conflicts:
	activerecord/CHANGELOG.md
2015-01-02 10:48:48 -03:00
Ryuta Kamizono
4157f5d172 Format the datetime string according to the precision of the datetime field.
Incompatible to rounding behavior between MySQL 5.6 and earlier.

In 5.5, when you insert `2014-08-17 12:30:00.999999` the fractional part
is ignored. In 5.6, it's rounded to `2014-08-17 12:30:01`:

http://bugs.mysql.com/bug.php?id=68760
2015-01-02 22:30:07 +09:00
Ryuta Kamizono
ae419af666 Allow precision option for MySQL datetimes. 2015-01-02 22:30:07 +09:00
Rafael Mendonça França
70c2777d1c Merge pull request #18080 from korbin/fix_reaping_frequency_configuration
Fix issue with reaping_frequency type.
2015-01-02 01:37:07 -03:00
Rafael Mendonça França
04852b875e Fix error message when trying to create an associated record
This error only happens when the foreign key is missing.

Before this fix the following exception was being raised:

    NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218>

Now the message is:

    ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
2014-12-30 21:02:46 -03:00
Prathamesh Sonpatki
e2fcaf804f Update CHANGELOG entry for #18070 [ci skip]
- Improved wording of CHANGELOG entry for 5acd24bbea.
2014-12-31 00:07:22 +05:30