Commit Graph

9340 Commits

Author SHA1 Message Date
Rafael Mendonça França
f3b87be3bb Merge pull request #15582 from sgrif/sg-timestamps
Refactor determination of max updated timestamp
2014-06-11 13:50:38 -03:00
Matthew Draper
e520339104 Merge pull request #15630 from eileencodes/refactor-join-keys-on-add_constraints
begin refactoring add_constraints by moving join keys
2014-06-12 01:52:15 +09:30
Rafael Mendonça França
70b931f846 Merge pull request #15429 from sgrif/sg-rm-cached-attributes
rm cached attributes
2014-06-11 12:54:58 -03:00
Arthur Neves
4a15c53de4
Add has_one? docs [skip ci] 2014-06-11 11:27:31 -04:00
Santiago Pastorino
cd7cd9b947 Merge pull request #15637 from akshay-vishnoi/delete-deprecated-method
Remove deprecation warning
2014-06-11 11:42:23 -03:00
Rafael Mendonça França
ea3455d81b Merge pull request #15638 from sgrif/sg-column-types
Ensure `column_types` returns a type object, and not a column
2014-06-11 11:23:26 -03:00
Sean Griffin
66736c8e50 rm cached attributes
The original patch that added this concept can be found
[here](https://web.archive.org/web/20090601022739/http://dev.rubyonrails.org/ticket/9767).
The current default behavior is to cache everything except serialized
columns, unless the user specified otherwise. If anyone were to specify
otherwise, many types would actually be completely broken. Still, the
method is left in place with a deprecation warning in case anyone is
actually still calling this method.
2014-06-11 08:01:33 -06:00
Sean Griffin
4a2be83a7b Remove YAML serialization workaround for columns
We are no longer including column objects in YAML serialization, thanks
to https://github.com/rails/rails/pull/15621
2014-06-11 07:59:29 -06:00
Sean Griffin
09dd29e4f7 Ensure column_types returns a type object, and not a column 2014-06-11 07:54:39 -06:00
Akshay Vishnoi
75e3464e58 Remove deprecation warning 2014-06-11 19:19:46 +05:30
eileencodes
5823e42998 begin refactoring add_constraints by moving join keys
add_constraints is complicated and difficult to read. This is the
beginning of a long process of refactoring this code. First step:
moved the join keys out of AssociationScope and into reflection.

We then don't need to call `reflection` because now reflection is
`self`.

`foreign_key` must be named something else because reflection already has a
`foreign_key` method and when passed into `JoinKeys` it was getting the
wrong assignment. `reflection_foreign_key` seemed to be an appropriate name.
I also named `key` `reflection_key` to match `reflection_foreign_key`.
2014-06-10 22:08:50 -04:00
Rafael Mendonça França
80b4fe2c50 Merge pull request #15621 from sgrif/sg-column-type-decorations
No need to decorate columns twice
2014-06-10 19:14:37 -03:00
Sean Griffin
da3b4b6173 No need to decorate columns twice
We never want result types to override column types, and
`decorate_columns` can only affect column types. No need to go through
the decoration multiple times, we can just exclude the column types from
the result types instead.
2014-06-10 14:52:14 -06:00
Kuldeep Aggarwal
16db90d13f remove deprecation call while initializing ClassCache object 2014-06-11 00:08:19 +05:30
Akshay Vishnoi
bd43203def Remove deprecated method ActiveRecord::Base.quoted_locking_column 2014-06-10 22:36:00 +05:30
Sean Griffin
47f1c10c8f Keep the types of virtual columns after yaml serialization
On MySQL and PostgreSQL, the adapter does not type cast virtual columns
for us.
2014-06-10 08:42:47 -06:00
Rafael Mendonça França
bfb8b139aa Merge pull request #15607 from sgrif/sg-array-type-cast
Inline PG array type casting helper
2014-06-10 11:06:55 -03:00
Sean Griffin
b5aa210bf7 Inline PG array type casting helper 2014-06-10 08:04:14 -06:00
James Yang
9feb4a8b5c ActiveRecord::FinderMethods.find passes proc parameter #15382 2014-06-10 08:46:07 +02:00
Arthur Neves
34c77bcf2d
Use HasAndBelongsToMany instead of HABTM 2014-06-09 22:58:28 -04:00
eileencodes
bfd0159413 reuse available collection? check instead of macro
Reflection has an available method that is used to check if the
reflection is a collection. Any :has_many macro is considered a
collection and `collection?` should be used instead of
`macro == :has_many`.
2014-06-09 19:27:08 -04:00
Rafael Mendonça França
e1175d99e2 Merge pull request #15596 from eileencodes/add-has_one-method-and-reuse
add has_one? method and reuse instead of checking macro
2014-06-09 20:21:58 -03:00
Aaron Patterson
32b6873d08 Merge pull request #15595 from eileencodes/abstract-away-habtm-macro
Abstract away use of HABTM macro
2014-06-09 16:19:07 -07:00
eileencodes
9eb87fbf15 Abstract away use of HABTM macro
By having the `:has_and_belongs_to_many` macro in the `@collection`
we are punishing `:has_many` associations because it has to allocate
the array and check the macro.

@collection is returned to `macro == :has_many` and a new reflection
class `HABTMReflection` is created to handle this case instead.
2014-06-09 19:16:00 -04:00
eileencodes
5a0b184c53 add has_one? method and reuse instead of checking macro
Instead of checking for `macro == :has_one` throughout the
codebase we can create a `has_one?` method to match the `belongs_to?`,
`polymorphic?` and other methods.
2014-06-09 19:12:43 -04:00
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
Sean Griffin
d24e6407a7 Rename type_cast to type_cast_from_database
In some cases there is a difference between the two, we should always
be doing one or the other. For convenience, `type_cast` is still a
private method on type, so new types that do not need different behavior
don't need to implement two methods, but it has been moved to private so
it cannot be used accidentally.
2014-06-09 13:39:51 -06:00
Rafael Mendonça França
254efb712a Merge pull request #15586 from sgrif/sg-identity-type
Use an actual identity type in AR::Result#identity_type
2014-06-09 16:31:25 -03:00
Sean Griffin
2742162072 Use an actual identity type in AR::Result#identity_type
We should be able to rely on this object implenting the full type
interface.
2014-06-09 13:28:26 -06:00
Rafael Mendonça França
ddb0b4a474 Merge pull request #15591 from sgrif/sg-rm-write-attribute
Make `_before_type_cast` actually be before type cast
2014-06-09 16:13:48 -03:00
Rafael Mendonça França
19f1cfbb03 Do not try to set the foreign_key again on has_many through
Integration tests are inside protected_attributes test suite.

Fixes #15496
Fixes rails/protected_attributes#35
2014-06-09 15:40:57 -03:00
Sean Griffin
c93dbfef36 Make _before_type_cast actually be before type cast
- The following is now true for all types, all the time
  - `model.attribute_before_type_cast == given_value`
  - `model.attribute == model.save_and_reload.attribute`
  - `model.attribute == model.dup.attribute`
  - `model.attribute == YAML.load(YAML.dump(model)).attribute`
- Removes the remaining types implementing `type_cast_for_write`
- Simplifies the implementation of time zone aware attributes
- Brings tz aware attributes closer to being implemented as an attribute
  decorator
- Adds additional point of control for custom types
2014-06-09 12:30:12 -06:00
Sean Griffin
82820ef53d Refactor determination of max updated timestamp
`[].max # => nil`
2014-06-09 08:31:14 -06:00
thedarkone
57a2c0d059 Remove a long gone :order option from has_one's valid_options. 2014-06-09 16:29:41 +02:00
Rafael Mendonça França
cf94a551dc Merge pull request #15558 from sgrif/sg-rename-property
Rename `property` to `attribute`

Conflicts:
	activerecord/lib/active_record/attribute_methods/serialization.rb
	activerecord/lib/active_record/base.rb
2014-06-07 15:12:24 -03:00
Rafael Mendonça França
4cf63ce373 Merge pull request #15546 from sgrif/sg-lazy-decorators
Don't query the database schema when calling `serialize`
2014-06-07 15:09:23 -03:00
Rafael Mendonça França
dc73e39b4d Merge pull request #15561 from sgrif/sg-time-zone-aware-arrays
Ensure time zones don't change after round trip with array columns
2014-06-07 14:57:04 -03:00
Rafael Mendonça França
c6e166b25e Merge pull request #15562 from sgrif/sg-double-type-cast-dirty
Do not type cast twice on attribute assignment
2014-06-07 14:52:30 -03:00
Sean Griffin
368cca51d2 Do not type cast twice on attribute assignment
The definition of `write_attribute` in dirty checking ultimately leads
to the columns calling `type_cast` on the value to perform the
comparison. However, this is a potentially expensive computation that we
cache when it occurs in `read_attribute`. The only case that we need the
non-type-cast form is for numeric, so we pass that through as well
(something I'm looking to remove in the future).

This also reduces the number of places that manually access various
stages in an attribute's type casting lifecycle, which will aid in one
of the larger refactorings that I'm working on.
2014-06-07 11:46:58 -06:00
Rafael Mendonça França
263774f045 Merge pull request #15564 from sgrif/sg-remove-dead-code
Remove dead branch when restoring ID within a transaction

Conflicts:
	activerecord/lib/active_record/transactions.rb
2014-06-07 14:33:59 -03:00
Sean Griffin
105e0304b9 Move conditionals about freezing closer to the definition of freeze
Reduces the number of places that care about the internals of how we
store and type cast attributes. We do not need to go through the
dup/freeze dance, as you couldn't have saved a frozen new record anyway,
and that is the only time we would end up modifying the frozen hash.
2014-06-07 11:03:36 -06:00
Sean Griffin
35164093f5 Remove dead branch when restoring ID within a transaction
There is no way to have an instance of an Active Record model where
`has_attribute?(self.class.primary_key)` returns false. The record is
always initialized in such a way that `@raw_attributes` will have an id
key with nil for the value.
2014-06-07 10:23:25 -06:00
Sean Griffin
e1f33110e8 Remove duplicated @raw_attributes.keys
Reduces the number of things outside of attribute methods that cares
about the details of how we store and type cast attributes
2014-06-07 09:55:28 -06:00
Sean Griffin
3b22df2350 Ensure time zones don't change after round trip with array columns
The times would be equivalent, even if they were in different time
zones. E.g. 12:00 UTC == 5:00 PDT
2014-06-07 09:38:15 -06: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
Sean Griffin
3fab9d8821 Rename property to attribute
For consistency with https://github.com/rails/rails/pull/15557
2014-06-07 07:20:25 -06:00
Sean Griffin
2dca1ba039 Don't query the database schema when calling serialize
We need to decorate the types lazily. This is extracted to a separate
API, as there are other refactorings that will be able to make use of
it, and to allow unit testing the finer points more granularly.
2014-06-07 07:03:42 -06:00
Yves Senn
23a751c2e1 Merge pull request #15556 from sgrif/sg-time-zone-aware-arrays
Add array support when time zone aware attributes are enabled
2014-06-07 14:44:12 +02:00
Sean Griffin
1c181c2950 Add array support when time zone aware attributes are enabled 2014-06-07 06:43:39 -06:00
Vijay Dev
b9ea1d3384 Merge branch 'master' of github.com:rails/docrails 2014-06-07 10:05:23 +00:00