Commit Graph

1397 Commits

Author SHA1 Message Date
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
Jan
4942b41267 Fix typo in CHANGELOG 2015-12-18 22:25:57 +01:00
eileencodes
099ddfdefd Add CHANGELOG headers for Rails 5.0.0.beta1 2015-12-18 15:58:25 -05:00
Matthew Draper
2750b1b417 Merge pull request #22653 from matthewd/find_array_ordered
ActiveRecord::Base#find(array) returning result in the same order as the array passed
2015-12-18 16:42:30 +10:30
Matthew Draper
e0e918609f Merge pull request #20815 from byroot/do-not-include-column-limit-if-it-is-default
Do not include column limit in schema.rb if it matches the default
2015-12-18 14:52:05 +10:30
Matthew Draper
da6713fd03 Merge pull request #22623 from greysteil/support-passing-schema-name-to-indexes
Support passing the schema name prefix to `conenction.indexes`
2015-12-18 14:17:50 +10:30
Matthew Draper
c316ce9ba4 Merge pull request #19456 from greysteil/index-exists-behaviour
Ignore index name in `index_exists?` when not passed a name to check for
2015-12-18 14:13:46 +10:30
Matthew Draper
4a58aef7e3 Merge pull request #22642 from seuros/remove-mysql-adapter
Remove legacy mysql adapter
2015-12-18 13:51:04 +10:30
Genadi Samokovarov
008e5ab76d Pass over the ApplicationRecord changelog entry
The changelog entry for ApplicationRecord was a bit confusing. Thank you
guys for helping me get it in a better shape.

[ci skip]
2015-12-17 10:42:53 +01:00
Grey Baker
d927f35bf0 Support passing the schema name prefix to conenction.indexes
Support passing the schema name as a prefix to table name in
`ConnectionAdapters::SchemaStatements#indexes`. Previously the prefix would
be considered a full part of the index name, and only the schema in the
current search path would be considered.
2015-12-17 09:25:50 +00:00
Genadi Samokovarov
2067fff9e3 Introduce ApplicationRecord, an Active Record layer supertype
It's pretty common for folks to monkey patch `ActiveRecord::Base` to
work around an issue or introduce extra functionality. Instead of
shoving even more stuff in `ActiveRecord::Base`, `ApplicationRecord` can
hold all those custom work the apps may need.

Now, we don't wanna encourage all of the application models to inherit
from `ActiveRecord::Base`, but we can encourage all the models that do,
to inherit from `ApplicationRecord`.

Newly generated applications have `app/models/application_record.rb`
present by default. The model generators are smart enough to recognize
that newly generated models have to inherit from `ApplicationRecord`,
but only if it's present.
2015-12-16 10:30:09 +01:00
Grey Baker
9771f5e178 Ignore index name in index_exists? when not passed a name to check for 2015-12-15 17:36:09 +00:00
Lucjan Suski
9d21a7fc50 Pass SQL group by values when including scoped association
Fixes problem when added `group()` in association scope was lost
in eager loaded association.
2015-12-15 17:58:57 +01:00
Matthew Draper
6940dc860c Add migration versioning via Migration subclasses 2015-12-15 17:18:08 +10:30
Sean Griffin
574f255629 Use a bind param for LIMIT and OFFSET
We currently generate an unbounded number of prepared statements when
`limit` or `offset` are called with a dynamic argument. This changes
`LIMIT` and `OFFSET` to use bind params, eliminating the problem.

`Type::Value#hash` needed to be implemented, as it turns out we busted
the query cache if the type object used wasn't exactly the same object.

This drops support for passing an `Arel::Nodes::SqlLiteral` to `limit`.
Doing this relied on AR internals, and was never officially supported
usage.

Fixes #22250.
2015-12-14 08:40:02 -07:00
Genadi Samokovarov
5a300b2ed6 Introduce after_{create,update,delete}_commit callbacks
Those are actually shortcuts for `after_commit`.

Before:

    after_commit :add_to_index_later, on: :create
    after_commit :update_in_index_later, on: :update
    after_commit :remove_from_index_later, on: :destroy

After:

    after_create_commit  :add_to_index_later
    after_update_commit  :update_in_index_later
    after_destroy_commit :remove_from_index_later
2015-12-06 20:33:36 +02:00
claudiob
728e28ffd6 Remove old comment about AC::Parameters>subclasses
[ci skip]

Q: What happens if you initialize an AR model by passing Parameters that
have not been whitelisted with `permit`?

