Commit Graph

1428 Commits

Author SHA1 Message Date
eileencodes
73f8c16601 Ensure suppressor runs before validations
I ran into an issue where validations on a suppressed record were
causing validation errors to be thrown on a record that was never going
to be saved.

There isn't a reason to run the validations on a record that doesn't
matter.

This change moves the suppressor up the chain to be run on the `save` or
`save!` in the validations rather than in persistence. The issue with
running it when we hit persistence is that the validations are run
first, then we hit persistance, and then we hit the suppressor. The
suppressor comes first.

The change to the test was required since I added the
`validates_presence_of` validations. Adding this alone was enough to
demonstrate the issue. I added a new test to demonstrate the new
behavior is explict.
2016-02-24 14:33:22 -05:00
eileencodes
dbfa8fdfc2 Preparing for 5.0.0.beta3 release
Adds changelog headers for beta3 release
2016-02-24 11:14:40 -05:00
eileencodes
5a064bec62 Remove changelog entry for reverted commit
I had to revert changes made for this CHANGELOG entry so this is no
longer valid. The change for this entry was removed in 2c02bc0.
2016-02-24 08:44:22 -05:00
Matthew Draper
22c318d6cf Merge pull request #23794 from matthewd/mutation-safe-to_a
Mutating the result of Relation#to_a should not affect the relation
2016-02-21 09:13:56 +10:30
Ryuta Kamizono
af6a6e2e7b Add accidentally removed # [ci skip]
`#` was removed at f57092a but this `#` is intentional.
e.g. https://github.com/rails/rails/blame/v5.0.0.beta2/activerecord/CHANGELOG.md#L1423-L1426
2016-02-18 10:26:00 +09:00
Eileen M. Uchitelle
f57092ad72 Fix indentation for code block in changelog
This was showing up as an H1. Fixing the indentation here fixes the codeblock.
2016-02-17 18:32:58 -05:00
Mehmet Emin İNAÇ
a94018da0b Remove accidentally duplicated change log title [ci skip] 2016-02-18 00:13:24 +02:00
Philippe Huibonhoa
359adaedd9 Fixed where for polymorphic associations when passed an array containing different types.
When passing in an array of different types of objects to `where`, it would only take into account the class of the first object in the array.

    PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)])
	# => SELECT "price_estimates".* FROM "price_estimates"
         WHERE ("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" IN (1, 2))

This is fixed to properly look for any records matching both type and id:

    PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)])
    # => SELECT "price_estimates".* FROM "price_estimates"
         WHERE (("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" = 1)
         OR ("price_estimates"."estimate_of_type" = 'Car' AND "price_estimates"."estimate_of_id" = 2))
2016-02-16 10:41:26 -08:00
Yves Senn
84c18246bc Merge pull request #23614 from georgemillo/foreign_key
Let t.foreign_key use the same `to_table` twice

Conflicts:
	activerecord/CHANGELOG.md
2016-02-16 11:54:49 +01:00
Yves Senn
cf0b903f43 Merge pull request #23706 from vipulnsward/add-changelog-for-regression
Add missing CHANGELOG for regression fix in #18155 which fixes #13387
2016-02-16 09:44:08 +01:00
Vipul A M
8d3912ac24 Add missing CHANGELOG for regression fix in #18155 which fixes #13387
[ci skip]
2016-02-16 13:07:34 +05:30
George Millo
aedde2a33d Let t.foreign_key use the same to_table twice
Previously if you used `t.foreign_key` twice within the same
`create_table` block using the same `to_table`, all statements except
the final one would fail silently. For example, the following code:

    def change
      create_table :flights do |t|
        t.integer :from_id, index: true, null: false
        t.integer :to_id,   index: true, null: false

        t.foreign_key :airports, column: :from_id
        t.foreign_key :airports, column: :to_id
      end
    end

Would only create one foreign key, on the column `from_id`.

This commit allows multiple foreign keys to the same table to be created
within one `create_table` block.
2016-02-15 16:04:34 -07:00
Eileen M. Uchitelle
7ee2002008 Merge pull request #23377 from bogdan/last-with-sql
Fix AR::Relation#last bugs instroduced in 7705fc
2016-02-13 09:45:04 -05:00
Ryuta Kamizono
5f038aa488 Add the missing author name [ci skip]
The author name was lost in the merge commit 6fedc7d.
2016-02-13 19:39:56 +09:00
Bogdan Gusiev
b679916143 Make ActiveRecord::Relation#last to reverse SQL order
instead of loading the relation into memory
2016-02-13 10:32:51 +02:00
Gaurav Sharma
33e202d3ae use rails instead of rake
since starting with Rails 5.x(beta) we prefer to use rails as the replacement of rake commands, may be change log will be the same
2016-02-12 23:12:56 +05:30
Sean Griffin
6fedc7d56a Merge pull request #18109 from k0kubun/unscoped-joins
Allow `joins` to be unscoped

