2011-12-20 00:16:23 -05:00
|
|
|
## Rails 4.0.0 (unreleased) ##
|
2012-05-13 18:04:33 -04:00
|
|
|
|
2012-12-21 12:15:33 -05:00
|
|
|
* Serialized attributes can be serialized in integer columns.
|
|
|
|
Fix #8575.
|
|
|
|
|
|
|
|
*Rafael Mendonça França*
|
|
|
|
|
2012-12-15 16:42:22 -05:00
|
|
|
* Keep index names when using `alter_table` with sqlite3.
|
2012-12-21 12:15:33 -05:00
|
|
|
Fix #3489.
|
2012-12-15 16:42:22 -05:00
|
|
|
|
|
|
|
*Yves Senn*
|
|
|
|
|
2012-12-19 20:08:34 -05:00
|
|
|
* Add ability for postgresql adapter to disable user triggers in `disable_referential_integrity`.
|
2012-12-21 12:15:33 -05:00
|
|
|
Fix #5523.
|
2012-12-18 10:46:16 -05:00
|
|
|
|
|
|
|
*Gary S. Weaver*
|
|
|
|
|
2012-10-30 13:29:47 -04:00
|
|
|
* Added support for `validates_uniqueness_of` in PostgreSQL array columns.
|
|
|
|
Fixes #8075.
|
|
|
|
|
|
|
|
*Pedro Padron*
|
|
|
|
|
2012-12-15 21:10:58 -05:00
|
|
|
* Allow int4range and int8range columns to be created in PostgreSQL and properly convert to/from database.
|
|
|
|
|
|
|
|
*Alexey Vasiliev aka leopard*
|
|
|
|
|
2012-12-14 02:29:49 -05:00
|
|
|
* Do not log the binding values for binary columns.
|
|
|
|
|
|
|
|
*Matthew M. Boedicker*
|
|
|
|
|
2012-12-01 20:56:28 -05:00
|
|
|
* Fix counter cache columns not updated when replacing `has_many :through`
|
|
|
|
associations.
|
|
|
|
|
|
|
|
*Matthew Robertson*
|
|
|
|
|
2012-12-12 15:51:38 -05:00
|
|
|
* Recognize migrations placed in directories containing numbers and 'rb'.
|
|
|
|
Fix #8492
|
|
|
|
|
|
|
|
*Yves Senn*
|
|
|
|
|
2012-12-10 14:22:30 -05:00
|
|
|
* Add `ActiveRecord::Base.cache_timestamp_format` class attribute to control
|
|
|
|
the format of the timestamp value in the cache key.
|
|
|
|
This allows users to improve the precision of the cache key.
|
|
|
|
Fixes #8195.
|
|
|
|
|
|
|
|
*Rafael Mendonça França*
|
|
|
|
|
2012-12-10 15:14:17 -05:00
|
|
|
* Add `:nsec` date format. This can be used to improve the precision of cache key.
|
|
|
|
|
|
|
|
*Jamie Gaskins*
|
|
|
|
|
2012-11-27 03:57:45 -05:00
|
|
|
* Session variables can be set for the `mysql`, `mysql2`, and `postgresql` adapters
|
|
|
|
in the `variables: <hash>` parameter in `database.yml`. The key-value pairs of this
|
|
|
|
hash will be sent in a `SET key = value` query on new database connections. See also:
|
|
|
|
http://dev.mysql.com/doc/refman/5.0/en/set-statement.html
|
|
|
|
http://www.postgresql.org/docs/8.3/static/sql-set.html
|
|
|
|
|
|
|
|
*Aaron Stone*
|
|
|
|
|
2012-12-07 13:52:55 -05:00
|
|
|
* Allow `Relation#where` with no arguments to be chained with new `not` query method.
|
2012-11-04 23:56:30 -05:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-12-07 13:52:55 -05:00
|
|
|
Developer.where.not(name: 'Aaron')
|
2012-11-04 23:56:30 -05:00
|
|
|
|
|
|
|
*Akira Matsuda*
|
|
|
|
|
2012-12-06 20:09:11 -05:00
|
|
|
* Unscope `update_column(s)` query to ignore default scope.
|
|
|
|
|
|
|
|
When applying `default_scope` to a class with a where clause, using
|
|
|
|
`update_column(s)` could generate a query that would not properly update
|
|
|
|
the record due to the where clause from the `default_scope` being applied
|
|
|
|
to the update query.
|
|
|
|
|
|
|
|
class User < ActiveRecord::Base
|
|
|
|
default_scope where(active: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
user = User.first
|
|
|
|
user.active = false
|
|
|
|
user.save!
|
|
|
|
|
|
|
|
user.update_column(:active, true) # => false
|
|
|
|
|
|
|
|
In this situation we want to skip the default_scope clause and just
|
|
|
|
update the record based on the primary key. With this change:
|
|
|
|
|
|
|
|
user.update_column(:active, true) # => true
|
|
|
|
|
|
|
|
Fixes #8436.
|
|
|
|
|
|
|
|
*Carlos Antonio da Silva*
|
|
|
|
|
2012-12-06 19:23:01 -05:00
|
|
|
* SQLite adapter no longer corrupts binary data if the data contains `%00`.
|
|
|
|
|
2012-12-06 13:43:33 -05:00
|
|
|
*Chris Feist*
|
|
|
|
|
2012-12-06 19:23:01 -05:00
|
|
|
* Fix performance problem with `primary_key` method in PostgreSQL adapter when having many schemas.
|
|
|
|
Uses `pg_constraint` table instead of `pg_depend` table which has many records in general.
|
2012-12-04 11:12:46 -05:00
|
|
|
Fix #8414
|
|
|
|
|
|
|
|
*kennyj*
|
|
|
|
|
2012-12-02 15:24:47 -05:00
|
|
|
* Do not instantiate intermediate Active Record objects when eager loading.
|
|
|
|
These records caused `after_find` to run more than expected.
|
|
|
|
Fix #3313
|
|
|
|
|
|
|
|
*Yves Senn*
|
|
|
|
|
2012-04-05 15:21:48 -04:00
|
|
|
* Add STI support to init and building associations.
|
2012-12-14 17:16:59 -05:00
|
|
|
Allows you to do `BaseClass.new(type: "SubClass")` as well as
|
|
|
|
`parent.children.build(type: "SubClass")` or `parent.build_child`
|
2012-04-05 15:21:48 -04:00
|
|
|
to initialize an STI subclass. Ensures that the class name is a
|
|
|
|
valid class and that it is in the ancestors of the super class
|
|
|
|
that the association is expecting.
|
|
|
|
|
|
|
|
*Jason Rush*
|
|
|
|
|
2012-11-28 21:26:32 -05:00
|
|
|
* Observers was extracted from Active Record as `rails-observers` gem.
|
|
|
|
|
|
|
|
*Rafael Mendonça França*
|
|
|
|
|
2012-11-28 15:43:09 -05:00
|
|
|
* Ensure that associations take a symbol argument. *Steve Klabnik*
|
|
|
|
|
2012-11-28 08:06:19 -05:00
|
|
|
* Fix dirty attribute checks for `TimeZoneConversion` with nil and blank
|
2012-11-25 05:13:39 -05:00
|
|
|
datetime attributes. Setting a nil datetime to a blank string should not
|
|
|
|
result in a change being flagged. Fix #8310
|
|
|
|
|
|
|
|
*Alisdair McDiarmid*
|
|
|
|
|
2012-11-21 03:48:48 -05:00
|
|
|
* Prevent mass assignment to the type column of polymorphic associations when using `build`
|
|
|
|
Fix #8265
|
|
|
|
|
|
|
|
*Yves Senn*
|
|
|
|
|
2012-11-17 16:08:07 -05:00
|
|
|
* Deprecate calling `Relation#sum` with a block. To perform a calculation over
|
|
|
|
the array result of the relation, use `to_a.sum(&block)`.
|
|
|
|
|
|
|
|
*Carlos Antonio da Silva*
|
|
|
|
|
2012-11-21 09:11:14 -05:00
|
|
|
* Fix postgresql adapter to handle BC timestamps correctly
|
|
|
|
|
2012-12-14 17:16:59 -05:00
|
|
|
HistoryEvent.create!(name: "something", occured_at: Date.new(0) - 5.years)
|
2012-11-21 09:11:14 -05:00
|
|
|
|
|
|
|
*Bogdan Gusiev*
|
|
|
|
|
2012-11-19 22:38:19 -05:00
|
|
|
* When running migrations on Postgresql, the `:limit` option for `binary` and `text` columns is silently dropped.
|
|
|
|
Previously, these migrations caused sql exceptions, because Postgresql doesn't support limits on these types.
|
|
|
|
|
|
|
|
*Victor Costan*
|
|
|
|
|
2012-11-18 20:25:13 -05:00
|
|
|
* Don't change STI type when calling `ActiveRecord::Base#becomes`.
|
|
|
|
Add `ActiveRecord::Base#becomes!` with the previous behavior.
|
2011-09-14 11:32:31 -04:00
|
|
|
|
2012-11-18 20:25:13 -05:00
|
|
|
See #3023 for more information.
|
2011-09-14 11:32:31 -04:00
|
|
|
|
|
|
|
*Thomas Hollstegge*
|
|
|
|
|
2012-11-18 19:00:38 -05:00
|
|
|
* `rename_index` can be used inside a `change_table` block.
|
|
|
|
|
|
|
|
change_table :accounts do |t|
|
|
|
|
t.rename_index :user_id, :account_id
|
|
|
|
end
|
|
|
|
|
|
|
|
*Jarek Radosz*
|
|
|
|
|
2012-11-16 18:37:02 -05:00
|
|
|
* `#pluck` can be used on a relation with `select` clause. Fix #7551
|
2012-11-11 11:15:26 -05:00
|
|
|
|
2012-11-16 18:37:02 -05:00
|
|
|
Example:
|
2012-11-11 11:15:26 -05:00
|
|
|
|
|
|
|
Topic.select([:approved, :id]).order(:id).pluck(:id)
|
|
|
|
|
2012-11-16 18:37:02 -05:00
|
|
|
*Yves Senn*
|
2012-11-11 11:15:26 -05:00
|
|
|
|
2012-11-10 08:30:20 -05:00
|
|
|
* Do not create useless database transaction when building `has_one` association.
|
2012-11-11 11:13:33 -05:00
|
|
|
|
2012-11-10 08:30:20 -05:00
|
|
|
Example:
|
|
|
|
|
|
|
|
User.has_one :profile
|
|
|
|
User.new.build_profile
|
|
|
|
|
|
|
|
*Bogdan Gusiev*
|
|
|
|
|
2012-11-16 18:37:02 -05:00
|
|
|
* `:counter_cache` option for `has_many` associations to support custom named counter caches.
|
2012-11-04 11:09:25 -05:00
|
|
|
Fix #7993
|
|
|
|
|
|
|
|
*Yves Senn*
|
|
|
|
|
2012-11-02 17:51:06 -04:00
|
|
|
* Deprecate the possibility to pass a string as third argument of `add_index`.
|
|
|
|
Pass `unique: true` instead.
|
|
|
|
|
|
|
|
add_index(:users, :organization_id, unique: true)
|
|
|
|
|
|
|
|
*Rafael Mendonça França*
|
|
|
|
|
2012-11-02 16:58:27 -04:00
|
|
|
* Raise an `ArgumentError` when passing an invalid option to `add_index`.
|
|
|
|
|
|
|
|
*Rafael Mendonça França*
|
|
|
|
|
2012-10-30 10:54:16 -04:00
|
|
|
* Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
|
|
|
|
|
|
|
|
*Alexis Bernard*
|
|
|
|
|
2012-10-30 16:14:16 -04:00
|
|
|
* `AR::Base#attributes_before_type_cast` now returns unserialized values for serialized attributes.
|
|
|
|
|
|
|
|
*Nikita Afanasenko*
|
|
|
|
|
2012-11-16 18:37:02 -05:00
|
|
|
* Use query cache/uncache when using `DATABASE_URL`.
|
2012-10-30 13:21:52 -04:00
|
|
|
Fix #6951.
|
|
|
|
|
|
|
|
*kennyj*
|
|
|
|
|
2012-09-24 18:59:07 -04:00
|
|
|
* Added `#none!` method for mutating `ActiveRecord::Relation` objects to a NullRelation.
|
|
|
|
It acts like `#none` but modifies relation in place.
|
|
|
|
|
|
|
|
*Juanjo Bazán*
|
|
|
|
|
2012-10-28 12:48:04 -04:00
|
|
|
* Fix bug where `update_columns` and `update_column` would not let you update the primary key column.
|
|
|
|
|
|
|
|
*Henrik Nyh*
|
|
|
|
|
2012-10-28 13:05:30 -04:00
|
|
|
* The `create_table` method raises an `ArgumentError` when the primary key column is redefined.
|
|
|
|
Fix #6378
|
|
|
|
|
|
|
|
*Yves Senn*
|
|
|
|
|
2012-10-28 15:18:31 -04:00
|
|
|
* `ActiveRecord::AttributeMethods#[]` raises `ActiveModel::MissingAttributeError`
|
|
|
|
error if the given attribute is missing. Fixes #5433.
|
|
|
|
|
|
|
|
class Person < ActiveRecord::Base
|
|
|
|
belongs_to :company
|
|
|
|
end
|
|
|
|
|
|
|
|
# Before:
|
|
|
|
person = Person.select('id').first
|
|
|
|
person[:name] # => nil
|
|
|
|
person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
|
|
|
|
person[:company_id] # => nil
|
|
|
|
person.company # => nil
|
|
|
|
|
|
|
|
# After:
|
|
|
|
person = Person.select('id').first
|
|
|
|
person[:name] # => ActiveModel::MissingAttributeError: missing_attribute: name
|
|
|
|
person.name # => ActiveModel::MissingAttributeError: missing_attribute: name
|
|
|
|
person[:company_id] # => ActiveModel::MissingAttributeError: missing_attribute: company_id
|
|
|
|
person.company # => ActiveModel::MissingAttributeError: missing_attribute: company_id
|
|
|
|
|
|
|
|
*Francesco Rodriguez*
|
|
|
|
|
2012-10-16 05:53:18 -04:00
|
|
|
* Small binary fields use the `VARBINARY` MySQL type, instead of `TINYBLOB`.
|
|
|
|
|
|
|
|
*Victor Costan*
|
|
|
|
|
2012-09-10 16:50:04 -04:00
|
|
|
* Decode URI encoded attributes on database connection URLs.
|
|
|
|
|
|
|
|
*Shawn Veader*
|
|
|
|
|
2012-10-19 08:18:47 -04:00
|
|
|
* Add `find_or_create_by`, `find_or_create_by!` and
|
|
|
|
`find_or_initialize_by` methods to `Relation`.
|
|
|
|
|
|
|
|
These are similar to the `first_or_create` family of methods, but
|
|
|
|
the behaviour when a record is created is slightly different:
|
|
|
|
|
|
|
|
User.where(first_name: 'Penélope').first_or_create
|
|
|
|
|
|
|
|
will execute:
|
|
|
|
|
|
|
|
User.where(first_name: 'Penélope').create
|
|
|
|
|
|
|
|
Causing all the `create` callbacks to execute within the context of
|
|
|
|
the scope. This could affect queries that occur within callbacks.
|
|
|
|
|
|
|
|
User.find_or_create_by(first_name: 'Penélope')
|
|
|
|
|
|
|
|
will execute:
|
|
|
|
|
|
|
|
User.create(first_name: 'Penélope')
|
|
|
|
|
|
|
|
Which obviously does not affect the scoping of queries within
|
|
|
|
callbacks.
|
|
|
|
|
2012-10-19 10:56:18 -04:00
|
|
|
The `find_or_create_by` version also reads better, frankly.
|
|
|
|
|
|
|
|
If you need to add extra attributes during create, you can do one of:
|
|
|
|
|
|
|
|
User.create_with(active: true).find_or_create_by(first_name: 'Jon')
|
|
|
|
User.find_or_create_by(first_name: 'Jon') { |u| u.active = true }
|
|
|
|
|
|
|
|
The `first_or_create` family of methods have been nodoc'ed in favour
|
|
|
|
of this API. They may be deprecated in the future but their
|
|
|
|
implementation is very small and it's probably not worth putting users
|
|
|
|
through lots of annoying deprecation warnings.
|
2012-10-19 08:18:47 -04:00
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-09-10 16:50:04 -04:00
|
|
|
* Fix bug with presence validation of associations. Would incorrectly add duplicated errors
|
2012-10-16 22:04:40 -04:00
|
|
|
when the association was blank. Bug introduced in 1fab518c6a75dac5773654646eb724a59741bc13.
|
|
|
|
|
|
|
|
*Scott Willson*
|
|
|
|
|
2012-10-28 15:18:31 -04:00
|
|
|
* Fix bug where sum(expression) returns string '0' for no matching records.
|
2012-10-15 18:19:25 -04:00
|
|
|
Fixes #7439
|
|
|
|
|
|
|
|
*Tim Macfarlane*
|
|
|
|
|
2012-10-12 18:07:30 -04:00
|
|
|
* PostgreSQL adapter correctly fetches default values when using multiple schemas and domains in a db. Fixes #7914
|
|
|
|
|
|
|
|
*Arturo Pie*
|
|
|
|
|
2012-09-26 15:16:17 -04:00
|
|
|
* Learn ActiveRecord::QueryMethods#order work with hash arguments
|
|
|
|
|
|
|
|
When symbol or hash passed we convert it to Arel::Nodes::Ordering.
|
|
|
|
If we pass invalid direction(like name: :DeSc) ActiveRecord::QueryMethods#order will raise an exception
|
2012-10-15 18:19:25 -04:00
|
|
|
|
2012-09-26 15:16:17 -04:00
|
|
|
User.order(:name, email: :desc)
|
|
|
|
# SELECT "users".* FROM "users" ORDER BY "users"."name" ASC, "users"."email" DESC
|
|
|
|
|
|
|
|
*Tima Maslyuchenko*
|
|
|
|
|
2012-05-12 07:17:32 -04:00
|
|
|
* Rename `ActiveRecord::Fixtures` class to `ActiveRecord::FixtureSet`.
|
|
|
|
Instances of this class normally hold a collection of fixtures (records)
|
|
|
|
loaded either from a single YAML file, or from a file and a folder
|
|
|
|
with the same name. This change make the class name singular and makes
|
|
|
|
the class easier to distinguish from the modules like
|
|
|
|
`ActiveRecord::TestFixtures`, which operates on multiple fixture sets,
|
|
|
|
or `DelegatingFixtures`, `::Fixtures`, etc.,
|
|
|
|
and from the class `ActiveRecord::Fixture`, which corresponds to a single
|
|
|
|
fixture.
|
|
|
|
|
|
|
|
*Alexey Muranov*
|
|
|
|
|
2012-10-04 15:57:44 -04:00
|
|
|
* The postgres adapter now supports tables with capital letters.
|
|
|
|
Fix #5920
|
|
|
|
|
|
|
|
*Yves Senn*
|
|
|
|
|
2012-10-04 09:23:27 -04:00
|
|
|
* `CollectionAssociation#count` returns `0` without querying if the
|
|
|
|
parent record is not persisted.
|
2012-10-03 19:02:14 -04:00
|
|
|
|
|
|
|
Before:
|
|
|
|
|
2012-10-04 09:23:27 -04:00
|
|
|
person.pets.count
|
2012-10-03 19:02:14 -04:00
|
|
|
# SELECT COUNT(*) FROM "pets" WHERE "pets"."person_id" IS NULL
|
|
|
|
# => 0
|
|
|
|
|
|
|
|
After:
|
|
|
|
|
2012-10-04 09:23:27 -04:00
|
|
|
person.pets.count
|
2012-10-03 19:02:14 -04:00
|
|
|
# fires without sql query
|
|
|
|
# => 0
|
|
|
|
|
|
|
|
*Francesco Rodriguez*
|
|
|
|
|
2012-10-02 10:30:06 -04:00
|
|
|
* Fix `reset_counters` crashing on `has_many :through` associations.
|
|
|
|
Fix #7822.
|
|
|
|
|
|
|
|
*lulalala*
|
|
|
|
|
2012-09-28 12:55:35 -04:00
|
|
|
* Support for partial inserts.
|
|
|
|
|
|
|
|
When inserting new records, only the fields which have been changed
|
|
|
|
from the defaults will actually be included in the INSERT statement.
|
|
|
|
The other fields will be populated by the database.
|
|
|
|
|
|
|
|
This is more efficient, and also means that it will be safe to
|
|
|
|
remove database columns without getting subsequent errors in running
|
|
|
|
app processes (so long as the code in those processes doesn't
|
|
|
|
contain any references to the removed column).
|
|
|
|
|
2012-10-19 11:45:41 -04:00
|
|
|
The `partial_updates` configuration option is now renamed to
|
|
|
|
`partial_writes` to reflect the fact that it now impacts both inserts
|
|
|
|
and updates.
|
|
|
|
|
2012-09-28 12:55:35 -04:00
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-09-23 14:49:34 -04:00
|
|
|
* Allow before and after validations to take an array of lifecycle events
|
|
|
|
|
|
|
|
*John Foley*
|
|
|
|
|
2012-09-21 11:14:42 -04:00
|
|
|
* Support for specifying transaction isolation level
|
|
|
|
|
|
|
|
If your database supports setting the isolation level for a transaction, you can set
|
|
|
|
it like so:
|
|
|
|
|
|
|
|
Post.transaction(isolation: :serializable) do
|
|
|
|
# ...
|
|
|
|
end
|
|
|
|
|
|
|
|
Valid isolation levels are:
|
|
|
|
|
|
|
|
* `:read_uncommitted`
|
|
|
|
* `:read_committed`
|
|
|
|
* `:repeatable_read`
|
|
|
|
* `:serializable`
|
|
|
|
|
|
|
|
You should consult the documentation for your database to understand the
|
|
|
|
semantics of these different levels:
|
|
|
|
|
|
|
|
* http://www.postgresql.org/docs/9.1/static/transaction-iso.html
|
|
|
|
* https://dev.mysql.com/doc/refman/5.0/en/set-transaction.html
|
|
|
|
|
|
|
|
An `ActiveRecord::TransactionIsolationError` will be raised if:
|
|
|
|
|
|
|
|
* The adapter does not support setting the isolation level
|
|
|
|
* You are joining an existing open transaction
|
|
|
|
* You are creating a nested (savepoint) transaction
|
|
|
|
|
|
|
|
The mysql, mysql2 and postgresql adapters support setting the transaction
|
|
|
|
isolation level. However, support is disabled for mysql versions below 5,
|
|
|
|
because they are affected by a bug (http://bugs.mysql.com/bug.php?id=39170)
|
|
|
|
which means the isolation level gets persisted outside the transaction.
|
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-09-19 18:10:32 -04:00
|
|
|
* `ActiveModel::ForbiddenAttributesProtection` is included by default
|
|
|
|
in Active Record models. Check the docs of `ActiveModel::ForbiddenAttributesProtection`
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
*Guillermo Iguaran*
|
|
|
|
|
|
|
|
* Remove integration between Active Record and
|
|
|
|
`ActiveModel::MassAssignmentSecurity`, `protected_attributes` gem
|
|
|
|
should be added to use `attr_accessible`/`attr_protected`. Mass
|
|
|
|
assignment options has been removed from all the AR methods that
|
2012-09-20 14:48:32 -04:00
|
|
|
used it (ex. `AR::Base.new`, `AR::Base.create`, `AR::Base#update_attributes`, etc).
|
2012-09-19 18:10:32 -04:00
|
|
|
|
|
|
|
*Guillermo Iguaran*
|
|
|
|
|
2012-09-19 11:09:03 -04:00
|
|
|
* Fix the return of querying with an empty hash.
|
|
|
|
Fix #6971.
|
|
|
|
|
|
|
|
User.where(token: {})
|
|
|
|
|
|
|
|
Before:
|
|
|
|
|
|
|
|
#=> SELECT * FROM users;
|
|
|
|
|
|
|
|
After:
|
|
|
|
|
|
|
|
#=> SELECT * FROM users WHERE 1 = 2;
|
|
|
|
|
|
|
|
*Damien Mathieu*
|
2012-07-05 07:24:59 -04:00
|
|
|
|
2012-09-17 09:48:58 -04:00
|
|
|
* Fix creation of through association models when using `collection=[]`
|
|
|
|
on a `has_many :through` association from an unsaved model.
|
|
|
|
Fix #7661.
|
2012-09-16 21:23:58 -04:00
|
|
|
|
|
|
|
*Ernie Miller*
|
|
|
|
|
2012-09-15 21:43:30 -04:00
|
|
|
* Explain only normal CRUD sql (select / update / insert / delete).
|
2012-09-17 09:48:58 -04:00
|
|
|
Fix problem that explains unexplainable sql.
|
|
|
|
Closes #7544 #6458.
|
2012-09-15 21:43:30 -04:00
|
|
|
|
|
|
|
*kennyj*
|
|
|
|
|
2012-09-13 10:12:11 -04:00
|
|
|
* You can now override the generated accessor methods for stored attributes
|
|
|
|
and reuse the original behavior with `read_store_attribute` and `write_store_attribute`,
|
|
|
|
which are counterparts to `read_attribute` and `write_attribute`.
|
|
|
|
|
|
|
|
*Matt Jones*
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Accept belongs_to (including polymorphic) association keys in queries.
|
2012-09-11 14:11:51 -04:00
|
|
|
|
|
|
|
The following queries are now equivalent:
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
Post.where(author: author)
|
|
|
|
Post.where(author_id: author)
|
2012-09-11 14:11:51 -04:00
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
PriceEstimate.where(estimate_of: treasure)
|
|
|
|
PriceEstimate.where(estimate_of_type: 'Treasure', estimate_of_id: treasure)
|
2012-09-11 14:11:51 -04:00
|
|
|
|
|
|
|
*Peter Brown*
|
|
|
|
|
2012-09-07 11:02:29 -04:00
|
|
|
* Use native `mysqldump` command instead of `structure_dump` method
|
|
|
|
when dumping the database structure to a sql file. Fixes #5547.
|
|
|
|
|
|
|
|
*kennyj*
|
|
|
|
|
2012-08-19 18:02:34 -04:00
|
|
|
* PostgreSQL inet and cidr types are converted to `IPAddr` objects.
|
2012-09-16 23:34:43 -04:00
|
|
|
|
2012-08-19 18:02:34 -04:00
|
|
|
*Dan McClain*
|
|
|
|
|
|
|
|
* PostgreSQL array type support. Any datatype can be used to create an
|
|
|
|
array column, with full migration and schema dumper support.
|
|
|
|
|
|
|
|
To declare an array column, use the following syntax:
|
|
|
|
|
|
|
|
create_table :table_with_arrays do |t|
|
2012-09-16 23:34:43 -04:00
|
|
|
t.integer :int_array, array: true
|
2012-08-19 18:02:34 -04:00
|
|
|
# integer[]
|
2012-09-20 14:48:32 -04:00
|
|
|
t.integer :int_array, array: true, length: 2
|
2012-08-19 18:02:34 -04:00
|
|
|
# smallint[]
|
2012-09-16 23:34:43 -04:00
|
|
|
t.string :string_array, array: true, length: 30
|
2012-08-19 18:02:34 -04:00
|
|
|
# char varying(30)[]
|
2012-09-16 23:34:43 -04:00
|
|
|
end
|
2012-08-19 18:02:34 -04:00
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
This respects any other migration detail (limits, defaults, etc).
|
2012-09-18 04:51:27 -04:00
|
|
|
Active Record will serialize and deserialize the array columns on
|
2012-08-19 18:02:34 -04:00
|
|
|
their way to and from the database.
|
|
|
|
|
|
|
|
One thing to note: PostgreSQL does not enforce any limits on the
|
|
|
|
number of elements, and any array can be multi-dimensional. Any
|
|
|
|
array that is multi-dimensional must be rectangular (each sub array
|
|
|
|
must have the same number of elements as its siblings).
|
|
|
|
|
|
|
|
If the `pg_array_parser` gem is available, it will be used when
|
2012-09-16 23:34:43 -04:00
|
|
|
parsing PostgreSQL's array representation.
|
2012-08-19 18:02:34 -04:00
|
|
|
|
|
|
|
*Dan McClain*
|
|
|
|
|
2012-09-06 15:39:42 -04:00
|
|
|
* Attribute predicate methods, such as `article.title?`, will now raise
|
|
|
|
`ActiveModel::MissingAttributeError` if the attribute being queried for
|
2012-09-16 23:34:43 -04:00
|
|
|
truthiness was not read from the database, instead of just returning `false`.
|
2012-09-06 15:39:42 -04:00
|
|
|
|
|
|
|
*Ernie Miller*
|
|
|
|
|
2012-09-08 08:07:07 -04:00
|
|
|
* `ActiveRecord::SchemaDumper` uses Ruby 1.9 style hash, which means that the
|
|
|
|
schema.rb file will be generated using this new syntax from now on.
|
|
|
|
|
|
|
|
*Konstantin Shabanov*
|
2012-09-07 14:27:08 -04:00
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Map interval with precision to string datatype in PostgreSQL. Fixes #7518.
|
|
|
|
|
|
|
|
*Yves Senn*
|
2012-09-07 14:27:05 -04:00
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Fix eagerly loading associations without primary keys. Fixes #4976.
|
|
|
|
|
|
|
|
*Kelley Reynolds*
|
2012-09-07 10:05:58 -04:00
|
|
|
|
2012-09-06 16:16:03 -04:00
|
|
|
* Rails now raise an exception when you're trying to run a migration that has an invalid
|
|
|
|
file name. Only lower case letters, numbers, and '_' are allowed in migration's file name.
|
|
|
|
Please see #7419 for more details.
|
|
|
|
|
|
|
|
*Jan Bernacki*
|
|
|
|
|
2012-09-13 10:12:11 -04:00
|
|
|
* Fix bug when calling `store_accessor` multiple times.
|
2012-09-05 18:38:54 -04:00
|
|
|
Fixes #7532.
|
|
|
|
|
|
|
|
*Matt Jones*
|
|
|
|
|
|
|
|
* Fix store attributes that show the changes incorrectly.
|
|
|
|
Fixes #7532.
|
|
|
|
|
|
|
|
*Matt Jones*
|
|
|
|
|
2012-09-05 18:00:07 -04:00
|
|
|
* Fix `ActiveRecord::Relation#pluck` when columns or tables are reserved words.
|
|
|
|
|
|
|
|
*Ian Lesperance*
|
|
|
|
|
2012-09-08 12:34:22 -04:00
|
|
|
* Allow JSON columns to be created in PostgreSQL and properly encoded/decoded.
|
2012-09-05 13:01:21 -04:00
|
|
|
to/from database.
|
|
|
|
|
|
|
|
*Dickson S. Guedes*
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Fix time column type casting for invalid time string values to correctly return `nil`.
|
2012-09-05 07:05:25 -04:00
|
|
|
|
|
|
|
*Adam Meehan*
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Allow to pass Symbol or Proc into `:limit` option of #accepts_nested_attributes_for.
|
2012-08-25 20:42:40 -04:00
|
|
|
|
|
|
|
*Mikhail Dieterle*
|
|
|
|
|
2012-08-15 01:22:50 -04:00
|
|
|
* ActiveRecord::SessionStore has been extracted from Active Record as `activerecord-session_store`
|
2012-09-16 23:34:43 -04:00
|
|
|
gem. Please read the `README.md` file on the gem for the usage.
|
|
|
|
|
|
|
|
*Prem Sichanugrist*
|
2012-08-15 01:22:50 -04:00
|
|
|
|
2012-02-28 13:20:27 -05:00
|
|
|
* Fix `reset_counters` when there are multiple `belongs_to` association with the
|
|
|
|
same foreign key and one of them have a counter cache.
|
|
|
|
Fixes #5200.
|
|
|
|
|
|
|
|
*Dave Desrochers*
|
|
|
|
|
2012-07-07 09:10:01 -04:00
|
|
|
* `serialized_attributes` and `_attr_readonly` become class method only. Instance reader methods are deprecated.
|
|
|
|
|
|
|
|
*kennyj*
|
|
|
|
|
2012-08-21 09:18:10 -04:00
|
|
|
* Round usec when comparing timestamp attributes in the dirty tracking.
|
|
|
|
Fixes #6975.
|
|
|
|
|
|
|
|
*kennyj*
|
|
|
|
|
2012-11-24 06:30:18 -05:00
|
|
|
* Use inversed parent for first and last child of `has_many` association.
|
2012-08-17 09:50:12 -04:00
|
|
|
|
|
|
|
*Ravil Bayramgalin*
|
|
|
|
|
2012-11-24 06:30:18 -05:00
|
|
|
* Fix `Column.microseconds` and `Column.fast_string_to_time` to avoid converting
|
2012-08-14 16:33:06 -04:00
|
|
|
timestamp seconds to a float, since it occasionally results in inaccuracies
|
|
|
|
with microsecond-precision times. Fixes #7352.
|
|
|
|
|
|
|
|
*Ari Pollak*
|
|
|
|
|
2012-08-16 17:19:47 -04:00
|
|
|
* Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
|
|
|
|
and the dup'ed object shared the same errors.
|
|
|
|
|
2012-10-24 09:14:59 -04:00
|
|
|
*Christian Seiler*
|
2012-08-16 17:19:47 -04:00
|
|
|
|
2012-08-15 11:47:20 -04:00
|
|
|
* Raise `ArgumentError` if list of attributes to change is empty in `update_all`.
|
|
|
|
|
|
|
|
*Roman Shatsov*
|
|
|
|
|
2012-04-29 22:38:32 -04:00
|
|
|
* Fix AR#create to return an unsaved record when AR::RecordInvalid is
|
|
|
|
raised. Fixes #3217.
|
|
|
|
|
|
|
|
*Dave Yeu*
|
|
|
|
|
2012-09-08 12:34:22 -04:00
|
|
|
* Fixed table name prefix that is generated in engines for namespaced models.
|
|
|
|
|
2012-08-11 08:00:40 -04:00
|
|
|
*Wojciech Wnętrzak*
|
|
|
|
|
2012-09-08 12:34:22 -04:00
|
|
|
* Make sure `:environment` task is executed before `db:schema:load` or `db:structure:load`.
|
2012-08-05 19:33:26 -04:00
|
|
|
Fixes #4772.
|
|
|
|
|
|
|
|
*Seamus Abshere*
|
|
|
|
|
2012-08-03 05:50:49 -04:00
|
|
|
* Allow Relation#merge to take a proc.
|
|
|
|
|
|
|
|
This was requested by DHH to allow creating of one's own custom
|
|
|
|
association macros.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
module Commentable
|
|
|
|
def has_many_comments(extra)
|
|
|
|
has_many :comments, -> { where(:foo).merge(extra) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Post < ActiveRecord::Base
|
|
|
|
extend Commentable
|
|
|
|
has_many_comments -> { where(:bar) }
|
|
|
|
end
|
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-09-08 12:34:22 -04:00
|
|
|
* Add CollectionProxy#scope.
|
2012-08-01 18:14:29 -04:00
|
|
|
|
|
|
|
This can be used to get a Relation from an association.
|
|
|
|
|
|
|
|
Previously we had a #scoped method, but we're deprecating that for
|
|
|
|
AR::Base, so it doesn't make sense to have it here.
|
|
|
|
|
|
|
|
This was requested by DHH, to facilitate code like this:
|
|
|
|
|
|
|
|
Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do
|
|
|
|
@topics = @project.topics.scope
|
|
|
|
@todolists = @project.todolists.scope
|
|
|
|
@attachments = @project.attachments.scope
|
|
|
|
@documents = @project.documents.scope
|
|
|
|
end
|
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-09-08 12:34:22 -04:00
|
|
|
* Add `Relation#load`.
|
2012-08-01 16:42:38 -04:00
|
|
|
|
|
|
|
This method explicitly loads the records and then returns `self`.
|
|
|
|
|
|
|
|
Rather than deciding between "do I want an array or a relation?",
|
|
|
|
most people are actually asking themselves "do I want to eager load
|
|
|
|
or lazy load?" Therefore, this method provides a way to explicitly
|
|
|
|
eager-load without having to switch from a `Relation` to an array.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
@posts = Post.where(published: true).load
|
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-09-28 13:10:38 -04:00
|
|
|
* `Relation#order`: make new order prepend old one.
|
|
|
|
|
|
|
|
User.order("name asc").order("created_at desc")
|
|
|
|
# SELECT * FROM users ORDER BY created_at desc, name asc
|
|
|
|
|
|
|
|
This also affects order defined in `default_scope` or any kind of associations.
|
|
|
|
|
|
|
|
*Bogdan Gusiev*
|
|
|
|
|
2012-08-03 06:50:50 -04:00
|
|
|
* `Model.all` now returns an `ActiveRecord::Relation`, rather than an
|
2012-09-08 12:34:22 -04:00
|
|
|
array of records. Use `Relation#to_a` if you really want an array.
|
2012-08-03 06:50:50 -04:00
|
|
|
|
|
|
|
In some specific cases, this may cause breakage when upgrading.
|
|
|
|
However in most cases the `ActiveRecord::Relation` will just act as a
|
|
|
|
lazy-loaded array and there will be no problems.
|
|
|
|
|
|
|
|
Note that calling `Model.all` with options (e.g.
|
|
|
|
`Model.all(conditions: '...')` was already deprecated, but it will
|
|
|
|
still return an array in order to make the transition easier.
|
|
|
|
|
|
|
|
`Model.scoped` is deprecated in favour of `Model.all`.
|
|
|
|
|
|
|
|
`Relation#all` still returns an array, but is deprecated (since it
|
|
|
|
would serve no purpose if we made it return a `Relation`).
|
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-07-20 12:59:27 -04:00
|
|
|
* `:finder_sql` and `:counter_sql` options on collection associations
|
|
|
|
are deprecated. Please transition to using scopes.
|
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
|
|
|
* `:insert_sql` and `:delete_sql` options on `has_and_belongs_to_many`
|
|
|
|
associations are deprecated. Please transition to using `has_many
|
2012-09-08 12:34:22 -04:00
|
|
|
:through`.
|
2012-07-20 12:59:27 -04:00
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-09-28 13:10:38 -04:00
|
|
|
* Added `#update_columns` method which updates the attributes from
|
|
|
|
the passed-in hash without calling save, hence skipping validations and
|
|
|
|
callbacks. `ActiveRecordError` will be raised when called on new objects
|
|
|
|
or when at least one of the attributes is marked as read only.
|
|
|
|
|
|
|
|
post.attributes # => {"id"=>2, "title"=>"My title", "body"=>"My content", "author"=>"Peter"}
|
|
|
|
post.update_columns(title: 'New title', author: 'Sebastian') # => true
|
|
|
|
post.attributes # => {"id"=>2, "title"=>"New title", "body"=>"My content", "author"=>"Sebastian"}
|
|
|
|
|
|
|
|
*Sebastian Martinez + Rafael Mendonça França*
|
|
|
|
|
2012-07-18 03:21:57 -04:00
|
|
|
* The migration generator now creates a join table with (commented) indexes every time
|
|
|
|
the migration name contains the word `join_table`:
|
|
|
|
|
2012-07-19 02:05:54 -04:00
|
|
|
rails g migration create_join_table_for_artists_and_musics artist_id:index music_id
|
2012-07-18 03:21:57 -04:00
|
|
|
|
|
|
|
*Aleksey Magusev*
|
|
|
|
|
2012-07-02 15:44:17 -04:00
|
|
|
* Add `add_reference` and `remove_reference` schema statements. Aliases, `add_belongs_to`
|
|
|
|
and `remove_belongs_to` are acceptable. References are reversible.
|
2012-09-16 23:34:43 -04:00
|
|
|
|
2012-07-06 07:55:49 -04:00
|
|
|
Examples:
|
2012-07-02 15:44:17 -04:00
|
|
|
|
|
|
|
# Create a user_id column
|
|
|
|
add_reference(:products, :user)
|
2012-07-06 07:55:49 -04:00
|
|
|
# Create a supplier_id, supplier_type columns and appropriate index
|
2012-07-02 15:44:17 -04:00
|
|
|
add_reference(:products, :supplier, polymorphic: true, index: true)
|
|
|
|
# Remove polymorphic reference
|
|
|
|
remove_reference(:products, :supplier, polymorphic: true)
|
|
|
|
|
|
|
|
*Aleksey Magusev*
|
|
|
|
|
2012-06-30 15:31:40 -04:00
|
|
|
* Add `:default` and `:null` options to `column_exists?`.
|
|
|
|
|
|
|
|
column_exists?(:testings, :taggable_id, :integer, null: false)
|
|
|
|
column_exists?(:testings, :taggable_type, :string, default: 'Photo')
|
|
|
|
|
|
|
|
*Aleksey Magusev*
|
|
|
|
|
2012-07-06 05:39:46 -04:00
|
|
|
* `ActiveRecord::Relation#inspect` now makes it clear that you are
|
|
|
|
dealing with a `Relation` object rather than an array:.
|
2012-06-30 15:31:40 -04:00
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
User.where(age: 30).inspect
|
2012-07-26 03:30:50 -04:00
|
|
|
# => <ActiveRecord::Relation [#<User ...>, #<User ...>, ...]>
|
2012-06-26 14:33:21 -04:00
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
User.where(age: 30).to_a.inspect
|
2012-07-26 03:30:50 -04:00
|
|
|
# => [#<User ...>, #<User ...>]
|
2012-07-06 05:39:46 -04:00
|
|
|
|
2012-07-06 10:53:33 -04:00
|
|
|
The number of records displayed will be limited to 10.
|
|
|
|
|
|
|
|
*Brian Cardarella, Jon Leighton & Damien Mathieu*
|
2012-06-26 14:33:21 -04:00
|
|
|
|
2012-07-01 11:57:48 -04:00
|
|
|
* Add `collation` and `ctype` support to PostgreSQL. These are available for PostgreSQL 8.4 or later.
|
2012-06-29 06:18:44 -04:00
|
|
|
Example:
|
|
|
|
|
2012-07-26 03:30:50 -04:00
|
|
|
development:
|
|
|
|
adapter: postgresql
|
|
|
|
host: localhost
|
|
|
|
database: rails_development
|
|
|
|
username: foo
|
|
|
|
password: bar
|
|
|
|
encoding: UTF8
|
|
|
|
collation: ja_JP.UTF8
|
|
|
|
ctype: ja_JP.UTF8
|
2012-06-29 06:18:44 -04:00
|
|
|
|
|
|
|
*kennyj*
|
|
|
|
|
2012-12-14 17:16:59 -05:00
|
|
|
* Changed `validates_presence_of` on an association so that children objects
|
2012-06-22 12:09:48 -04:00
|
|
|
do not validate as being present if they are marked for destruction. This
|
|
|
|
prevents you from saving the parent successfully and thus putting the parent
|
|
|
|
in an invalid state.
|
|
|
|
|
|
|
|
*Nick Monje & Brent Wheeldon*
|
|
|
|
|
2012-05-29 17:36:28 -04:00
|
|
|
* `FinderMethods#exists?` now returns `false` with the `false` argument.
|
|
|
|
|
|
|
|
*Egor Lynko*
|
|
|
|
|
2012-06-21 17:40:54 -04:00
|
|
|
* Added support for specifying the precision of a timestamp in the postgresql
|
|
|
|
adapter. So, instead of having to incorrectly specify the precision using the
|
|
|
|
`:limit` option, you may use `:precision`, as intended. For example, in a migration:
|
|
|
|
|
|
|
|
def change
|
|
|
|
create_table :foobars do |t|
|
2012-12-14 17:16:59 -05:00
|
|
|
t.timestamps precision: 0
|
2012-06-21 17:40:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
*Tony Schneider*
|
|
|
|
|
2012-07-01 13:34:47 -04:00
|
|
|
* Allow `ActiveRecord::Relation#pluck` to accept multiple columns. Returns an
|
2012-06-22 08:44:30 -04:00
|
|
|
array of arrays containing the typecasted values:
|
2012-06-22 08:30:00 -04:00
|
|
|
|
|
|
|
Person.pluck(:id, :name)
|
|
|
|
# SELECT people.id, people.name FROM people
|
|
|
|
# [[1, 'David'], [2, 'Jeremy'], [3, 'Jose']]
|
|
|
|
|
|
|
|
*Jeroen van Ingen & Carlos Antonio da Silva*
|
|
|
|
|
2012-06-21 15:47:12 -04:00
|
|
|
* Improve the derivation of HABTM join table name to take account of nesting.
|
|
|
|
It now takes the table names of the two models, sorts them lexically and
|
|
|
|
then joins them, stripping any common prefix from the second table name.
|
|
|
|
|
|
|
|
Some examples:
|
|
|
|
|
|
|
|
Top level models (Category <=> Product)
|
|
|
|
Old: categories_products
|
|
|
|
New: categories_products
|
|
|
|
|
|
|
|
Top level models with a global table_name_prefix (Category <=> Product)
|
|
|
|
Old: site_categories_products
|
|
|
|
New: site_categories_products
|
|
|
|
|
|
|
|
Nested models in a module without a table_name_prefix method (Admin::Category <=> Admin::Product)
|
|
|
|
Old: categories_products
|
|
|
|
New: categories_products
|
|
|
|
|
|
|
|
Nested models in a module with a table_name_prefix method (Admin::Category <=> Admin::Product)
|
|
|
|
Old: categories_products
|
|
|
|
New: admin_categories_products
|
|
|
|
|
|
|
|
Nested models in a parent model (Catalog::Category <=> Catalog::Product)
|
|
|
|
Old: categories_products
|
|
|
|
New: catalog_categories_products
|
|
|
|
|
|
|
|
Nested models in different parent models (Catalog::Category <=> Content::Page)
|
|
|
|
Old: categories_pages
|
|
|
|
New: catalog_categories_content_pages
|
|
|
|
|
|
|
|
*Andrew White*
|
|
|
|
|
2012-07-01 13:34:47 -04:00
|
|
|
* Move HABTM validity checks to `ActiveRecord::Reflection`. One side effect of
|
2012-06-21 15:47:12 -04:00
|
|
|
this is to move when the exceptions are raised from the point of declaration
|
|
|
|
to when the association is built. This is consistant with other association
|
|
|
|
validity checks.
|
|
|
|
|
|
|
|
*Andrew White*
|
|
|
|
|
2012-05-25 08:42:28 -04:00
|
|
|
* Added `stored_attributes` hash which contains the attributes stored using
|
2012-07-01 13:34:47 -04:00
|
|
|
`ActiveRecord::Store`. This allows you to retrieve the list of attributes
|
2012-05-25 08:42:28 -04:00
|
|
|
you've defined.
|
2012-03-13 11:14:20 -04:00
|
|
|
|
2012-05-25 08:42:28 -04:00
|
|
|
class User < ActiveRecord::Base
|
|
|
|
store :settings, accessors: [:color, :homepage]
|
|
|
|
end
|
|
|
|
|
|
|
|
User.stored_attributes[:settings] # [:color, :homepage]
|
|
|
|
|
|
|
|
*Joost Baaij & Carlos Antonio da Silva*
|
2012-03-13 11:14:20 -04:00
|
|
|
|
2012-06-16 10:44:20 -04:00
|
|
|
* PostgreSQL default log level is now 'warning', to bypass the noisy notice
|
|
|
|
messages. You can change the log level using the `min_messages` option
|
|
|
|
available in your config/database.yml.
|
|
|
|
|
|
|
|
*kennyj*
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Add uuid datatype support to PostgreSQL adapter.
|
|
|
|
|
|
|
|
*Konstantin Shabanov*
|
2012-06-14 18:21:58 -04:00
|
|
|
|
2012-06-10 05:38:37 -04:00
|
|
|
* Added `ActiveRecord::Migration.check_pending!` that raises an error if
|
2012-09-16 23:34:43 -04:00
|
|
|
migrations are pending.
|
|
|
|
|
|
|
|
*Richard Schneeman*
|
2012-06-10 05:38:37 -04:00
|
|
|
|
2012-06-05 02:35:05 -04:00
|
|
|
* Added `#destroy!` which acts like `#destroy` but will raise an
|
|
|
|
`ActiveRecord::RecordNotDestroyed` exception instead of returning `false`.
|
|
|
|
|
|
|
|
*Marc-André Lafortune*
|
|
|
|
|
2012-05-28 20:56:54 -04:00
|
|
|
* Added support to `CollectionAssociation#delete` for passing `fixnum`
|
|
|
|
or `string` values as record ids. This finds the records responding
|
|
|
|
to the `id` and executes delete on them.
|
|
|
|
|
|
|
|
class Person < ActiveRecord::Base
|
|
|
|
has_many :pets
|
|
|
|
end
|
|
|
|
|
|
|
|
person.pets.delete("1") # => [#<Pet id: 1>]
|
2012-12-05 01:11:54 -05:00
|
|
|
person.pets.delete(2, 3) # => [#<Pet id: 2>, #<Pet id: 3>]
|
2012-05-28 20:56:54 -04:00
|
|
|
|
|
|
|
*Francesco Rodriguez*
|
|
|
|
|
2012-05-18 11:30:05 -04:00
|
|
|
* Deprecated most of the 'dynamic finder' methods. All dynamic methods
|
|
|
|
except for `find_by_...` and `find_by_...!` are deprecated. Here's
|
|
|
|
how you can rewrite the code:
|
|
|
|
|
|
|
|
* `find_all_by_...` can be rewritten using `where(...)`
|
|
|
|
* `find_last_by_...` can be rewritten using `where(...).last`
|
|
|
|
* `scoped_by_...` can be rewritten using `where(...)`
|
|
|
|
* `find_or_initialize_by_...` can be rewritten using
|
|
|
|
`where(...).first_or_initialize`
|
|
|
|
* `find_or_create_by_...` can be rewritten using
|
2012-10-19 08:18:47 -04:00
|
|
|
`find_or_create_by(...)` or where(...).first_or_create`
|
2012-05-18 11:30:05 -04:00
|
|
|
* `find_or_create_by_...!` can be rewritten using
|
2012-10-19 08:18:47 -04:00
|
|
|
`find_or_create_by!(...) or `where(...).first_or_create!`
|
2012-05-18 11:30:05 -04:00
|
|
|
|
|
|
|
The implementation of the deprecated dynamic finders has been moved
|
2012-08-17 05:21:52 -04:00
|
|
|
to the `activerecord-deprecated_finders` gem. See below for details.
|
2012-05-18 11:30:05 -04:00
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
|
|
|
* Deprecated the old-style hash based finder API. This means that
|
|
|
|
methods which previously accepted "finder options" no longer do. For
|
|
|
|
example this:
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
Post.find(:all, conditions: { comments_count: 10 }, limit: 5)
|
2012-05-18 11:30:05 -04:00
|
|
|
|
|
|
|
Should be rewritten in the new style which has existed since Rails 3:
|
|
|
|
|
|
|
|
Post.where(comments_count: 10).limit(5)
|
|
|
|
|
|
|
|
Note that as an interim step, it is possible to rewrite the above as:
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
Post.all.merge(where: { comments_count: 10 }, limit: 5)
|
2012-05-18 11:30:05 -04:00
|
|
|
|
|
|
|
This could save you a lot of work if there is a lot of old-style
|
|
|
|
finder usage in your application.
|
|
|
|
|
2012-07-27 13:08:18 -04:00
|
|
|
`Relation#merge` now accepts a hash of
|
2012-05-18 11:30:05 -04:00
|
|
|
options, but they must be identical to the names of the equivalent
|
|
|
|
finder method. These are mostly identical to the old-style finder
|
|
|
|
option names, except in the following cases:
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* `:conditions` becomes `:where`.
|
|
|
|
* `:include` becomes `:includes`.
|
|
|
|
* `:extend` becomes `:extending`.
|
2012-05-18 11:30:05 -04:00
|
|
|
|
|
|
|
The code to implement the deprecated features has been moved out to
|
2012-08-17 05:21:52 -04:00
|
|
|
the `activerecord-deprecated_finders` gem. This gem is a dependency
|
2012-05-18 11:30:05 -04:00
|
|
|
of Active Record in Rails 4.0. It will no longer be a dependency
|
|
|
|
from Rails 4.1, but if your app relies on the deprecated features
|
|
|
|
then you can add it to your own Gemfile. It will be maintained by
|
|
|
|
the Rails core team until Rails 5.0 is released.
|
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-05-10 07:47:50 -04:00
|
|
|
* It's not possible anymore to destroy a model marked as read only.
|
|
|
|
|
|
|
|
*Johannes Barre*
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Added ability to ActiveRecord::Relation#from to accept other ActiveRecord::Relation objects.
|
2012-04-29 14:17:57 -04:00
|
|
|
|
|
|
|
Record.from(subquery)
|
|
|
|
Record.from(subquery, :a)
|
|
|
|
|
|
|
|
*Radoslav Stankov*
|
|
|
|
|
2012-05-09 11:20:14 -04:00
|
|
|
* Added custom coders support for ActiveRecord::Store. Now you can set
|
|
|
|
your custom coder like this:
|
|
|
|
|
|
|
|
store :settings, accessors: [ :color, :homepage ], coder: JSON
|
|
|
|
|
|
|
|
*Andrey Voronkov*
|
2011-12-20 00:16:23 -05:00
|
|
|
|
2012-05-05 03:23:13 -04:00
|
|
|
* `mysql` and `mysql2` connections will set `SQL_MODE=STRICT_ALL_TABLES` by
|
|
|
|
default to avoid silent data loss. This can be disabled by specifying
|
|
|
|
`strict: false` in your `database.yml`.
|
|
|
|
|
|
|
|
*Michael Pearson*
|
|
|
|
|
2012-04-26 20:06:54 -04:00
|
|
|
* Added default order to `first` to assure consistent results among
|
2012-05-12 07:17:32 -04:00
|
|
|
different database engines. Introduced `take` as a replacement to
|
2012-04-26 20:06:54 -04:00
|
|
|
the old behavior of `first`.
|
|
|
|
|
|
|
|
*Marcelo Silveira*
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Added an `:index` option to automatically create indexes for references
|
2012-03-02 20:59:23 -05:00
|
|
|
and belongs_to statements in migrations.
|
|
|
|
|
|
|
|
The `references` and `belongs_to` methods now support an `index`
|
|
|
|
option that receives either a boolean value or an options hash
|
|
|
|
that is identical to options available to the add_index method:
|
|
|
|
|
|
|
|
create_table :messages do |t|
|
2012-09-16 23:34:43 -04:00
|
|
|
t.references :person, index: true
|
2012-03-02 20:59:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
Is the same as:
|
|
|
|
|
|
|
|
create_table :messages do |t|
|
|
|
|
t.references :person
|
|
|
|
end
|
|
|
|
add_index :messages, :person_id
|
|
|
|
|
|
|
|
Generators have also been updated to use the new syntax.
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
*Joshua Wood*
|
2012-03-02 20:59:23 -05:00
|
|
|
|
2012-04-12 12:55:39 -04:00
|
|
|
* Added bang methods for mutating `ActiveRecord::Relation` objects.
|
|
|
|
For example, while `foo.where(:bar)` will return a new object
|
|
|
|
leaving `foo` unchanged, `foo.where!(:bar)` will mutate the foo
|
|
|
|
object
|
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-03-30 07:44:45 -04:00
|
|
|
* Added `#find_by` and `#find_by!` to mirror the functionality
|
|
|
|
provided by dynamic finders in a way that allows dynamic input more
|
|
|
|
easily:
|
|
|
|
|
|
|
|
Post.find_by name: 'Spartacus', rating: 4
|
|
|
|
Post.find_by "published_at < ?", 2.weeks.ago
|
|
|
|
Post.find_by! name: 'Spartacus'
|
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-03-29 17:36:04 -04:00
|
|
|
* Added ActiveRecord::Base#slice to return a hash of the given methods with
|
|
|
|
their names as keys and returned values as values.
|
|
|
|
|
|
|
|
*Guillermo Iguaran*
|
|
|
|
|
2012-03-21 18:18:18 -04:00
|
|
|
* Deprecate eager-evaluated scopes.
|
|
|
|
|
|
|
|
Don't use this:
|
|
|
|
|
|
|
|
scope :red, where(color: 'red')
|
|
|
|
default_scope where(color: 'red')
|
|
|
|
|
|
|
|
Use this:
|
|
|
|
|
|
|
|
scope :red, -> { where(color: 'red') }
|
|
|
|
default_scope { where(color: 'red') }
|
|
|
|
|
|
|
|
The former has numerous issues. It is a common newbie gotcha to do
|
|
|
|
the following:
|
|
|
|
|
|
|
|
scope :recent, where(published_at: Time.now - 2.weeks)
|
|
|
|
|
|
|
|
Or a more subtle variant:
|
|
|
|
|
|
|
|
scope :recent, -> { where(published_at: Time.now - 2.weeks) }
|
|
|
|
scope :recent_red, recent.where(color: 'red')
|
|
|
|
|
|
|
|
Eager scopes are also very complex to implement within Active
|
|
|
|
Record, and there are still bugs. For example, the following does
|
|
|
|
not do what you expect:
|
|
|
|
|
|
|
|
scope :remove_conditions, except(:where)
|
|
|
|
where(...).remove_conditions # => still has conditions
|
|
|
|
|
|
|
|
*Jon Leighton*
|
|
|
|
|
2012-03-04 14:10:48 -05:00
|
|
|
* Remove IdentityMap
|
|
|
|
|
|
|
|
IdentityMap has never graduated to be an "enabled-by-default" feature, due
|
|
|
|
to some inconsistencies with associations, as described in this commit:
|
|
|
|
|
|
|
|
https://github.com/rails/rails/commit/302c912bf6bcd0fa200d964ec2dc4a44abe328a6
|
|
|
|
|
|
|
|
Hence the removal from the codebase, until such issues are fixed.
|
|
|
|
|
|
|
|
*Carlos Antonio da Silva*
|
2012-03-01 22:10:06 -05:00
|
|
|
|
2012-02-29 11:22:42 -05:00
|
|
|
* Added the schema cache dump feature.
|
|
|
|
|
|
|
|
`Schema cache dump` feature was implemetend. This feature can dump/load internal state of `SchemaCache` instance
|
|
|
|
because we want to boot rails more quickly when we have many models.
|
|
|
|
|
|
|
|
Usage notes:
|
|
|
|
|
|
|
|
1) execute rake task.
|
|
|
|
RAILS_ENV=production bundle exec rake db:schema:cache:dump
|
|
|
|
=> generate db/schema_cache.dump
|
|
|
|
|
2012-08-01 12:44:11 -04:00
|
|
|
2) add config.active_record.use_schema_cache_dump = true in config/production.rb. BTW, true is default.
|
2012-02-29 11:22:42 -05:00
|
|
|
|
|
|
|
3) boot rails.
|
|
|
|
RAILS_ENV=production bundle exec rails server
|
2012-03-08 06:07:44 -05:00
|
|
|
=> use db/schema_cache.dump
|
2012-02-29 11:22:42 -05:00
|
|
|
|
|
|
|
4) If you remove clear dumped cache, execute rake task.
|
|
|
|
RAILS_ENV=production bundle exec rake db:schema:cache:clear
|
|
|
|
=> remove db/schema_cache.dump
|
|
|
|
|
|
|
|
*kennyj*
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Added support for partial indices to PostgreSQL adapter.
|
2012-02-08 22:20:52 -05:00
|
|
|
|
|
|
|
The `add_index` method now supports a `where` option that receives a
|
|
|
|
string with the partial index criteria.
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
add_index(:accounts, :code, where: 'active')
|
2012-02-08 22:20:52 -05:00
|
|
|
|
2012-08-11 12:11:01 -04:00
|
|
|
Generates
|
2012-02-08 22:20:52 -05:00
|
|
|
|
2012-08-11 12:11:01 -04:00
|
|
|
CREATE INDEX index_accounts_on_code ON accounts(code) WHERE active
|
2012-02-08 22:20:52 -05:00
|
|
|
|
|
|
|
*Marcelo Silveira*
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Implemented ActiveRecord::Relation#none method.
|
2012-01-30 15:36:47 -05:00
|
|
|
|
|
|
|
The `none` method returns a chainable relation with zero records
|
|
|
|
(an instance of the NullRelation class).
|
|
|
|
|
|
|
|
Any subsequent condition chained to the returned relation will continue
|
|
|
|
generating an empty relation and will not fire any query to the database.
|
|
|
|
|
|
|
|
*Juanjo Bazán*
|
|
|
|
|
|
|
|
* Added the `ActiveRecord::NullRelation` class implementing the null
|
2012-09-16 23:34:43 -04:00
|
|
|
object pattern for the Relation class.
|
2012-01-30 15:36:47 -05:00
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
*Juanjo Bazán*
|
|
|
|
|
|
|
|
* Added new `dependent: :restrict_with_error` option. This will add
|
2012-08-10 07:33:51 -04:00
|
|
|
an error to the model, rather than raising an exception.
|
2012-01-27 13:48:59 -05:00
|
|
|
|
2012-08-10 07:33:51 -04:00
|
|
|
The `:restrict` option is renamed to `:restrict_with_exception` to
|
|
|
|
make this distinction explicit.
|
2012-01-27 13:48:59 -05:00
|
|
|
|
2012-08-10 07:33:51 -04:00
|
|
|
*Manoj Kumar & Jon Leighton*
|
2012-01-27 13:48:59 -05:00
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Added `create_join_table` migration helper to create HABTM join tables.
|
2012-01-27 11:57:43 -05:00
|
|
|
|
|
|
|
create_join_table :products, :categories
|
|
|
|
# =>
|
2012-09-16 23:34:43 -04:00
|
|
|
# create_table :categories_products, id: false do |td|
|
|
|
|
# td.integer :product_id, null: false
|
|
|
|
# td.integer :category_id, null: false
|
2012-01-27 11:57:43 -05:00
|
|
|
# end
|
|
|
|
|
|
|
|
*Rafael Mendonça França*
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* The primary key is always initialized in the @attributes hash to `nil` (unless
|
2012-01-27 11:57:43 -05:00
|
|
|
another value has been specified).
|
2012-01-25 17:42:08 -05:00
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
*Aaron Paterson*
|
|
|
|
|
2012-01-16 16:14:34 -05:00
|
|
|
* In previous releases, the following would generate a single query with
|
|
|
|
an `OUTER JOIN comments`, rather than two separate queries:
|
|
|
|
|
|
|
|
Post.includes(:comments)
|
|
|
|
.where("comments.name = 'foo'")
|
|
|
|
|
|
|
|
This behaviour relies on matching SQL string, which is an inherently
|
|
|
|
flawed idea unless we write an SQL parser, which we do not wish to
|
|
|
|
do.
|
|
|
|
|
2012-01-16 16:35:21 -05:00
|
|
|
Therefore, it is now deprecated.
|
|
|
|
|
|
|
|
To avoid deprecation warnings and for future compatibility, you must
|
|
|
|
explicitly state which tables you reference, when using SQL snippets:
|
2012-01-16 16:14:34 -05:00
|
|
|
|
|
|
|
Post.includes(:comments)
|
|
|
|
.where("comments.name = 'foo'")
|
|
|
|
.references(:comments)
|
|
|
|
|
|
|
|
Note that you do not need to explicitly specify references in the
|
|
|
|
following cases, as they can be automatically inferred:
|
|
|
|
|
2012-12-07 17:03:00 -05:00
|
|
|
Post.includes(:comments).where(comments: { name: 'foo' })
|
|
|
|
Post.includes(:comments).where('comments.name' => 'foo')
|
|
|
|
Post.includes(:comments).order('comments.name')
|
2012-01-16 16:14:34 -05:00
|
|
|
|
2012-12-07 17:03:00 -05:00
|
|
|
You do not need to worry about this unless you are doing eager
|
2012-01-16 16:14:34 -05:00
|
|
|
loading. Basically, don't worry unless you see a deprecation warning
|
|
|
|
or (in future releases) an SQL error due to a missing JOIN.
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
*Jon Leighton*
|
2012-01-16 16:14:34 -05:00
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
* Support for the `schema_info` table has been dropped. Please
|
2012-01-10 13:54:00 -05:00
|
|
|
switch to `schema_migrations`.
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
*Aaron Patterson*
|
|
|
|
|
|
|
|
* Connections *must* be closed at the end of a thread. If not, your
|
2011-12-30 14:37:21 -05:00
|
|
|
connection pool can fill and an exception will be raised.
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
*Aaron Patterson*
|
|
|
|
|
2011-12-20 14:18:36 -05:00
|
|
|
* PostgreSQL hstore records can be created.
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
*Aaron Patterson*
|
|
|
|
|
2011-12-20 00:16:23 -05:00
|
|
|
* PostgreSQL hstore types are automatically deserialized from the database.
|
|
|
|
|
2012-09-16 23:34:43 -04:00
|
|
|
*Aaron Patterson*
|
|
|
|
|
2012-08-28 15:15:12 -04:00
|
|
|
Please check [3-2-stable](https://github.com/rails/rails/blob/3-2-stable/activerecord/CHANGELOG.md) for previous changes.
|