| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
A common source of bugs and code bloat within Active Record has been the
need for us to maintain the list of bind values separately from the AST
they're associated with. This makes any sort of AST manipulation
incredibly difficult, as any time we want to potentially insert or
remove an AST node, we need to traverse the entire tree to find where
the associated bind parameters are.
With this change, the bind parameters now live on the AST directly.
Active Record does not need to know or care about them until the final
AST traversal for SQL construction. Rather than returning just the SQL,
the Arel collector will now return both the SQL and the bind parameters.
At this point the connection adapter will have all the values that it
had before.
A bit of this code is janky and something I'd like to refactor later. In
particular, I don't like how we're handling associations in the
predicate builder, the special casing of `StatementCache::Substitute` in
`QueryAttribute`, or generally how we're handling bind value replacement
in the statement cache when prepared statements are disabled.
This also mostly reverts #26378, as it moved all the code into a
location that I wanted to delete.
/cc @metaskills @yahonda, this change will affect the adapters
Fixes #29766.
Fixes #29804.
Fixes #26541.
Close #28539.
Close #24769.
Close #26468.
Close #26202.
There are probably other issues/PRs that can be closed because of this
commit, but that's all I could find on the first few pages.
|
|\
| |
| | |
Match destroyed_by_association for has_one to has_many
|
| |
| |
| |
| |
| |
| |
| | |
When a has_many association is destroyed by `dependent: destroy`,
destroyed_by_association is set to the reflection, and this can be
checked in callbacks. This matches that behaviour for has_one
associations.
|
|/ |
|
|\
| |
| | |
Make preload query to preparable
|
| |
| |
| |
| |
| |
| |
| | |
Currently preload query cannot be prepared statements even if
`prepared_statements: true` due to array handler in predicate builder
doesn't support making bind params. This makes preload query to
preparable by don't passing array value if possible.
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Without this fix, `JoinDependency` doesn't use a custom table alias:
```
% ARCONN=sqlite3 be ruby -w -Itest test/cases/relations_test.rb -n test_using_a_custom_table_with_joins_affects_the_wheres
Using sqlite3
Run options: -n test_using_a_custom_table_with_joins_affects_the_wheres --seed 14531
E
Error:RelationTest#test_using_a_custom_table_with_joins_affects_the_wheres:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: posts.author_id: SELECT "omg_posts".* FROM "posts" "omg_posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" WHERE "omg_posts"."title" = ? LIMIT ?
```
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
I investigated where `scope_for_create` is reused in tests with the
following code:
```diff
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -590,6 +590,10 @@ def where_values_hash(relation_table_name = table_name)
end
def scope_for_create
+ if defined?(@scope_for_create) && @scope_for_create
+ puts caller
+ puts "defined"
+ end
@scope_for_create ||= where_values_hash.merge!(create_with_value.stringify_keys)
end
```
It was hit only `test_scope_for_create_is_cached`. This means that
`scope_for_create` will not be reused in normal use cases. So we can
remove caching `scope_for_create` to respect changing `where_clause` and
`create_with_value`.
|
| |
| |
| |
| |
| |
| |
| | |
This is related with #27680.
Since `where_values_hash` keys constructed by `where` are string, so we
need `stringify_keys` to `create_with_value` before merging it.
|
|/
|
|
| |
If `table.table_alias` is not nil, it is enough to use `table` simply.
|
|
|
|
| |
Fixes #28324.
|
| |
|
|
|
|
| |
These are no longer used since b98668decb9712f26118de57623fd15d7d28646d.
|
|\ |
|
| |
| |
| |
| |
| | |
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
|
| |\
| | |
| | |
| | | |
Enforce frozen string in Rubocop
|
| | | |
|
| |\ \
| | | |
| | | |
| | | | |
Make ActiveSupport frozen-string-literal friendly.
|
| | | | |
|
| |\ \ \
| | | | |
| | | | | |
Should be clear `@association_ids` when joined newly associated record
|
| | | |/
| | |/|
| | | |
| | | | |
Fixes #29627.
|
|/ / / |
|
|/ / |
|
|\ \
| | |
| | | |
Remove unused `aliased_table_name` in `Association`
|
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
`aliased_table_name` in `Association` was added at a3502c4.
`aliased_table_name` in `JoinDependency` (added at 55854c4) is used, but
it looks like that added one in `Association` is never used from the
beginning.
|
|\ \ \
| |/ /
|/| | |
Prevent extra `through_scope`
|
| | |
| | |
| | |
| | | |
We can reuse `through_scope` for `reset_association`.
|
|\ \ \
| | | |
| | | |
| | | |
| | | | |
kamipo/dont_passing_klass_connection_to_association_scope
Don't passing `klass.connection` to `AssociationScope`
|
| | | |
| | | |
| | | |
| | | |
| | | | |
Passing `klass.connection` is redundant because `AssociationScope` is
passed an association itself and an association has `klass`.
|
|\ \ \ \
| |/ / /
|/| | |
| | | |
| | | | |
kamipo/fix_ids_reader_to_respect_case_sensitive_pk
Fix `ids_reader` to respect case sensitive primary key
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
```ruby
car = Car.create!(name: "Tofaş")
# Before
car.bulb_ids # => SELECT "bulbs".ID FROM "bulbs" WHERE "bulbs"."name" = $1 AND "bulbs"."car_id" = $2 [["name", "defaulty"], ["car_id", 3]]
# After
car.bulb_ids # => SELECT "bulbs"."ID" FROM "bulbs" WHERE "bulbs"."name" = $1 AND "bulbs"."car_id" = $2 [["name", "defaulty"], ["car_id", 3]]
```
|
|\ \ \ \
| |/ / /
|/| | | |
ActiveRecord: do not create "has many through" records that have been removed
|
| | | |
| | | |
| | | |
| | | |
| | | | |
If a record was built on a HasManyThroughAssociation, then removed, and
then the record was saved, the removed record would be created anyways.
|
|\ \ \ \
| | | | |
| | | | | |
Refactor join dependency to move building constraints to `join_scope` in `Reflection`
|
| | | | | |
|
| |/ / / |
|
|/ / /
| | |
| | |
| | |
| | | |
Simply we can skip instantiating `NullPreloader` if `assoc.klass` is
nil.
|
|\ \ \
| | | |
| | | | |
Extract `build_scope` and `predicate_builder` in `Reflection`
|
| | | | |
|
| | | | |
|
|\ \ \ \
| | | | |
| | | | | |
Ensure that using correct alias tracker
|
| |/ / /
| | | |
| | | |
| | | | |
association, not the join root
|
|\ \ \ \
| |/ / /
|/| | | |
Rails 5.1.2.rc1 regression - Clear offset cache on CollectionProxy reset/reload
|
| | | | |
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
The `@offsets` cache is used by FinderMethods to cache records found by
find_nth. This cache is cleared in AR::Relation#reset, but not in
CollectionProxy#reset or CollectionProxy#reload.
Because of this, since #29098, calling #first/#find_nth/etc after
calling #reload or #reset on an association could return a stale record.
This is an issue both when the full association target is loaded and
when the item is loaded in #find_nth.
This commit solves the problem by clearing the `@offsets` cache in
CollectionProxy#reset and CollectionProxy#reload.
|
|/ / /
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Doing `Author.joins(:posts).merge(Post.joins(:comments))` does this
`SELECT ... INNER JOIN posts ON... LEFT OUTER JOIN comments ON...`
instead of doing
`SELECT ... INNER JOIN posts ON... INNER JOIN comments ON...`.
This behavior is unexpected and makes little sense as, basically, doing
`Post.joins(:comments)` means I want posts that have comments. Turning
it to a LEFT JOIN means I want posts and join the comments data, if
any.
We can see this problem directly in the existing tests.
The test_relation_merging_with_merged_joins_as_symbols only does joins
from posts to comments to ratings while the ratings fixture isn't
loaded, but the count is non-zero.
|
| |/
|/|
| |
| | |
Because constructing `scope` is a little expensive.
|
| |
| |
| |
| |
| |
| | |
A collection association will raise on `#create_association` when the parent is
unpersisted. A singular association should do the same. This addresses
issue #29219.
|
| | |
|