A: An `ActiveModel::ForbiddenAttributesError` is raised.

I think this behavior is correct, and it's better than what used to happen,
with unpermitted parameter being simply ignored.
2015-12-02 18:05:01 -08:00
Yves Senn
3da890f891 Merge pull request #17169 from kuldeepaggarwal/fix-STI-default-type
STI cast new instances to `default type` on initialize.
2015-12-02 13:39:30 +01:00
Kuldeep Aggarwal
6b18bdd00c STI cast new instances to default type on initialize.
fixes #17121
2015-12-02 16:11:24 +05:30
Yves Senn
f746534ca4 Merge pull request #22345 from GUI/fix-multi-schema-structure-dump
Fix rake db:structure:dump on Postgres when multiple schemas are used

Conflicts:
	activerecord/CHANGELOG.md

Closes #22346.
2015-11-30 16:06:57 +01:00
Ryuta Kamizono
d5007f183a Fix indentation in CHANGELOG.md [ci skip] 2015-11-30 20:44:56 +09:00
Sean Griffin
b5bbdbd3bc Revert "Add prepared statements support for Mysql2Adapter" 2015-11-26 11:53:10 -07:00
Ryuta Kamizono
38746d085b Add prepared statements support for Mysql2Adapter 2015-11-26 11:16:26 +09:00
Ryuta Kamizono
3991ebcb36 Add schema dumping support for PostgreSQL geometric data types 2015-11-24 06:16:17 +09:00
Nick Muerdter
d1dcdf2128 Fix rake db:structure:dump on Postgres when multiple schemas are used.
If postgresql is being used and there are multiple schemas listed on the
`schema_search_path`, then `structure.sql` dumps (triggered by `rake
db:structure:dump` or `config.active_record.schema_format = :sql`) began
failing in Rails 4.2.5.

This is due to the changes made in
https://github.com/rails/rails/pull/17885 The problem is that multiple
schemas were getting getting passed to `Kernel.system` as a single,
space delimited string argument (for example, "--schema=foo
--schema=bar"). However, with the updated array style of calling
`Kernel.system`, these need to be passed as separate arguments (for
example, "--schema=foo", "--schema=bar"). If they get passed as a single
string, then the underlying pg_dump program isn't sure how to interpret
that single argument and you'll get an error reporting: "pg_dump: No
matching schemas were found"
2015-11-19 11:42:04 -07:00
Sean Griffin
6b7861e834 Revert "Allow specifying the default table options for mysql adapters"
This reverts commit 8246b593bff71f2cebf274c133bb8917f1e094c8.

There was concern about this modifying the behavior of past migrations.
We're going to add an way to modify the migration generator instead.
2015-11-19 10:01:06 -07:00
Sean Griffin
8246b593bf Allow specifying the default table options for mysql adapters
It's often the case that you want to have an option that you cannot
specify at the database level, but want applied to *all* tables that you
create. For example, you might want to specify `ROW_FORMAT=DYNAMIC` to
not have to limit text columns to length 171 for indexing when using
utf8mb4. This allows an easy way to specify this in your database
configuration.

While this change affects both MySQL and MySQL2, the test only covers
MySQL2, as the legacy mysql adapter appears to always return ASCII
strings, and is tangential to what we're actually doing.
2015-11-19 09:38:27 -07:00
Andrew White
32a8cd961e Fix incorrect issue number [ci skip] 2015-11-17 15:46:31 +00:00
yui-knk
24b1c219e1 [ci skip] Add CHANGELOG for #22300 (817c1825c15013fd0180762ac5c05a2e024a640d) 2015-11-18 00:16:38 +09:00
yui-knk
7429633b82 Deprecate #table_exists?, #tables and passing arguments to #talbes
Reported on #21509, how views is treated by `#tables` are differ
by each adapters. To fix this different behavior, after Rails 5.0
is released, deprecate `#tables`.

And `#table_exists?` would check both tables and views.
To make their behavior consistent with `#tables`, after Rails 5.0
is released, deprecate `#table_exists?`.
2015-11-09 23:13:23 +09:00
Kassio Borges
c8bbe9aefa Improve support for non Active Record objects on validates_associated
Skipping `marked_for_destruction?` when the associated object does not responds
to it make easier to validate virtual associations built on top of Active Model
objects and/or serialized objects that implement a `valid?` instance method.
2015-11-08 10:58:39 -02:00
Kevin Buchanan
2fe4586974 Avoids mutating the original response in connection management middleware 2015-11-06 16:14:24 -06:00