| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
privileges (take 2)
Re-create https://github.com/rails/rails/pull/21233
eeac6151a5 was reverted (127509c071b4) because it breaks tests.
----------------
ref: 72c1557254
- We must use `authors` fixture with `author_addresses` because of its foreign key constraint.
- Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
|
|\
| |
| | |
Fix extension method with dirty target in has_many associations
|
| |
| |
| |
| |
| |
| |
| | |
Extension methods should not delegate to `scope` to respect dirty
target on `CollectionProxy`.
Fixes #28419.
|
|/
|
|
|
|
|
| |
Since b644964b `ActiveRecord::Relation` includes `Enumerable` so
delegating `collect`, `all?`, and `include?` are also unneeded.
`collect` without block returns `Enumerable` without preloading by that.
We should use `load` rather than `collect` for force loading.
|
|
|
|
|
|
|
|
|
|
|
| |
Use it to specify that an association should be initialized with a
particular record before validation. For example:
# Before
belongs_to :account
before_validation -> { self.account ||= Current.account }
# After
belongs_to :account, default: -> { Current.account }
|
|
|
|
|
|
|
|
| |
The `select` in `QueryMethods` is also an enumerable method.
Enumerable methods with block should delegate to `records` on
`CollectionProxy`, not `scope`.
Fixes #28348.
|
|\
| |
| | |
Make required by default test for belongs_to association clearer
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Since #18937 `belongs_to` associations receive a setting to determine if
it should be or not treated as `required` by default.
While the tests were still passing, it was not evident that the
"default" behaviour for `required` could change in fuction of a setting,
that is set by default for fresh Rails5 apps, but not for upgraded
apps.
This commit try to relate them to make it clear what is the behaviour
expected when the setting is set as `true` or not set.
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
I incorrectly changed behavior of `dup`. Reading the original issue I
thought that `dup` should retain the original contents of the record
and it's associations but it is in fact supposed to be a copy as if a
record had been reinitialized.
This reverts commit ca8c21df0fdbf1f03ba2f7fb16b39c3282dc1be0.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
In Rails 3.2 dupping a `CollectionProxy` would dup it's `load_target` as
well. That functionality has been broken since the release of Rails 4.0.
I hit this in an application upgrade and wondered why duplicating a
CollectionProxy and assigning it to a variable stopped working.
When calling `dup` on a `CollectionProxy` only the owner (ex.
topic) was getting duplicated and the `load_target` would remain in tact
with it's original object ID. Dupping the `load_target` is useful for performing
a logging operation after records have been destroyed in a method.
For example:
```
def transfer_operation
saved_replies = topic.replies
topic.replies.clear
saved_replies.each do |reply|
user.update_replies_count!
end
end
```
This change adds a `initialize_dup` method that performs a `deep_dup` on
the `@associatiation` so that the `load_target` is dupped as well.
Fixes #17117
|
|/
|
|
|
|
|
| |
`supports_migrations?` was added at 4160b518 to determine if schema
statements (`create_table`, `drop_table`, etc) are implemented in the
adapter. But all tested databases has been supported migrations since
a4fc93c3 at least.
|
|\
| |
| | |
Delegate to `scope` rather than `merge!` for collection proxy
|
| |
| |
| |
| | |
Because merging the association scope was removed.
|
| |
| |
| |
| | |
empty lines
|
| |
| |
| |
| |
| |
| |
| | |
```
go get -u github.com/client9/misspell/cmd/misspell
misspell -w -error -source=text .
```
|
| |
| |
| |
| | |
Fixes #27666.
|
|\ \
| | |
| | | |
Reload `through_record` that has been destroyed in `create_through_record`
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
This is an alternative of #27714.
If `has_one :through` association has set `nil`, `through_record` is
destroyed but still remain loaded target in `through_proxy` until
`reload` or `reset` explicitly.
If `through_proxy` is not reset (remain destroyed (frozen) target),
setting new record causes `RuntimeError: Can't modify frozen hash`.
To prevent `RuntimeError`, should reload `through_record` that has been
destroyed in `create_through_record`.
|
|/ /
| |
| |
| |
| |
| |
| | |
`assert_raise` does not check error message. However, in some tests,
it seems like expecting error message checking with `assert_raise`.
Instead of specifying an error message in `assert_raise`, modify to use
another assert to check the error message.
|
| |
| |
| |
| |
| |
| | |
These are followups for 307065f959f2b34bdad16487bae906eb3bfeaf28,
but TBH I'm personally not very much confortable with this style.
Maybe we could override assert_equal in our test_helper not to warn?
|
| |
| |
| |
| | |
(I personally prefer writing one string in one line no matter how long it is, though)
|
| |
| |
| |
| |
| |
| |
| |
| | |
The idea of `class_name` as an option of reflection is that passing a
string would allow us to lazy autoload the class.
Using `belongs_to :client, class_name: Customer` is eagerloading models more than necessary
and creating possible circular dependencies.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This will cause a failure with the changes from 8e2e5f9:
https://github.com/rails/rails/commit/8e2e5f9e3d1f434e265dc104ea9b00ff75702fc3
With the `singularize` call that is being done in that method when there
is multiple nestings of associations (JOIN calling a JOIN) and the
`stringify_keys!` is only called once here:
https://github.com/rails/rails/blob/21e5fd4/activerecord/lib/active_record/relation/where_clause_factory.rb#L16
And not in the subsequent recursion in `.predicate_builder`
|
| |
| |
| |
| |
| |
| |
| | |
https://github.com/rails/rails/issues/26834
This change raises an error if a has_many through association
is defined before the through association.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
mtsmfm/disable-referential-integrity-without-superuser-privileges"
This reverts commit eeac6151a55cb7d5f799e1ae33aa64a839cbc3aa, reversing
changes made to 5c40239d3104543e70508360d27584a3e4dc5baf.
Reason: Broke the isolated tests.
https://travis-ci.org/rails/rails/builds/188721346
|
|\ \
| | |
| | |
| | |
| | | |
mtsmfm/disable-referential-integrity-without-superuser-privileges
Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
privileges
ref: 72c1557254
- We must use `authors` fixture with `author_addresses` because of its foreign key constraint.
- Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
|
| | |
| | |
| | |
| | | |
provided.
|
| | | |
|
| | | |
|
|\ \ \
| |_|/
|/| | |
Add a record to target before any callbacks loads the record
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
`append_record` was added at 15ddd51 for not double adding the record.
But adding `append_record` (checking `@target.include?(record)`) caused
performance regression #27434. Instead of checking not double adding the
record, add a record to target before any callbacks loads the record.
Fixes #27434.
|
| | | |
|
|/ / |
|
| | |
|
|\ \
| | |
| | |
| | |
| | | |
kamipo/prevent_range_error_for_belongs_to_associations
Prevent `RangeError` for `belongs_to` associations
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Currently to access `belongs_to` associations raises a `RangeError` if
foreign key attribute has out of range value.
It should return a nil value rather than raising a `RangeError`.
Fixes #20140.
|
| |/
|/| |
|
| |
| |
| |
| |
| |
| |
| |
| | |
Fixes casting of IDs to the data type of the association primary key,
rather than then the data type of the model's primary key. (Tests use a
string primary key on the association, rather than an int.)
Tests issue #20995
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
9c9fb19 changed the behaviour of the _ids= setters for associations to
raise an AssociationTypeMismatch when unknown IDs are given:
Class: <ActiveRecord::AssociationTypeMismatch>
Message: <"Developer(#43811860) expected, got NilClass(#16732720)">
This restores the original ActiveRecord::RecordNotFound exception with a
much clearer error message:
Class: <ActiveRecord::RecordNotFound>
Message: <"Couldn't find all Developers with 'id': (1, -9999) [WHERE \"contracts\".\"company_id\" = ?] (found 1 results, but was looking for 2)">
Fixes #25719
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This patch brings back the functionality of passing true to the
association proxy. The behavior was deprecated with #20888 and scheduled
for removal in Rails 5.1.
The deprecation mentioned that instead of `Article.category(true)` one
should use `article#reload.category`. Unfortunately the alternative does
not expose the same behavior as passing true to the reader
did. Specifically reloading the parent record throws unsaved changes and
other caches away. Passing true only affected the association.
This is problematic and there is no easy workaround. I propose to bring
back the old functionality by introducing this new reader method for
singular associations.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Currently if `CollectionProxy` has more than one new record,
`CollectionProxy#uniq` result is incorrect.
And `CollectionProxy#uniq` was aliased to `distinct` in a1bb6c8b06db.
But the `uniq` method and the `SELECT DISTINCT` method are different
methods. The doc in `CollectionProxy` is for the `SELECT DISTINCT`
method, not for the `uniq` method.
Therefore, reverting the alias in `CollectionProxy` to fix the
inconsistency and to have the both methods.
|
| |
| |
| |
| |
| |
| | |
* Fixes TypeError when cache counter value equals nil
* Test case for counter cache on unloaded has_many association
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
With the changes in #25337, double save bugs are pretty much impossible,
so we can just lift this restriction with pretty much no change. There
were a handful of cases where we were relying on specific quirks in
tests that had to be updated. The change to has_one associations was due
to a particularly interesting test where an autosaved has_one
association was replaced with a new child, where the child failed to
save but the test wanted to check that the parent id persisted to `nil`.
I think this is almost certainly the wrong behavior, and I may change
that behavior later. But ultimately the root cause was because we never
remove the parent in memory when nullifying the child. This makes #23197
no longer needed, but it is what we'll do to fix some issues on 5.0
Close #23197
|
| | |
|
|\ \
| | |
| | |
| | | |
Fix for has_and_belongs_to_many & has_many_through associations
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
partial_writes is false
This will fix #19663
Also with this fix, active record does not fire unnecassary update queries while partial_writes is true
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Using Constant and symbol class_name option for associations are valid but raises exception on HABTM associations.
There was a test case which tries to cover symbol class_name usage but doesn't cover correctly. Fixed both symbol usage and constant usage as well.
These are all working as expected now;
```
has_and_belongs_to_many :foos, class_name: 'Foo'
has_and_belongs_to_many :foos, class_name: :Foo
has_and_belongs_to_many :foos, class_name: Foo
```
Closes #23767
|