Fixes #13775
2016-02-11 11:33:30 -07:00
Brian Christian
eaa1efe7d0 include activerecord and activesupport CHANGELOG entries 2016-02-10 10:31:44 -08:00
Sean Griffin
5ccf8a9853 Merge pull request #23508 from meinac/add_numeric_type_into_migrations
Added numeric helper into `SchemaStatements` for MySQL and PostgreSQL
2016-02-07 15:31:29 -07:00
Mehmet Emin İNAÇ
aa38f7d615 Added numeric helper into migrations.
With this addition, you can add a column into the table like:

```
  create_table(:numeric_types) do |t|
    t.numeric :foo, precision: 10, scale: 2, default: 2.0
  end
```

The result of the migration above is same with:

```
  create_table(:numeric_types) do |t|
    t.decimal :foo, precision: 10, scale: 2, default: 2.0
  end
```
2016-02-07 03:22:03 +02:00
Sean Griffin
d666a5a5cf Revert "Dump indexes in create_table instead of add_index"
This reverts commit 99801c6a7b69eb4b006a55de17ada78f3a0fa4c1.

Ultimately it doesn't matter whether `add_index` or `t.index` are used
in the schema dumper in any meaningful way. There are gems out there
which hook into the old behavior for things like indexing materialized
views. Since the reverted commit doesn't seem to add much benefit,
there's no reason for us to break these gems.
2016-02-05 13:33:48 -07:00
Remo Mueller
85a3e0fa82 The minimum supported version of PostgreSQL is now >= 9.1 2016-02-02 16:51:07 -05:00
Rafael Mendonça França
60b040e362 Add some Action Cable CHANGELOG entries
And improve changelongs.

[ci skip]
2016-02-01 19:57:50 -02:00
Sean Griffin
49f6ce63f3 Preparing for Rails 5.0.0.beta2 2016-02-01 14:37:52 -07:00
Sean Griffin
0cbcae59dd Revert "Merge pull request #16400 from bogdan/last-with-sql"
This reverts commit 9f3730a516f30beb0050caea9539f8d6b808e58a, reversing
changes made to 2637fb75d82e1c69333855abd58c2470994995d3.

