Commit Graph

1326 Commits

Author SHA1 Message Date
Yves Senn
1b356c2e7a add CHANGELOG entry for #19176. [ci skip] 2015-03-04 08:46:12 +01:00
Arthur Neves
4e757746a6 Add changelog for #15549 fix [skip ci] 2015-02-27 16:05:28 -05:00
Sean Griffin
38218929e9 Properly create through records when called with where
Various behaviors needed by associations (such as creating the through
record) are lost when `where` is called, since we stop having a
`CollectionProxy` and start having an `AssociationRelation` which does
not contain this behavior. I *think* we should be able to rm
`AssociationRelation`, but we have tests saying the changes required to
do that would be bad (Without saying why. Of course. >_>)

Fixes #19073.
2015-02-26 12:42:55 -07:00
Ryuta Kamizono
3239b6a98a Add SchemaMigration.create_table support any unicode charsets for MySQL.
MySQL unicode support is not only `utf8mb4`.
Then, The index length problem is not only `utf8mb4`.

http://dev.mysql.com/doc/refman/5.6/en/charset-unicode.html

    SELECT * FROM information_schema.character_sets WHERE maxlen > 3;
    +--------------------+----------------------+------------------+--------+
    | CHARACTER_SET_NAME | DEFAULT_COLLATE_NAME | DESCRIPTION      | MAXLEN |
    +--------------------+----------------------+------------------+--------+
    | utf8mb4            | utf8mb4_general_ci   | UTF-8 Unicode    |      4 |
    | utf16              | utf16_general_ci     | UTF-16 Unicode   |      4 |
    | utf16le            | utf16le_general_ci   | UTF-16LE Unicode |      4 |
    | utf32              | utf32_general_ci     | UTF-32 Unicode   |      4 |
    +--------------------+----------------------+------------------+--------+
2015-02-26 07:57:53 +09:00
Yves Senn
72c1557254 rework disable_referential_integrity for PostgreSQL.
[Toby Ovod-Everett & Andrey Nering & Yves Senn]

Closes #17726.
Closes #10939.

This patch makes three distinct modifications:

1. no longer fall back to disabling user triggers if system triggers can't be disabled
2. warn the user when referential integrity can't be disabled
3. restore aborted transactions when referential integrity can't be disabled

The motivation behind these changes is to make the behavior of Rails
transparent and less error-prone. To require superuser privileges is not optimal
but it's what Rails currently needs. Users who absolutely rely on disabling user triggers
can patch `disable_referential_integrity`.

We should investigate `SET CONSTRAINTS` as a possible solution which does not require
superuser privileges.

/cc @matthewd
2015-02-24 17:32:35 +01:00
Ryuta Kamizono
b8d320c129 Allow :limit option for MySQL bigint primary key support
Example:

    create_table :foos, id: :primary_key, limit: 8 do |t|
    end

    # or

    create_table :foos, id: false do |t|
      t.column :id, limit: 8
    end
2015-02-24 01:53:54 +09:00
Yves Senn
e71f5dad4e some indenting and punctuation fixes. [ci skip] 2015-02-23 16:54:40 +01:00
Josef Šimánek
6576f7354e Require belongs_to by default.
Deprecate `required` option in favor of `optional` for belongs_to.
2015-02-21 23:03:10 +01:00
Rafael Mendonça França
0f2261f2d1 Merge pull request #17139 from mfazekas/fix_becomes_changed_attributes
Always reset changed attributes in becomes
2015-02-20 15:01:28 -02:00
Ryuta Kamizono
a088ee9691 Format the time string according to the precision of the time column
It is also necessary to format a time column like a datetime column.
2015-02-20 10:25:31 +09:00
Ryuta Kamizono
9ef870c042 Allow :precision option for time type columns 2015-02-20 10:24:08 +09:00
Rafael Mendonça França
e28721baf2 Copy edit the suppressor documentation
[ci skip]
2015-02-19 09:08:51 -02:00
Michael Ryan
b9a1e9a4b2 Add ActiveRecord::Base.suppress 2015-02-18 18:30:05 -05:00
Hyonjee Joo
219d71fb90 Add time option to #touch
Fixes #18905. `#touch` now takes time as an option. Setting the option
saves the record with the updated_at/on attributes set to the current time
or the time specified. Updated tests and documentation accordingly.
2015-02-18 10:22:13 -05:00
Sean Griffin
89ba5bb456 Revert "Allow :precision option for time type columns"
This reverts commit 1502caefd30b137fd1a0865be34c5bbf85ba64c1.

The test suite for the mysql adapter broke when this commit was used
with MySQL 5.6.

Conflicts:
	activerecord/CHANGELOG.md
2015-02-17 11:12:52 -07:00
Vipul A M
6598272770 Deprecated passing of start value to find_in_batches and find_each in favour of begin_at value. 2015-02-17 14:10:35 +05:30
Yves Senn
6bd777c851 Merge pull request #18662 from estum/foreign-key-exists
Add `foreign_key_exists?` method.
2015-02-16 09:39:59 +01:00
Yves Senn
57a1d2bf9d remove CHANGELOG entry for Rails 5.0 only feature. #18918
`has_secure_token` hasen't been released yet. No need to track
every change in the CHANGELOG.
2015-02-13 09:16:22 +01:00
Wojciech Wnętrzak
0817bb06f7 Do not overwrite secret token value when already present.
```
user = User.create(token: "custom-secure-token")
user.token # => "custom-secure-token"
```
2015-02-12 22:05:45 +01:00
Eugene Gilburg
d7a7a050e1 Optimize none? and one? relation query methods to use LIMIT and COUNT.
Use SQL COUNT and LIMIT 1 queries for none? and one? methods if no block or limit is given,
instead of loading the entire collection to memory. The any? and many? methods already
follow this behavior.

