Commit Graph

1075 Commits

Author SHA1 Message Date
Yves Senn
2b12288139 AR specific length validator to respect marked_for_destruction.
Closes #7247.

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

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

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

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

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

The following will produce the error:

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

The problematic line is here:

    module ActiveRecord
      module Type
        module Numeric
          ...

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

The regex match doesn't accept numbers with a leading '-'.
2014-12-23 00:19:14 -06:00
Grey Baker
d318badc26 Don't raise on out-of-range datetimes passed by a user 2014-12-23 02:35:12 +00:00
Yves Senn
be1e0241f0 force: :cascade to recreate tables referenced by foreign-keys. 2014-12-19 11:27:04 +01:00
Yves Senn
36ce0c2c82 db:structure:load and db:schema:load no longer purge the database.
Closes #17945

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

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

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

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

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

The following error was produced:

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

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

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

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

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

see commit 1f31488499111fdfce79d8dc1cc8fb008f7cdb25 and 6259e4e2dcca9a79f22f96658c33efe81936bc0d

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

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

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

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

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

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

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

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

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

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

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

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

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

before:

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

after:

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

before:

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

after:

    User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"])
    # => ActiveRecord::UnknownAttributeError: unknown attribute on User: name
2014-10-15 17:32:35 -07:00