There are additional issues with this commit that need to be addressed
before this change is ready (see #23377). This is a temporary revert in
order for us to have more time to address the issues with that PR,
without blocking the release of beta2.
2016-02-01 14:03:12 -07:00
Takashi Kokubun
12e9e38d9a Allow joins to be unscoped 2016-01-31 02:30:09 +09:00
Bogdan Gusiev
7705fcf0b6 Reworked ActiveRecord::Relation#last to always use SQL
instead of loading relation
2016-01-28 17:45:53 +02:00
Bogdan Gusiev
14efb42a90 Introduce ActiveRecord::IrreversibleOrderError
Raises when #reverse_order can not process SQL order instead of making
invalid SQL before this patch
2016-01-27 12:53:51 +02:00
Akira Matsuda & Naoto Koshikawa
42dd2336b3 INSERT INTO schema_migrations in 1 SQL
We found that inserting all 600 schema_migrations for our mid-sized app takes about a minute on a cloud based CI environment.

I assume that the original code did not use multi-row-insert because SQLite3 was not supporting the syntax back then,
but it's been supported since 3.7.11: http://www.sqlite.org/releaselog/3_7_11.html
2016-01-27 18:17:13 +09:00
Prathamesh Sonpatki
909818b93b Pare back default index option for the migration generator
- Using `references` or `belongs_to` in migrations will always add index
  for the referenced column by default, without adding `index:true` option
  to generated migration file.
- Users can opt out of this by passing `index: false`.
- Legacy migrations won't be affected by this change. They will continue
  to run as they were before.
- Fixes #18146
2016-01-24 18:48:15 +05:30
Prathamesh Sonpatki
e677cc1170 Update CHANEGLOG for https://github.com/rails/rails/pull/20005 [ci skip] 2016-01-20 08:39:57 +05:30
Yves Senn
3ea4476942 run type column through attribtues API type casting.
Closes #21986.

This makes it possible to write custom types that define a different
mapping for STI columns.
2016-01-19 17:31:16 +01:00
Vipul A M
da26934313 Changed options for find_each and variants to have options start/finish instead of start_at/end_at based on comments
at https://github.com/rails/rails/pull/12257#issuecomment-74688344
2016-01-18 12:40:30 +05:30
Rafael França
de2259791c Merge pull request #20005 from kamipo/default_expression_support
Add `:expression` option support on the schema default
2016-01-16 04:18:21 -02:00
Kasper Timm Hansen
1aa1cec777 Revert "Merge pull request #20835 from glittershark/if-and-unless-in-secure-token"
This reverts commit 224eddfc0eeff6555ae88691306e61c7a9e8b758, reversing
changes made to 9d681fc74c6251d5f2b93fa9576c9b2113116680.

When merging the pull request, I misunderstood `has_secure_token` as declaring a model
has a token from birth and through the rest of its lifetime.

Therefore, supporting conditional creation doesn't make sense. You should never mark a
model as having a secure token if there's a time when it shouldn't have it on creation.
2016-01-14 21:52:03 +01:00
Ryuta Kamizono
5fd30ac52d Add expression support on the schema default
Example:

    create_table :posts do |t|
      t.datetime :published_at, default: -> { 'NOW()' }
    end
2016-01-13 22:03:56 +09:00
Yves Senn
f5ab4055b9 docs, formatting pass over changelogs. [ci skip] 2016-01-13 10:19:55 +01:00
Yves Senn
ede2343031 fix regression when loading fixture files with symbol keys.
Closes #22584.
2016-01-13 10:11:54 +01:00
Yves Senn
f718e52bcc add migration versioning example to the changelog. [ci skip]
Closes #23021.
2016-01-12 09:08:18 +01:00
Griffin Smith
21c0a1f301 Support :if and :unless in has_secure_token
Pass through :if and :unless options from has_secure_token to the
generated before_create callback
2016-01-09 14:49:00 -05:00
Prathamesh Sonpatki
ec9dce583b Added missing CHANGELOG entry for https://github.com/rails/rails/pull/22976
[ci skip]
2016-01-09 08:17:46 +05:30
Rafael Mendonça França
059820c09a Merge pull request #21688 from kamipo/add_text_and_blob_shorthand_methods
Add short-hand methods for text and blob types in MySQL
2016-01-06 03:21:14 -02:00
Rafael Mendonça França
53954aa476 Move CHANGELOG entry to Active Record
While the type definition is in Active Model the change of behavior will
be only user facing in Active Record so better to put the entry in its
changelog.

[ci skip]
2016-01-05 23:00:57 -02:00
Ryuta Kamizono
4d4239f980 Add short-hand methods for text and blob types in MySQL
In Pg and Sqlite3, `:text` and `:binary` have variable unlimited length.
But in MySQL, these have limited length for each types (ref #21591, #21619).
This change adds short-hand methods for each text and blob types.

Example:

    create_table :foos do |t|
      t.tinyblob   :tiny_blob
      t.mediumblob :medium_blob
      t.longblob   :long_blob
      t.tinytext   :tiny_text
      t.mediumtext :medium_text
      t.longtext   :long_text
    end
2016-01-05 10:36:37 +09:00
Ben Woosley
b42c3255bf Fix first(limit) to take advantage of loaded? records if available
I realized that `first(2)`, etc. was unnecessarily querying for the
records when they were already preloaded. This was because
`find_nth_with_limit` can not know which `@records` to return because
it conflates the `offset` and `index` into a single variable, while
the `@records` only needs the `index` itself to select the proper
record.

Because `find_nth` and `find_nth_with_limit` are public methods, I
instead introduced a private method `find_nth_with_limit_and_offset`
which is called internally and handles the `loaded?` checking.

Once the `offset` argument is removed from `find_nth`,
`find_nth_with_limit_and_offset` can be collapsed into
`find_nth_with_limit`, with `offset` always equal to `offset_index`.
2015-12-24 09:03:28 -08:00
Ben Woosley
16a476e4f8 Deprecate passing offset to find_nth
All uses of the `offset` are passing `offset_index`. Better to push
down the `offset` consideration into `find_nth`.

This also works toward enabling `find_nth_with_limit` to take
advantage of the `loaded?` state of the relation.
2015-12-24 09:02:54 -08:00
Yves Senn
e426258aa2 release notes, extracted notable changes from Active Record CHANGELOG.
[ci skip]
2015-12-23 12:06:38 +01:00
Yves Senn
b06f6a1d8c Revert "Merge pull request #22486 from methyl/fix-includes-for-groupped-association"
This reverts commit 537ac7d6ade61e95f2b70685ff2236b7de965bab, reversing
changes made to 9c9c54abe08d86967efd3dcac1d65158a0ff74ea.

Reason:
The way we preload associations will change the meaning of GROUP BY
operations. This is illustrated in the SQL generated by the added
test (failing on PG):

Association Load:
D, [2015-12-21T12:26:07.169920 #26969] DEBUG -- :   Post Load (0.7ms)  SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" = $1 GROUP BY posts.id ORDER BY SUM(comments.tags_count)  [["author_id", 1]]

Preload:
D, [2015-12-21T12:26:07.128305 #26969] DEBUG -- :   Post Load (1.3ms)  SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" IN (1, 2, 3) GROUP BY posts.id ORDER BY SUM(comments.tags_count)
2015-12-21 12:31:52 +01:00
Genadi Samokovarov
c5b6ec7b0f No more no changes entries in the CHANGELOGs
During the `5.0.0.beta1` release, the CHANGELOGs got an entry like the
following:

```
* No changes.
```

It is kinda confusing as there are indeed changes after it. Not a
biggie, just a small pass over the CHANGELOGs.

[ci skip]
2015-12-21 11:46:38 +02:00
Yves Senn
537ac7d6ad Merge pull request #22486 from methyl/fix-includes-for-groupped-association
Pass group values when including association

Conflicts:
	activerecord/CHANGELOG.md
2015-12-21 10:10:07 +01:00