1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

1177 commits

Author SHA1 Message Date
Ryuta Kamizono
6fa6c739d1 Correctly dump serial and bigserial 2015-03-04 17:52:11 +09:00
Yves Senn
1b356c2e7a add CHANGELOG entry for . [ci skip] 2015-03-04 08:46:12 +01:00
Arthur Neves
4e757746a6 Add changelog for 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 .
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 .
Closes .

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 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 . `#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 1502caefd3.

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 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.
`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 
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 
2015-02-11 13:46:30 -07:00
Yves Senn
a893718c31 fix remove_reference with foreign_key: true on MySQL. .
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 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 
2015-02-06 17:53:06 -02:00
Rafael Mendonça França
25bbe595f1 Merge pull request 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 .
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 
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 .
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 . 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  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 
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 .
2015-01-23 12:50:01 -07:00
Sean Griffin
b9d668f8cb Don't remove join dependencies in Relation#exists?
Fixes 
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 .
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 from brainopia/fix_after_commit_for_fixtures
Support after_commit callbacks in transactional fixtures
2015-01-20 09:53:15 -07:00