| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
| |
Using a subclass to check the sequence name does not work in that case.
The sequence name will be calucalted based on the base class.
|
|
|
|
| |
prompted by #19221.
|
|
|
|
| |
These methods are nodoc so we should not document them.
|
|
|
|
|
|
|
|
|
| |
This helper no longer makes sense as a separate method. Instead I'll
just have `deserialize` call `cast` by default. This led to a random
infinite loop in the `JSON` pg type, when it called `super` from
`deserialize`. Not really a great way to fix that other than not calling
super, or continuing to have the separate method, which makes the public
API differ from what we say it is.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The same is not true of `define_attribute`, which is meant to be the low
level no-magic API that sits underneath. The differences between the two
APIs are:
- `attribute`
- Lazy (the attribute will be defined after the schema has loaded)
- Allows either a type object or a symbol
- `define_attribute`
- Runs immediately (might get trampled by schema loading)
- Requires a type object
This was the last blocker in terms of public interface requirements
originally discussed for this feature back in May. All the
implementation blockers have been cleared, so this feature is probably
ready for release (pending one more look-over by me).
|
|
|
|
| |
onwards.
|
| |
|
|
|
|
|
|
|
|
|
| |
Active Record defines `attribute_method_suffix :?`. That suffix will
match any predicate method when the lookup occurs in Active Model. This
will make it incorrectly decide that `id_changed?` should not exist,
because it attempts to determine if the attribute `id_changed` is
present, rather than `id` with the `_changed?` suffix. Instead, we will
look for any correct match.
|
| |
|
|
|
|
|
| |
`Computer` class needs to be require
See #17217 for more details
|
|
|
|
|
| |
We support this behavior, but have no tests which assert that type
casting actually occurs.
|
|
|
|
|
|
|
|
|
|
|
| |
Sufficiently large integers cause `find` and `find_by` to raise
`StatementInvalid` instead of `RecordNotFound` or just returning `nil`.
Given that we can't cast to `nil` for `Integer` like we would with junk
data for other types, we raise a `RangeError` instead, and rescue in
places where it would be highly unexpected to get an exception from
casting.
Fixes #17380
|
|
|
|
| |
We were relying on hash inequality in tests
|
|
|
|
|
|
|
|
|
|
|
| |
* Also duplicated find_by tests from relations_test.rb to finder_test.rb now
that we have a completely different implementation on the class (in core.rb
with AST caching stuff).
* Also removed a (failing) test that used mocks. Now that we have tests for the
behavior, there's no point having another test that tests the implementation
(that it delegates). Further, what the test was implying is nolonger true with
the current implementation, because Class.find_by is a real method now.
|
| |
|
|\
| |
| | |
Introduce an Attribute object to handle the type casting dance
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
There's a lot more that can be moved to these, but this felt like a good
place to introduce the object. Plans are:
- Remove all knowledge of type casting from the columns, beyond a
reference to the cast_type
- Move type_cast_for_database to these objects
- Potentially make them mutable, introduce a state machine, and have
dirty checking handled here as well
- Move `attribute`, `decorate_attribute`, and anything else that
modifies types to mess with this object, not the columns hash
- Introduce a collection object to manage these, reduce allocations, and
not require serializing the types
|
|/ |
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
For consistency with https://github.com/rails/rails/pull/15557
|
|
|
|
|
| |
`@raw_attributes` should not contain the type-cast, mutable version of
the value.
|
|
|
|
|
|
| |
With ActiveRecord::Properties, we now have a reasonable path for users
to continue to keep this behavior if they want it. This is an edge case
that has added a lot of complexity to the code base.
|
|
|
|
|
|
|
|
| |
It appears that the only time that `quote` is called with a column,
but without first calling `type_cast` is when where is called with an
array. My previous pull request broke this behavior, without failing
tests. This adds a test for the only case I can think of that exercises
the `if column.type == :integer` branch of `quote` effectively.
|
|
|
|
|
|
|
|
| |
It appears to have been used at some point in the past, but is no longer
used in any meaningful way. Whether a column is considered primary is
a property of the model, not the schema/column. This also removes the
need for yet another layer of caching of the model's schema, and we can
leave that to the schema cache.
|
| |
|
| |
|
|
|
|
| |
'AssociationRelation' is consistent.
|
|
|
|
| |
consistent.
|
|
|
|
|
|
|
|
|
|
|
| |
Example:
author.posts == Post.where(author_id: author.id)
# => true
Post.where(author_id: author.id) == author.posts
# => true
Fixes #13506
|
|
|
|
|
|
| |
460eb83d cused `ActiveRecord::Base#==` to sometimes return `nil` in some cases,
this ensures we always return a boolean value. Also fixed a similar problem in
AR reflections.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit bring the famous ordinal Array instance methods defined
in ActiveSupport into ActiveRecord as fully-fledged finders.
These finders ensure a default ascending order of the table's primary
key, and utilize the OFFSET SQL verb to locate the user's desired
record. If an offset is defined in the query, calling #second adds
to the offset to get the actual desired record.
Fixes #13743.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This solves order depndent problems in `base_test.rb`. The leaked column
information crashed test cases using the `Weird` class later on:
```
2) Error:
BasicsTest#test_group_weirds_by_from:
SyntaxError: /Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:387: invalid hex escape
... attribute_before_type_cast("\x{A4CA}\x{A4DE}\x{A4A8}", *arg...
... ^
/Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:387: invalid hex escape
...te_before_type_cast("\x{A4CA}\x{A4DE}\x{A4A8}", *args)
... ^
/Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:387: invalid hex escape
...e_type_cast("\x{A4CA}\x{A4DE}\x{A4A8}", *args)
... ^
/Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:385:in `module_eval'
/Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:385:in `define_proxy_call'
/Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:294:in `block in define_attribute_method'
/Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:285:in `each'
/Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:285:in `define_attribute_method'
/Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:252:in `block in define_attribute_methods'
/Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:252:in `each'
/Users/senny/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:252:in `define_attribute_methods'
/Users/senny/Projects/rails/activerecord/lib/active_record/attribute_methods.rb:72:in `block in define_attribute_methods'
/Users/senny/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/mutex_m.rb:73:in `synchronize'
/Users/senny/.rbenv/versions/2.0.0-p353/lib/ruby/2.0.0/mutex_m.rb:73:in `mu_synchronize'
/Users/senny/Projects/rails/activerecord/lib/active_record/attribute_methods.rb:69:in `define_attribute_methods'
/Users/senny/Projects/rails/activerecord/lib/active_record/attribute_methods.rb:174:in `method_missing'
/Users/senny/Projects/rails/activerecord/lib/active_record/attribute_assignment.rb:45:in `public_send'
/Users/senny/Projects/rails/activerecord/lib/active_record/attribute_assignment.rb:45:in `_assign_attribute'
/Users/senny/Projects/rails/activerecord/lib/active_record/attribute_assignment.rb:32:in `block in assign_attributes'
/Users/senny/Projects/rails/activerecord/lib/active_record/attribute_assignment.rb:26:in `each'
/Users/senny/Projects/rails/activerecord/lib/active_record/attribute_assignment.rb:26:in `assign_attributes'
/Users/senny/Projects/rails/activerecord/lib/active_record/core.rb:458:in `init_attributes'
/Users/senny/Projects/rails/activerecord/lib/active_record/core.rb:191:in `initialize'
/Users/senny/Projects/rails/activerecord/lib/active_record/inheritance.rb:30:in `new'
/Users/senny/Projects/rails/activerecord/lib/active_record/inheritance.rb:30:in `new'
/Users/senny/Projects/rails/activerecord/lib/active_record/persistence.rb:33:in `create'
test/cases/base_test.rb:646:in `test_group_weirds_by_from'
```
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
| |
We can conditional define the tests depending on the adapter or
connection.
Lets keep the skip for fail tests that need to be fixed.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
| |
order," -- will be replaced with a check to ensure that the keys used for comparison are integers, and only fail if they are not.
This reverts commit 6256734e2d0bdd89f4b5d11da259d40afa0c95c7.
Conflicts:
activerecord/CHANGELOG.md
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
marshalling between processes does not work with an in-memory db.
This breaks the `test_sqlite3_mem` run (see stacktrace below).
After that failure most tests start to fail randomly.
```
/Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:512:in `table_structure': Could not find table 'posts' (ActiveRecord::StatementInvalid)
from /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:399:in `columns'
from /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/schema_cache.rb:93:in `block in prepare_default_proc'
from /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/schema_cache.rb:44:in `yield'
from /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/schema_cache.rb:44:in `columns'
from /Users/senny/Projects/rails/activerecord/lib/active_record/model_schema.rb:208:in `columns'
from /Users/senny/Projects/rails/activerecord/lib/active_record/model_schema.rb:249:in `column_defaults'
from /Users/senny/Projects/rails/activerecord/lib/active_record/locking/optimistic.rb:171:in `column_defaults'
from /Users/senny/Projects/rails/activerecord/lib/active_record/core.rb:167:in `initialize'
from /Users/senny/Projects/rails/activerecord/lib/active_record/inheritance.rb:27:in `new'
from /Users/senny/Projects/rails/activerecord/lib/active_record/inheritance.rb:27:in `new'
from /Users/senny/Projects/rails/activerecord/test/cases/base_test.rb:1368:in `block in test_marshal_between_processes'
from /Users/senny/Projects/rails/activerecord/test/cases/base_test.rb:1366:in `fork'
from /Users/senny/Projects/rails/activerecord/test/cases/base_test.rb:1366:in `test_marshal_between_processes'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest/test.rb:110:in `block (3 levels) in run'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest/test.rb:208:in `capture_exceptions'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest/test.rb:107:in `block (2 levels) in run'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest/test.rb:260:in `time_it'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest/test.rb:106:in `block in run'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest.rb:296:in `on_signal'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest/test.rb:280:in `with_info_handler'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest/test.rb:105:in `run'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest.rb:268:in `block (2 levels) in run'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest.rb:267:in `each'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest.rb:267:in `block in run'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest.rb:296:in `on_signal'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest.rb:285:in `with_info_handler'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest.rb:266:in `run'
from /Users/senny/Projects/rails/activesupport/lib/active_support/test_case.rb:31:in `block in __run'
from /Users/senny/Projects/rails/activesupport/lib/active_support/test_case.rb:31:in `map'
from /Users/senny/Projects/rails/activesupport/lib/active_support/test_case.rb:31:in `__run'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest.rb:115:in `run'
from /Users/senny/Projects/rails/.bundle/gems/minitest-5.0.8/lib/minitest.rb:46:in `block in autorun'
```
/cc @tenderlove
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
or even be numbers, so sorting by id doesn't make sense. Please use `sort_by`
and specify the attribute you wish to sort with. For example, change:
Post.all.to_a.sort
to:
Post.all.to_a.sort_by(&:id)
|
| |
|
|
|
|
|
|
|
|
|
| |
When the adapter is with prepared statement disabled and the binds array
is not empty the connection adapter will try to set the binds values and
will fail. Now we are checking if the adapter has the prepared statement
disabled.
Fixes #12023
|