[Eugene Gilburg & Rafael Mendonça França]
2015-02-12 17:40:59 -02:00
Ryuta Kamizono
1502caefd3 Allow :precision option for time type columns 2015-02-12 07:23:53 +09:00
Sean Griffin
c51f9b61ce Refactor enum to be defined in terms of the attributes API
In addition to cleaning up the implementation, this allows type casting
behavior to be applied consistently everywhere. (#where for example). A
good example of this was the previous need for handling value to key
conversion in the setter, because the number had to be passed to `where`
directly. This is no longer required, since we can just pass the string
along to where. (It's left around for backwards compat)

Fixes #18387
2015-02-11 15:02:36 -07:00
Sean Griffin
5e0b555b45 current_scope shouldn't pollute sibling STI classes
It looks like the only reason `current_scope` was thread local on
`base_class` instead of `self` is to ensure that when we call a named
scope created with a proc on the parent class, it correctly uses the
default scope of the subclass. The reason this wasn't happening was
because the proc captured `self` as the parent class, and we're not
actually defining a real method. Using `instance_exec` fixes the
problem.

Fixes #18806
2015-02-11 13:46:30 -07:00
Yves Senn
a893718c31 fix remove_reference with foreign_key: true on MySQL. #18664.
MySQL rejects to remove an index which is used in a foreign key constraint:

```
ActiveRecord::StatementInvalid: Mysql2::Error: Cannot drop index 'index_copies_on_title_id': needed in a foreign key constraint: ALTER TABLE `copies` DROP `title_id`
```

Removing the constraint before removing the column (and the index) solves this problem.
2015-02-11 11:20:59 +01:00
Rafael Mendonça França
3d91083e14 Merge pull request #18877 from prathamesh-sonpatki/ar-changelog-typos-2
Fixed typos in ActiveRecord CHANGELOG [ci skip]
2015-02-10 17:23:13 -02:00
Prathamesh Sonpatki
cb7190aa9c Fixed typos in ActiveRecord CHANGELOG [ci skip] 2015-02-11 00:43:51 +05:30
Vipul A M
3dc432068b Add an option end_at to find_in_batches
that complements the `start`parameter to specify where to stop batch processing
2015-02-09 01:33:57 +05:30
Ryuta Kamizono
f983912037 Fix rounding problem for PostgreSQL timestamp column
If timestamp column have the precision, it need to format according to
the precision of timestamp column.
2015-02-08 22:22:55 +09:00
Ryuta Kamizono
0bbff5ee16 Respect the database default charset for schema_migrations table.
The charset of `version` column in `schema_migrations` table is depend
on the database default charset and collation rather than the encoding
of the connection.
2015-02-08 11:19:33 +09:00
Rafael Mendonça França
b71e08f8ba Raise ArgumentError when passing nil to Relation#merge
nil or false should not be valid argument to the merge method.

Closes #12264
2015-02-06 17:53:06 -02:00
Rafael Mendonça França
25bbe595f1 Merge pull request #18399 from kommen/unify-structure-file-envvar-names
Use SCHEMA instead of DB_STRUCTURE for specifiying structure file.

Conflicts:
	activerecord/CHANGELOG.md
2015-02-05 18:55:33 -02:00
Sean Griffin
cd0ed12d1a Respect custom primary keys for associations in Relation#where
While we query the proper columns, we go through normal handling for
converting the value to a primitive which assumes it should use the
table's primary key. If the association specifies a different value (and
we know that we're working with an association), we should use the
custom primary key instead.

Fixes #18813.
2015-02-04 08:56:46 -07:00
Miklos Fazekas
5f6370a81b Always reset changed attributes in becomes
When ```becomes``` changes @attributes it should also change
@changed_attributes. Otherwise we'll experience a kind of split head situation
where attributes are coming from ```self```, but changed_attributes is coming
from ```klass.new```. This affects the inheritance_colmn as it's changed by new
for example.

Fixes #16881
2015-02-04 15:42:14 +01:00
Sean Griffin
23bb8d77c6 Correct errors in counter cache updating
The cache name should be converted to a string when given, not compared
as a symbol. This edge case is already adequately covered by our tests,
but was masked by another issue where we were incorrectly updating the
counter cache twice. When paired with a bug where we didn't update the
counter cache because we couldn't find a match with the name, this made
it look like everything was working fine.

Fixes #10865.
2015-02-03 13:28:07 -07:00
Chris Sinjakli
b8e1f20267 Generate consistent names for foreign keys 2015-02-03 01:37:29 +00:00
eileencodes
27aa4dda7d Fix validations on child record when record parent has validate: false
Fixes #17621. This 5 year old (or older) issue causes validations to fire
when a parent record has `validate: false` option and a child record is
saved. It's not the responsibility of the model to validate an
associated object unless the object was created or modified by the
parent.

Clean up tests related to validations

`assert_nothing_raised` is not benefiting us in these tests
Corrected spelling of "respects"
It's better to use `assert_not_operator` over `assert !r.valid`
2015-02-01 16:03:49 -08:00
Aaron Patterson
aa8ade5811 Merge branch 'master' into mdluo-master
* master:
  Move required error message and changelog to Active Record
  Use public Module#include, in favor of https://bugs.ruby-lang.org/issues/8846
  Use Module#include instead of send :include, since now is a public method [ci skip]
  ✂️ warning from controller renderer test

Conflicts:
	activerecord/CHANGELOG.md
2015-02-01 08:42:22 -08:00
Carlos Antonio da Silva
fdeef19833 Move required error message and changelog to Active Record
The new association error belongs to Active Record, not Active Model.
See #18700 for reference.
2015-02-01 10:31:54 -02:00
Mingdong Luo
549d171a90 Merge branch 'master' into pr/18316
Conflicts:
	activerecord/CHANGELOG.md
2015-01-31 19:23:48 -08:00
Yves Senn
afe402dac7 unify CHANGELOG format. [ci skip] 2015-01-31 11:54:00 +01:00
Bogdan Gusiev
e94330fe40 Fixed AR::Relation#group method when argument is a SQL reserved keyword 2015-01-29 17:27:02 +02:00
Matthew Draper
b0b37942d7 Added #or to ActiveRecord::Relation
Post.where('id = 1').or(Post.where('id = 2'))
    # => SELECT * FROM posts WHERE (id = 1) OR (id = 2)

[Matthew Draper & Gael Muller]
2015-01-28 13:35:55 -07:00
Sean Griffin
56a3d5ec91 Don't redefine autosave association callbacks in nested attrs
These callbacks will already have been defined when the association was
built. The check against `reflection.autosave` happens at call time, not
at define time, so simply modifying the reflection is sufficient.

Fixes #18704
2015-01-28 09:53:38 -07:00
Sean Griffin
7c6f3938de Move integer range validation to never raise on assignment
Given that this was originally added to normalize an error that would
have otherwise come from the database (inconsistently), it's more
natural for us to raise in `type_cast_for_database`, rather than
`type_cast_from_user`. This way, things like numericality validators can
handle it instead if the user chooses to do so. It also fixes an issue
where assigning an out of range value would make it impossible to assign
a new value later.

This fixes several vague issues, none of which were ever directly
reported, so I have no issue number to give. Places it was mentioned
which I can remember:

- 9ba21381d7/lib/shoulda/matchers/active_model/allow_value_matcher.rb (L261-L263)
- https://github.com/rails/rails/issues/18653#issuecomment-71197026
2015-01-23 14:30:23 -07:00
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
Dieter Komendera
99e57a8dcc Use SCHEMA instead of DB_STRUCTURE for specifiying structure file.
`rake test:load_structure` already uses `SCHEMA` and there's no
need to maintain two different env vars.
2015-01-08 10:02:58 +01: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
Sammy Larbi
c840b18ac3 Fix n+1 query problem when eager loading nil associations (fixes #18312) 2015-01-03 13:31:54 -06: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
Arthur Neves
5acd24bbea
Ensures that primary_key method will return nil when multi-pk
When table has a composite primary key, the `primary_key` method for
sqlite3 and postgresql was only returning the first field of the key.

Ensures that it will return nil instead, as AR dont support composite pks.
2014-12-30 12:36:37 -05:00
Yves Senn
2b12288139 AR specific length validator to respect marked_for_destruction.
Closes #7247.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/models/owner.rb
2014-12-30 10:25:58 +01:00
Sean Griffin
fb14aa0c1b Ensure first! and friends work on loaded associations
Fixes #18237
2014-12-29 11:56:37 -07:00
Takashi Kokubun
068160b444 eager_load preserves readonly flag for associations 2014-12-30 01:07:33 +09:00
Ryuta Kamizono
3628025c0d Improve a dump of the primary key support.
If it is not a default primary key, correctly dump the type and options.
2014-12-29 09:19:21 +09:00
Yves Senn
ed7196645c docs, cleanup Active Record CHANGELOG. [ci skip] 2014-12-28 22:25:42 +01:00
Dan Olson
e780e2fda3 Provide :touch option to save() to accommodate saving without updating timestamps. [#18202] 2014-12-27 22:22:37 -06:00
Sean Griffin
307ec3db0f Provide a better error message for unsupported classes in serialize
We only support classes which provide a no-args constructor to use as a
default value. We can provide a more helpful error message if we catch
this when `serialize` is called, rather than letting it error when you
try to assign the attribute.

Fixes #18224
2014-12-27 19:49:09 -07:00
Ryuta Kamizono
a327a9dc58 Add bigint primary key support for MySQL.
Example:

    create_table :foos, id: :bigint do |t|
    end
2014-12-28 05:35:03 +09:00
Ryuta Kamizono
3cbfba6881 Support for any type primary key. 2014-12-28 05:35:03 +09:00
Ryuta Kamizono
9b3e7b396e Dump the default nil for PostgreSQL UUID primary key. 2014-12-26 17:54:08 +09:00
Sean Griffin
e550bbf8fc Changelog for 99a6f9e60ea55924b44f894a16f8de0162cf2702
Here you go, @senny. 😁
2014-12-23 07:21:43 -07:00
Sean Griffin
a054269ff8 Merge Pull Request #18157
Conflicts:
	activerecord/CHANGELOG.md
2014-12-23 07:13:54 -07:00
Yves Senn
ad783136d7 Replace deprecated #load_schema with #load_schema_for. 2014-12-23 12:07:15 +01:00
Yves Senn
0587070391 cleanup CHANGELOGs. [ci skip] 2014-12-23 08:56:17 +01:00
Daniel Fox
2859341c38 Fixing numeric attrs when set to same negative value
This bug occurs when an attribute of an ActiveRecord model is an
ActiveRecord::Type::Integer type or a ActiveRecord::Type::Decimal type (or any
other type that includes the ActiveRecord::Type::Numeric module. When the value
of the attribute is negative and is set to the same negative value, it is marked
as changed.

Take the following example of a Person model with the integer attribute age:

    class Person < ActiveRecord::Base
      # age          :integer(4)
    end

The following will produce the error:

    person = Person.new(age: -1)
    person.age = -1
    person.changes
    => { "age" => [-1, -1] }
    person.age_changed?
    => true

The problematic line is here:

    module ActiveRecord
      module Type
        module Numeric
          ...

          def non_numeric_string?(value)
            # 'wibble'.to_i will give zero, we want to make sure
            # that we aren't marking int zero to string zero as
            # changed.
            value.to_s !~ /\A\d+\.?\d*\z/
          end
        end
      end
    end

The regex match doesn't accept numbers with a leading '-'.
2014-12-23 00:19:14 -06:00
Grey Baker
d318badc26 Don't raise on out-of-range datetimes passed by a user 2014-12-23 02:35:12 +00:00
Prathamesh Sonpatki
5ef713c53c Allow ActiveRecord::Relation#update to run on result of a relation with callbacks and validations
- Right now, there is no method to update multiple records with
  validations and callbacks.
- Changed the behavior of existing `update` method so that when `id`
  attribute is not given and the method is called on an `Relation`
  object, it will execute update for every record of the `Relation` and
  will run validations and callbacks for every record.
- Added test case for validating that the callbacks run when `update` is
  called on a `Relation`.
- Changed test_create_columns_not_equal_attributes test from
  persistence_test to include author_name column on topics table as it
  it used in before_update callback.
- This change introduces performance issues when a large number of
  records are to be updated because it runs UPDATE query for every
  record of the result. The `update_all` method can be used in that case
  if callbacks are not required because it will only run single UPDATE
  for all the records.
2014-12-20 15:33:18 +05:30
Yves Senn
be1e0241f0 force: :cascade to recreate tables referenced by foreign-keys. 2014-12-19 11:27:04 +01:00
Yves Senn
36ce0c2c82 db:structure:load and db:schema:load no longer purge the database.
Closes #17945

`db:test:prepare` still purges the database to always keep the test
database in a consistent state.

This patch introduces new problems with `db:schema:load`. Prior
to the introduction of foreign-keys, we could run this file against
a non-empty database. Since every `create_table` containted the
`force: true` option, this would recreate tables when loading the schema.

However with foreign-keys in place, `force: true` wont work anymore and
the task will crash.

/cc @schneems
2014-12-18 10:08:17 +01:00
Ryuta Kamizono
b61a93b44e Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger. 2014-12-12 00:35:48 +09:00
Ulisses Almeida + Kassio Borges
075c81feec Add foreign_type option for polymorphic has_one and has_many.
To be possible to use a custom column name to save/read the polymorphic
associated type in a has_many or has_one polymorphic association, now users
can use the option :foreign_type to inform in what column the associated object
type will be saved.
2014-12-08 18:13:15 -02:00
Melanie Gilman
be6897e34d Remove deprecated behavior allowing nested arrays as query values 2014-12-04 16:13:00 -05:00
Melanie Gilman
c0609dd0f0 Deprecate Class handler in PredicateBuilder
Users should pass strings to queries instead of classes
2014-12-04 15:06:21 -05:00
Yves Senn
94e8fc0619 Active Record changelog needs to keep pointing at 4-2-stable. #17651
[ci skp]
2014-12-03 19:29:26 +01:00
Yves Senn
3f78a57fd6 docs, add new changelog entries at the top 😓 [ci skip] #17651 2014-12-03 19:27:13 +01:00
noam
b64fb3020b Failure to rollback t.timestamps when within a change_table migration
When running the following migration:

    change_table(:table_name) { |t| t/timestamps }

The following error was produced:

    wrong number of arguments (2 for 1) .... /connection_adapters/abstract/schema_statements.rb:851:in `remove_timestamps'

This is due to `arguments` containing an empty hash as its second
argument.
2014-12-03 11:35:40 -05:00
Yves Senn
9e4ed2f996 no need to pass native_database_types around 2014-12-02 13:36:46 +01:00
Rafael Mendonça França
f25ad07f5a Start Rails 5 development 🎉
We will support only Ruby >= 2.1.

But right now we don't accept pull requests with syntax changes to drop
support to Ruby 1.9.
2014-11-28 15:00:06 -02:00
Jon Atack
35c5f47d97 Active Record change log pass [skip ci] 2014-11-26 12:23:00 +01:00
Yves Senn
5c4495538b bring back db:test:prepare.
This reverts deprecations added in #13528.
The task is brought back for two reasons:
  1. Give plugins a way to hook into the test database initialization process
  2. Give the user a way to force a test database synchronization

While `test:prepare` is still a dependency of every test task, `db:test:prepare`
no longer hooks into it. This means that `test:prepare` runs before the schema
is synchronized. Plugins, which insert data can now hook into `db:test:prepare`.

The automatic schema maintenance can't detect when a migration is rolled-back,
modified and reapplied. In this case the user has to fall back to `db:test:prepare`
to force the synchronization to happen.
2014-11-25 18:17:01 +01:00
Santiago Pastorino
e3acd74fa8 Merge pull request #17678 from siddharth28/includes_with_scope_with_joins
Fix includes on association with a scope
2014-11-24 14:55:34 -02:00
Arthur Neves
5dc598814e
Add changelog entry for .reflections API change
`.reflections` public API changed to return a String instead of a Symbol
as keys.

see commit 1f31488499111fdfce79d8dc1cc8fb008f7cdb25 and 6259e4e2dcca9a79f22f96658c33efe81936bc0d

[fixes #16928]
[fixes #17610]
2014-11-22 20:29:29 -05:00
Sean Griffin
dcc143cd70 Rename the primary key index when renaming a table in pg
Also checked to make sure this does not affect foreign key constraints.
(It doesn't).

Fixes #12856
Closes #14088
2014-11-22 13:16:14 -07:00
siddharth@vinsol.com
91e3dab804 Fix includes on association with a scope containing joins along with conditions
on the joined assoiciation
2014-11-21 21:13:11 +05:30
Yves Senn
f766abd4cf make it possible to access fixtures excluded by a default_scope.
Prior to this patch you'd end up with an error like:

```
ActiveRecord::RecordNotFound: Couldn't find <Model> with 'id'=<id> [WHERE (<default_scope condition>)]
```
2014-11-21 14:57:25 +01:00
Yves Senn
e80e16b4ff Merge pull request #17580 from ccutrer/change_table_name
add a Table#name accessor like TableDefinition#name
2014-11-11 15:29:58 +01:00
Cody Cutrer
76e7305ea1 add a Table#name accessor like TableDefinition#name 2014-11-10 14:56:21 -07:00
Rafael Mendonça França
2574212423 Merge pull request #11694 from Empact/association-bind-values-not-updated-on-save
Fix that a collection proxy could be cached before the save of the owner, resulting in an invalid proxy lacking the owner’s id

Conflicts:
	activerecord/CHANGELOG.md
2014-11-10 15:46:02 -02:00
Yves Senn
888ea6bf44 Merge pull request #17541 from OpenSourceProjects/meaninful_message
Print out a meaningful error when ActiveRecord::ReadOnlyRecord is raised
2014-11-07 09:03:25 +01:00
Yves Senn
8e9cb9787b Merge pull request #17360 from bronzle/includes_and_unscoped
copy reflection_scopes’s unscoped value when building scope for preloading
2014-11-05 15:13:23 +01:00
Ted O'Meara
9007b789e1 Added SchemaDumper support for tables with jsonb columns. 2014-11-04 12:55:07 -05:00
Sean Griffin
d5902c9e7e Revert deprecation of sanitize_sql_hash_for_assignment
This method is still used by `update_all`
2014-11-02 13:52:34 -07:00
Sean Griffin
eb921000a1 Deprecate sanitize_sql_hash_ methods on ActiveRecord
These appear to be implementation relics of times past. They duplicate
the logic in Relation, and are no longer used internally.
2014-11-02 13:34:52 -07:00
Sean Griffin
10f75af933 Use bind values for joined tables in where statements
In practical terms, this allows serialized columns and tz aware columns
to be used in wheres that go through joins, where they previously would
not behave correctly. Internally, this removes 1/3 of the cases where we
rely on Arel to perform type casting for us.

There were two non-obvious changes required for this. `update_all` on
relation was merging its bind values with arel's in the wrong order.
Additionally, through associations were assuming there would be no bind
parameters in the preloader (presumably because the where would always
be part of a join)

[Melanie Gilman & Sean Griffin]
2014-11-01 15:39:51 -06:00
Yves Senn
82ce157844 fix MySQL enum type lookup with values matching another type. Closes #17402.
The MySQLAdapter type map used the lowest priority for enum types.
This was the result of a recent refactoring and lead to some broken lookups
for enums with values that match other types. Like `8bit`.

This patch restores the priority to what we had before the refactoring.

/cc @sgrif
2014-10-29 09:43:56 +01:00
Yves Senn
d616fec811 Merge pull request #17374 from maurogeorge/scope-exception
Raises ArgumentError when try to define a scope without a callable
2014-10-27 09:49:50 +01:00
Yves Senn
ffed7acd8e Merge pull request #14143 from derekprior/dp-compound-index-ordering
Use type column first in multi-column indexes

Conflicts:
	activerecord/CHANGELOG.md
2014-10-27 09:14:27 +01:00
Derek Prior
9cdd0a1fdf
Use type column first in multi-column indexes
`add_reference` can very helpfully add a multi-column index when you use
it to add a polymorphic reference. However, the first column in the
index is the `id` column, which is less than ideal.

The [PostgreSQL docs][1] say:
> A multicolumn B-tree index can be used with query conditions that
> involve any subset of the index's columns, but the index is most
> efficient when there are constraints on the leading (leftmost)
> columns.

The [MySQL docs][2] say:
> MySQL can use multiple-column indexes for queries that test all the
> columns in the index, or queries that test just the first column, the
> first two columns, the first three columns, and so on. If you specify
> the columns in the right order in the index definition, a single
> composite index can speed up several kinds of queries on the same
> table.

In a polymorphic relationship, the type column is much more likely to be
useful as the first column in an index than the id column. That is, I'm
more likely to query on type without an id than I am to query on id
without a type.

[1]: http://www.postgresql.org/docs/9.3/static/indexes-multicolumn.html
[2]: http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html
2014-10-24 16:34:30 -04:00
Dan Olson
032605f08b Fix Relation.rewhere to work with Range values 2014-10-20 05:38:34 -05:00
Yves Senn
a702d5aad5 Merge pull request #17019 from yuki24/add-class-name-to-unknown-attr-error
Message on AR::UnknownAttributeError should include the class name of a record
2014-10-20 08:49:27 +02:00
Yuki Nishijima
df08a45a77 AR::UnknownAttributeError should include the class name of a record
This would be helpful if 2 models have an attribute that has a similar
name to the other. e.g:

before:

    User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"])
    # => ActiveRecord::UnknownAttributeError: unknown attribute: name

after:

    User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"])
    # => ActiveRecord::UnknownAttributeError: unknown attribute on User: name
2014-10-20 08:45:37 +02:00
Yuki Nishijima
074880c4ea AR::UnknownAttributeError should include the class name of a record
This would be helpful if 2 models have an attribute that has a similar
name to the other. e.g:

before:

    User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"])
    # => ActiveRecord::UnknownAttributeError: unknown attribute: name

after:

    User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"])
    # => ActiveRecord::UnknownAttributeError: unknown attribute on User: name
2014-10-15 17:32:35 -07:00
Agis-
719d52db42 Autosave callbacks shouldn't be after_save
068f092ced8483e557725542dd919ab7c516e567 registered autosave callbacks
as `after_save` callbacks. This caused the regression described in #17209.

Autosave callbacks should be registered as `after_update` and
`after_create` callbacks, just like before.

This is a partial revert of 068f092ced8483e557725542dd919ab7c516e567.

Fixes #17209.
2014-10-13 17:50:32 +03:00
Yves Senn
fda7bc36e2 unify PG spelling in CHANGELOGs. [ci skip] 2014-10-06 10:30:21 +02:00
Ben Woosley
cc405496ce Fix that a collection proxy could be cached before the save of the owner, resulting in an invalid proxy lacking the owner’s id.
Absent this fix calls like: owner.association.update_all to behave unexpectedly because they try to act on association objects where
owner_id is null.

more evidence here: https://gist.github.com/Empact/5865555
```
Active Record 3.2.13
-- create_table(:firms, {:force=>true})
   -> 0.1371s
-- create_table(:clients, {:force=>true})
   -> 0.0005s
1 clients. 1 expected.
1 clients updated. 1 expected.
```

```
Active Record 4.0.0
-- create_table(:firms, {:force=>true})
   -> 0.1606s
-- create_table(:clients, {:force=>true})
   -> 0.0004s
1 clients. 1 expected.
0 clients updated. 1 expected.
```
2014-10-03 03:04:16 -07:00
Prathamesh Sonpatki
739eee67fc Fix typo in AR changelog
- middlware -> middleware
2014-09-27 16:18:29 +05:30
Simon Eskildsen
cb598c2115 ar/connection_pool: honor overriden rack.test in middleware
Honoring an overidden `rack.test` allows testing closed connection between
multiple requests. This is useful if you're working on database resiliency, to
ensure the connection is in the expected state from one request to another on
the same worker.
2014-09-23 02:33:18 +00:00
Prathamesh Sonpatki
a1e38ef33e Update changelog with tenderlove's entry
[ci skip]
2014-09-23 09:21:17 +09:00
Aaron Patterson
9a4e183fe9 add a truncate method to the connection
it doesn't work on SQLite3 since it doesn't support truncate, but that's
OK.  If you call truncate on the connection, you're now bound to that
database (same as if you use hstore or any other db specific feature).
2014-09-22 14:57:19 -07:00
Yves Senn
b537f14f3d Merge pull request #16987 from jonatack/patch-8
ActiveRecord CHANGELOG improvements [skip ci]
2014-09-20 18:46:44 +02:00
Jon Atack
1415fdd5a3 ActiveRecord CHANGELOG improvements [skip ci] 2014-09-20 15:21:23 +02:00
lethalbrains
48ee6b8708 [ci skip] ActionRecord CHANGELOG docs fixes 2014-09-19 17:17:50 +05:30
Rafael Mendonça França
afa4780572 Merge pull request #16875 from alan/dont_autosave_has_one_through_record
Don't autosave unchanged has_one through records

Conflicts:
	activerecord/CHANGELOG.md
2014-09-17 16:26:35 -03:00
Yves Senn
38b5e191f6 do not dump foreign keys for ignored tables. 2014-09-17 11:43:42 +02:00
Yves Senn
6d8221323f unify wording in Active Record CHANGELOG. [ci skip] 2014-09-17 11:25:30 +02:00
Yves Senn
c1ab07cd91 pg, correctly dump foreign keys targeting tables in a different schema.
Closes #16907.

[Matthew Draper & Yves Senn]
2014-09-17 11:13:10 +02:00
Alan Kennedy
93717f39b7 Don't autosave unchanged has_one through records 2014-09-15 15:34:39 +01:00
Matthew Draper
1d4d15a48d Merge pull request #13656 from chanks/rollback_transactions_in_killed_threads
Data corruption risk: Roll back open transactions when the running thread is killed.
2014-09-14 07:32:53 +09:30
Yves Senn
16868b53f9 A NullRelation should represent nothing. Closes #15176.
[Matthew Draper & Yves Senn]

Closes #16860. (pull request to discuss the implementation)
2014-09-11 08:04:48 +02:00
Jeremy Kemper
2c76793f08 Include default column limits in schema.rb
Allows :limit defaults to be changed without pulling the rug out from
under old migrations that omitted :limit because it matched the default
at the time.
2014-09-10 15:35:12 -07:00
Jeremy Kemper
da74eeb294 MySQL: schema.rb now includes TEXT and BLOB column limits. 2014-09-10 15:35:12 -07:00
Jeremy Kemper
39303c0221 MySQL: correct LONGTEXT and LONGBLOB limits from 2GB to their true 4GB 2014-09-10 15:35:12 -07:00
Yves Senn
d2069d60ae Merge pull request #14056 from girishso/14041
SQLite3Adapter now checks for views in table_exists? fixes: 14041

Conflicts:
	activerecord/CHANGELOG.md
2014-09-09 11:35:17 +02:00
Yves Senn
ae9412e857 introduce connection.supports_views? and basic view tests.
`AbstractAdapter#supports_views?` defaults to `false` so we have to turn it on
in adapter subclasses. Currently the flag only controls test execution.

/cc @yahonda
2014-09-09 11:26:30 +02:00
Yves Senn
d5580b91b6 Allow included modules to override association methods.
Closes #16684.

This is achieved by always generating `GeneratedAssociationMethods` when
`ActiveRecord::Base` is subclassed. When some of the included modules
of `ActiveRecord::Base` were reordered this behavior was broken as
`Core#initialize_generated_modules` was no longer called. Meaning that
the module was generated on first access.
2014-09-09 10:00:30 +02:00
Rafael Mendonça França
d12b9b2897 Remove CHANGELOG entry [ci skip] 2014-09-05 18:48:22 -03:00
Akshay Vishnoi
8f87a54199 cover all cases of For not --> Do not, related to #16804 2014-09-05 09:21:30 +05:30
Yves Senn
ded17a498a schema loading rake tasks maintain database connection for current env.
[Joshua Cody & Yves Senn]

Closes #16757.

Prior to this patch schema loading rake tasks had the potential to leak a
connection to a different database. This had side-effects when rake tasks
operating on the current connection (like `db:seed`) were chained.
2014-09-03 18:02:44 +02:00
Jeremy Kemper
d5ad203745 MySQL: set connection collation along with the charset
Sets the connection collation to the database collation configured
in database.yml. Otherwise, `SET NAMES utf8mb4` will use the default
collation for that charset (utf8mb4_general_ci) when you may have chosen
a different collation, like utf8mb4_unicode_ci.

This only applies to literal string comparisons, not column values, so
it is unlikely to affect you.
2014-08-30 10:07:07 -07:00
Yves Senn
20e7f08ecc minor changelog formatting changes. 2014-08-27 12:09:21 +02:00
Yves Senn
3fe54b3a05 pg, default_sequence_name needs to return a string.
This is a reacon to d6c1205584 (commitcomment-7502487)
This backwards incompatibility was introduced with d6c12055 to fix #7516.
However both `connection.default_sequence_name` and `model.sequence_name` are public API.
The PostgreSQL adapter should honor the interface and return strings.

/cc @matthewd @chancancode
2014-08-25 12:01:10 +02:00
Godfrey Chan
4287f6d456 CHANGELOG & improvements to #16649
* Require either FIRST or LAST qualifier for "NULLS ..."
* Require whitespace before "NULLS ..."
2014-08-23 23:54:22 -07:00
Agis-
431f8e0119 Only merge scopes with zero arity in has_many through
with dynamic conditions.

Fixes #16128

This bug was introduced in c35e438620
so it's present from 4.1.2-rc1 and after.

c35e438620
merges any relation scopes passed as proc objects to the relation,
but does *not* take into account the arity of the lambda.

To reproduce: https://gist.github.com/Agis-/5f1f0d664d2cd08dfb9b
2014-08-20 08:25:58 +03:00
yuuji.yaginuma
7a796b4c0a [ci skip] config.active_record.errors_in_transactional_callbacks -> config.active_record.raise_in_transactional_callbacks 2014-08-19 15:58:56 +09:00
Kassio Borges
7aeca5066a Fixes the Relation#exists? to work with polymorphic associations.
Fixes #15821.
2014-08-18 18:20:40 -03:00
Arthur Neves
b11b1e868a
Add option to stop swallowing errors on callbacks.
Currently, Active Record will rescue any errors raised within
after_rollback/after_create callbacks and print them to the
logs. Next versions of rails will not rescue those errors anymore,
and just bubble them up, as the other callbacks.

This adds a opt-in flag to enable that behaviour, of not rescuing
the errors.
    Example:
      # For not swallow errors in after_commit/after_rollback
      config.active_record.errors_in_transactional_callbacks = true

[fixes #13460]
2014-08-18 14:47:48 -04:00
Godfrey Chan
a5e2d2ef85 Merge pull request #16458 from chancancode/ar_fix_reserved_inheritance
Fixed issue w/custom accessors + reserved name + inheritance

Conflicts:
	activerecord/CHANGELOG.md
2014-08-17 11:59:46 -07:00
Godfrey Chan
008f3da383 Don't expose these new APIs yet (added in 877ea78 / #16189)
WARNING: don't use them! They might change or go away between future beta/RC/
patch releases!

Also added a CHANGELOG entry for this.
2014-08-16 23:09:10 -07:00
Arthur Neves
2e90fe736d
Fix regression on after_commit in nested transactions.
after_commit should not run in nested transactions, however they should
run once the outermost transaction gets committed. This patch fixes the
problem copying the records from the Savepoint to its parent. So the
RealTransaction will have all records that needs to run callbacks on it.

[fixes #16425]
2014-08-15 16:04:39 -04:00
Yves Senn
76b587880e Merge pull request #8813 from greyblake/dont_write_timestamps_if_they_are_not_attributes
Write timestamps only if there are timestamps columns

Conflicts:
	activerecord/CHANGELOG.md
2014-08-14 12:11:44 +02:00
Yves Senn
ecfce561e4 index_exists? with :name checks specified columns.
[Yves Senn & Matthew Draper]

The column check was embodied in the defaul index name.
If the :name option was used, the specified columns were not verified at all.

Given:

```
assert connection.index_exists?(table_name, :foo_id, :name => :index_testings_on_yo_momma)
```

That index could have been defined on any field, not necessarily on `:foo_id`.
2014-08-13 11:44:58 +02:00
lsylvester
0f99aa615e update error message to reflect that the record could have been destroyed 2014-08-11 20:56:21 +10:00
Godfrey Chan
2638d5c724 Fixed issue w/custom accessors + reserved name + inheritance
Fixed an issue where custom accessor methods (such as those generated by
`enum`) with the same name as a global method are incorrectly overridden
when subclassing.

This was partially fixed in 4155431 then broken again by e5f15a8.

Fixes #16288.
2014-08-11 00:00:23 -07:00
Rafael Mendonça França
e6e81f856e Define id_was to get the previous value of the primary key
Currently when we call id_was and we have a custom primary key name
Active Record will return the current value of the primary key. This
make impossible to correctly do an update operation if you change the
id.

Fixes #16413
2014-08-06 23:46:31 -03:00
Yves Senn
f15cef67f7 schema rake tasks are specific about the configuration to act on.
The rake tasks and the `DatabaseTakss` adapter classes used to
assume a configuration at some places. This forced the rake
tasks to establish a specific connection before calling into
`load_schema`.

After #15394 this started to cause issues because it could
`purge` the wrong database before loading the schema.
2014-08-06 08:25:18 +02:00
Yves Senn
53dba73dc1 Revert "Revert "Merge pull request #15394 from morgoth/fix-automatic-maintaining-test-schema-for-sql-format""
This reverts commit 5c87b5c5248154cf8aa76cce9a24a88769de022d.
2014-08-06 08:25:18 +02:00
Yves Senn
b2e88043b5 Merge pull request #16333 from joker1007/fix_decimal_cast_from_float_with_large_precision
Fix type casting to Decimal from Float with large precision

Conflicts:
	activerecord/CHANGELOG.md
2014-08-04 13:09:13 +02:00
eileencodes
01c80a12d4 Deprecate source_macro
`source_macro` is no longer used in any ActiveRecord code. I've
chosen to deprecate it because it was not marked as nodoc and may
be in use outside of rails source.
2014-08-02 10:01:06 -04:00
joker1007
1d6a87779c Fix type casting to Decimal from Float with ...
When I defines large precision column at RDBMS,
I assigns float value, raise ArgumentError (precision too large).
2014-08-01 00:29:20 +09:00
Kenn Ejima
2ee8419813 No verbose backtrace by db:drop when database does not exist. 2014-07-27 14:34:01 -07:00
Yves Senn
1ec601b4e3 Merge pull request #16220 from pcreux/postgresql-jsonb-support
Add support for Postgresql JSONB
2014-07-25 11:16:30 +02:00
Philippe Creux
99b82fdf03 Add support for Postgresql JSONB
[Philippe Creux, Chris Teague]
2014-07-24 10:39:39 -07:00
Yves Senn
091b246bb0 fix, mysql db:purge respects Rails.env.
Previously this method always established a connection to the test database.
This resulted in buggy behavior when combined with other tasks like
`bin/rake db:schema:load`.

This was one of the reasons why #15394 (22e9a91189af2c4e6217a888e77f22a23d3247d1)
was reverted:

> I’ve replicated it on a new app by the following commands: 1) rails
  generate model post:title, 2) rake db:migrate, 3) rake
  db:schema:load, 4) rails runner ‘puts Post.first’. The last command
  goes boom. Problem is that rake db:schema:load wipes the database,
  and then doesn’t actually restore it. This is all on MySQL. There’s
  no problem with SQLite.

  -- DHH

22e9a91189 (commitcomment-6834245)
2014-07-24 16:42:34 +02:00