Commit Graph

915 Commits

Author SHA1 Message Date
Rafael Mendonça França
dddbccb25a Timestamp values should be present on callbacks
This reverts commit dd3ea17191e316aeebddaa7b176f6cfeee7a6365 and add a
regression test.

Fixes #15418
2014-06-09 17:27:32 -03:00
Yves Senn
16f595f1b6 changelog for #15556 and credit @kuldeepaggarwal [Kuldeep Aggarwal]
This is a follow up to #15556

@kuldeepaggarwal did submit this patch way back (#13624).
2014-06-07 16:26:28 +02:00
Yves Senn
ac8ff90909 credit JoseLuis Torres for #15051. [JoseLuis Torres]
[ci skip]
2014-06-06 16:03:13 +02:00
Yves Senn
8fa8b7124b ActiveRecord::SchemaMigration has no primary key.
Before this patch, using `ActiveRecord::Base.primary_key_prefix_type`
with `:table_name_with_underscore` would change the `SchemaMigration` model
to have a primary key. This resulted in broken queries for PG because it tried
to return the inserted PK (which does not exist).

Closes #15051.
Closes #15419.
2014-06-06 15:53:33 +02:00
Yves Senn
e3cd80b4cf bin/rake db:migrate:status works with legacy migration numbers.
The migration numbers were normalized different ways. This left
the task output in an inconsistent state.

Closes #15538.
2014-06-06 12:16:48 +02:00
Yves Senn
01777079cd Merge pull request #14971 from versioncontrol/#14785
Baseclass becomes! subclass
2014-06-06 08:56:29 +02:00
Yves Senn
bb8b214184 Merge pull request #15512 from akshay-vishnoi/delete-deprecated-method
Remove deprecated method ActiveRecord::Migrator.proper_table_name
2014-06-05 11:35:55 +02:00
Akshay Vishnoi
6da0072253 Remove deprecated method ActiveRecord::Migrator.proper_table_name 2014-06-05 14:48:58 +05:30
Carlos Antonio da Silva
c5c0bad190 Merge pull request #15482 from laurocaetano/fix-regression-for-eager-load
Fix regression on eager loading association based on SQL query rather than existing column.

Conflicts:
	activerecord/CHANGELOG.md
2014-06-04 07:55:59 -03:00
Godfrey Chan
2a6f4282b9 Cleaned up duplicated CHANGELOG entry [ci skip] 2014-06-03 20:14:11 -07:00
Rafael Mendonça França
1c6bb0efe0 Merge pull request #15438 from sgrif/sg-null-column
Return a null column when no column exists for an attribute

Conflicts:
	activerecord/CHANGELOG.md
2014-06-03 19:30:34 -03:00
Rafael Mendonça França
5146f3af05 Merge pull request #15172 from notEthan/active_record_pretty_print
implement ActiveRecord::Base#pretty_print

Conflicts:
	activerecord/CHANGELOG.md
2014-06-03 19:02:28 -03:00
Lauro Caetano
2c555ec43a Fix regression on eager loading association based on SQL query rather
than existing column.

Fixes #15480.
2014-06-03 16:20:08 -03:00
Yves Senn
9e86428d23 pg, preserve money type when dumping schema and extract money default. 2014-06-03 17:54:25 +02:00
Sean Griffin
fb2a1c4b47 Return a null column when no column exists for an attribute 2014-06-03 09:33:46 -06:00
Yves Senn
fcd5e56b86 pg, preserve type when schema dumping bit and bit varying columns. 2014-06-03 16:17:59 +02:00
Yves Senn
098bb63ae4 pg, preserve point type when schema dumping. 2014-06-03 13:56:21 +02:00
Sean Griffin
e08494a912 New records should remain new after yaml serialization 2014-06-01 17:52:46 -06:00
Yves Senn
b9eeb0339d pg, support default values for enum types. Closes #7814.
This is an intermediate solution. It is related to the refactoring @sgrif
is making and will change in the future.
2014-05-30 13:48:05 +02:00
Yves Senn
d6c1205584 pg, default_sequence_name respects schema. Closes #7516. 2014-05-30 13:20:37 +02:00
Yves Senn
6c2b569660 Merge pull request #11896 from nkondratyev/fix_pg_columns_for_distinct
Fixed #columns_for_distinct of postgresql adapter

Conflicts:
	activerecord/CHANGELOG.md
2014-05-30 11:51:14 +02:00
Yves Senn
290de901dd pg, reset_pk_sequence! respects schemas. Closes #14719. 2014-05-30 11:09:36 +02:00
Ethan
35983ea0ce implement ActiveRecord::Base#pretty_print + changelog 2014-05-29 08:06:03 -04:00
Yves Senn
bdbf00dc78 pg, keep hstore and json attributes as Hash in @attributes.
The solution presented in this patch is not efficient. We should replace it
in the near future. The following needs to be worked out:
  * Is `@attributes` storing the Ruby or SQL representation?
  * `cacheable_column?` is broken but `hstore` and `json` rely on that behavior

Refs #15369.

/cc @sgrif @rafaelfranca
2014-05-28 13:35:02 +02:00
Rafael Mendonça França
7f73b9152c Merge pull request #15374 from sgrif/sg-private-properties
Remove AR Properties from the public API
2014-05-27 19:38:54 -03:00
Sean Griffin
aff73e0946 Remove AR Properties from the public API
Making this part of the public API was premature, let's make it private
again while I continue to work on the surrounding code.
2014-05-27 15:34:23 -07:00
Rafael Mendonça França
c352e064bc Add CHANGELOG entry for #15269 [ci skip] 2014-05-27 19:29:10 -03:00
Arthur Neves
8570f9391d
Fix redefine a has_and_belongs_to_many inside inherited class
After ad7b5efb55bcc2e0ccd3e7f22a81e984df8676d1, which changed how
has_an_belongs_to_many used to work, we start raising an error when
redefining the same has_an_belongs_to_many association. This commits fix
that regression.

[Fixes #14983]
2014-05-27 00:23:33 -04:00
Zachary Scott
5c5fa70459 Typo in AR CHANGELOG [ci skip] 2014-05-26 18:34:53 -07:00
Sean Griffin
65c33009ba Add a public API to allow users to specify column types
As a result of all of the refactoring that's been done, it's now
possible for us to define a public API to allow users to specify
behavior. This is an initial implementation so that I can work off of it
in smaller pieces for additional features/refactorings.

The current behavior will continue to stay the same, though I'd like to
refactor towards the automatic schema detection being built off of this
API, and add the ability to opt out of automatic schema detection.

Use cases:

- We can deprecate a lot of the edge cases around types, now that there
  is an alternate path for users who wish to maintain the same behavior.
- I intend to refactor serialized columns to be built on top of this
  API.
- Gem and library maintainers are able to interact with `ActiveRecord`
  at a slightly lower level in a more stable way.
- Interesting ability to reverse the work flow of adding to the schema.
  Model can become the single source of truth for the structure. We can
  compare that to what the database says the schema is, diff them, and
  generate a migration.
2014-05-26 15:26:38 -07:00
Arthur Neves
09ac448a8e
Merge pull request #15210 from arthurnn/fix_hbtm_reflection
Fix habtm reflection
Conflicts:
    activerecord/CHANGELOG.md
    activerecord/lib/active_record/counter_cache.rb
    activerecord/lib/active_record/reflection.rb
    activerecord/test/cases/reflection_test.rb
2014-05-24 14:55:20 -04:00
Zachary Scott
1d7b3fa84c Future port c8ddb61 2014-05-23 14:45:21 -07:00
Godfrey Chan
2d73f5ae2f Fixed serialization for records with an attribute named format.
* * *

This bug can be triggered when serializing record R (the instance) of type C
(the class), provided that the following conditions are met:

1. The name of one or more columns/attributes on C/R matches an existing private
   method on C (e.g. those defined by `Kernel`, such as `format`).

2. The attribute methods have not yet been generated on C.

In this case, the matching private methods will be called by the serialization
code (with no arguments) and their return values will be serialized instead. If
the method requires one or more arguments, it will result in an `ArgumentError`.

This regression is introduced in d1316bb.

* * *

Attribute methods (e.g. `#name` and `#format`, assuming the class has columns
named `name` and `format` in its database table) are lazily defined. Instead of
defining them when a the class is defined (e.g. in the `inherited` hook on
`ActiveRecord::Base`), this operation is deferred until they are first accessed.

The reason behind this is that is defining those methods requires knowing what
columns are defined on the database table, which usually requires a round-trip
to the database. Deferring their definition until the last-possible moment helps
reducing unnessary work, especially in development mode where classes are
redefined and throw away between requests.

Typically, when an attribute is first accessed (e.g. `a_book.format`), it will
fire the `method_missing` hook on the class, which triggers the definition of
the attribute methods. This even works for methods like `format`, because
calling a private method with an explicit receiver will also trigger that hook.

Unfortunately, `read_attribute_for_serialization` is simply an alias to `send`,
which does not respect method visibility. As a result, when serializing a record
with those conflicting attributes, the `method_missing` is not fired, and as a
result the attribute methods are not defined one would expected.

Before d1316bb, this is negated by the fact that calling the `run_callbacks`
method will also trigger a call to `respond_to?`, which is another trigger point
for the class to define its attribute methods. Therefore, when Active Record
tries to run the `after_find` callbacks, it will also define all the attribute
methods thus masking the problem.

* * *

The proper fix for this problem is probably to restrict `read_attribute_for_serialization`
to call public methods only (i.e. alias `read_attribute_for_serialization` to
`public_send` instead of `send`). This however would be quite risky to change
in a patch release and would probably require a full deprecation cycle.

Another approach would be to override `read_attribute_for_serialization` inside
Active Record to force the definition of attribute methods:

   def read_attribute_for_serialization(attribute)
     self.class.define_attribute_methods
     send(attribute)
   end

Unfortunately, this is quite likely going to cause a performance degradation.

This patch therefore restores the behaviour from the 4-0-stable branch by
explicitly forcing the class to define its attribute methods in a similar spot
(when records are initialized). This should not cause any extra roundtrips to
the database because the `@columns` should already be cached on the class.

Fixes #15188.
2014-05-22 14:35:04 -07:00
Matthew Draper
110d3d0c0b Merge pull request #14803 from kuldeepaggarwal/null_relation_sum_fix
Fixed a problem where `sum` used with a `group` was not returning a Hash.
2014-05-22 14:59:23 +09:30
Rafael Mendonça França
94e7dbce8a Merge pull request #14613 from Sirupsen/fix-serialize-update-column
Fix serialized field returning serialized data after update_column

Conflicts:
	activerecord/CHANGELOG.md
2014-05-21 12:38:11 -03:00
Rafael Mendonça França
6931bed1b4 Revert "Merge pull request #14544 from jefflai2/named_scope_sti"
This reverts commit 9a1abedcdeecd9464668695d4f9c1d55a2fd9332, reversing
changes made to c72d6c91a7c0c2dc81cc857a1d6db496e84e0065.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/models/comment.rb

This change break integration with activerecord-deprecated_finders so
I'm reverting until we find a way to make it work with this gem.
2014-05-21 12:15:57 -03:00
Lauro Caetano
4debc86bd3 Fix polymorphic eager load with foreign_key as String.
The foreign_key could be `String` and just doing `owners_map[owner_key]`
could return `nil`.
To prevent this bug, we should `to_s` both keys if their types are
different.

Fixes #14734.
2014-05-20 23:26:51 -03:00
Rafael Mendonça França
9a1abedcde Merge pull request #14544 from jefflai2/named_scope_sti
Fixes Issue #13466.

Conflicts:
	activerecord/CHANGELOG.md
2014-05-20 21:35:58 -03:00
Rafael Mendonça França
437f464b39 Merge pull request #14979 from brocktimus/master
Making belongs_to: touch behaviour be consistent with save updating updated_at
2014-05-20 21:03:56 -03:00
Rafael Mendonça França
26931eb320 Revert "Revert "Merge pull request #8313 from alan/only_save_changed_has_one_objects""
This reverts commit e94e6c27af495a2460c811bb506459f1428dec6b.

Conflicts:
	activerecord/CHANGELOG.md

The original commit was reverted only to be safe since #14407 were reported.
We don't have any proof we added a regression with the original commit
so reverting it now will give us more problem.

Closes #14407
2014-05-20 20:42:46 -03:00
Brock Trappitt
713fc39d93 Prevented belongs_to: touch propagating up if there are no changes being saved 2014-05-21 07:34:53 +08:00
Eric Chahin
1f4daf15f8 Fixed the inferred table name for HABTM within a schema
Fixes #14824.
2014-05-20 23:13:28 +09:30
Sean Griffin
d0f8c46e19 Remove :timestamp column type
The `:timestamp` type for columns is unused. All database adapters treat
them as the same database type. All code in `ActiveRecord` which changes
its behavior based on the column's type acts the same in both cases.
However, when the type is passed to code that checks for the `:datetime`
type, but not `:timestamp` (such as XML serialization), the result is
unexpected behavior.

Existing schema definitions will continue to work, and the `timestamp`
type is transparently aliased to `datetime`.
2014-05-19 11:32:13 -07:00
Rafael Mendonça França
889f61efff Merge pull request #10798 from jcxplorer/fix-enable_extension-with-table_name_prefix
Fix migrations that use enable_extension with table_name_prefix/suffix

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/migration.rb
2014-05-19 13:32:15 -03:00
Marc Schütz
9a0d35e820 Make :index in migrations work with all column types 2014-05-18 11:26:41 +02:00
Rafael Mendonça França
067131524b Merge pull request #14428 from jnormore/reset_counters_alias
Updates reset_counters to allow counter name in params
2014-05-17 16:21:41 -03:00
Leandro Facchinetti
7e35675059 Fix typo in CHANGELOG entry for #15071 2014-05-17 01:59:55 -03:00
Jason Normore
fec7bfe8d1 Updates reset_counters to allow counter name in params
Add support for counter name to be passed as parameter
on `CounterCache::ClassMethods#reset_counters`. This is
to be consistent with the other methods in the module
that all accept counter name.
2014-05-16 22:27:44 -04:00
Rafael Mendonça França
a9ebfc0f6a Add CHANGELOG entry for #15071 [ci skip] 2014-05-16 21:01:47 -03:00
Yves Senn
8109dc8067 formatting pass through CHANGELOGS. [ci skip] 2014-05-16 09:03:26 +02:00