| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
| |
These methods are defined in inheritance.rb
* `abstract_class?`
* `descends_from_active_record?`
* `compute_type`
|
|
|
|
|
|
|
| |
This reverts commit 60c9701269f5b412849f1a507df61ba4735914d7, reversing
changes made to 6a25202d9ea3b4a7c9f2d6154b97cf8ba58403db.
Reason: Broken build
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This triggers the JoinDependency work to reflect on the associations
and trigger an error as follows:
ActiveRecord::ConfigurationError: Association named 'account' was
not found on Company; perhaps you misspelled it?
Fix Company.of_first_firm joins association name
Should be `Company.joins(:accounts)` not `Company.joins(:account)`.
Do the same for Client.of_first_firm
|
|
|
|
|
|
|
| |
This can resolve confusing situation when a top level constant exists
but a namespaced version is identified.
Related to #19531.
|
|\
| |
| |
| |
| |
| |
| | |
https://github.com/agrobbin/rails into agrobbin-sti-subclass-from-attributes
Conflicts:
activerecord/CHANGELOG.md
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
If your STI class looks like this:
```ruby
class Company < ActiveRecord::Base
self.store_full_sti_class = false
class GoodCo < Company
end
class BadCo < Company
end
end
```
The expectation (which is valid) is that the `type` in the database is saved as
`GoodCo` or `BadCo`. However, another expectation should be that setting `type`
to `GoodCo` would correctly instantiate the object as a `Company::GoodCo`. That
second expectation is what this should fix.
|
|
|
|
|
|
|
|
|
| |
Make sure that tests do not hardcode the default value.
For example `test_instantiation_doesnt_try_to_require_corresponding_file`
always restored the configuration to `true` regardless of what it's
original value was.
Extract a helper to make the global modification consistent across tests.
|
|
|
|
|
|
|
|
|
|
| |
When ```becomes``` changes @attributes it should also change
@changed_attributes. Otherwise we'll experience a kind of split head situation
where attributes are coming from ```self```, but changed_attributes is coming
from ```klass.new```. This affects the inheritance_colmn as it's changed by new
for example.
Fixes #16881
|
| |
|
|
|
|
|
|
|
|
|
|
| |
This will allow eager type casting to take place as needed. There
doesn't seem to be any particular reason that the `in` statement was
forced for single values, and the commit message where it was introduced
gives no context.
See
https://github.com/rails/rails/commit/d90b4e2615e8048fdeffc6dffe3246704adee01f
|
|
|
|
|
|
|
| |
We added a comparison to "id", and call to `self.class.primary_key` a
*lot*. We also have performance hits from `&block` all over the place.
We skip the check in a new method, in order to avoid breaking the
behavior of `read_attribute`
|
| |
|
|
|
|
|
|
|
|
| |
Follow-Up to https://github.com/rails/rails/pull/14348
Ensure that SQLCounter.clear_log is called after each test.
This is a step to prevent side effects when running tests. This will allow us to run them in random order.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This commit fixes two regressions introduced in cafe31a078 where
newly created finder methods #second, #third, #forth, and #fifth
caused a NoMethodError error on reload associations and where we
were pulling the wrong element out of cached associations.
Examples:
some_book.authors.reload.second
# Before
# => NoMethodError: undefined method 'first' for nil:NilClass
# After
# => #<Author id: 2, name: "Sally Second", ...>
some_book.first.authors.first
some_book.first.authors.second
# Before
# => #<Author id: 1, name: "Freddy First", ...>
# => #<Author id: 1, name: "Freddy First", ...>
# After
# => #<Author id: 1, name: "Freddy First", ...>
# => #<Author id: 2, name: "Sally Second", ...>
Fixes #13783.
|
|
|
|
|
|
|
| |
The `subclass_from_attrs` method is called even if the column specified by
the `inheritance_column` setting doesn't exist. This prevents setting associations
via the attributes hash if the association name clashes with the value of the setting,
typically `:type`. This worked previously in Rails 3.2.
|
| |
|
| |
|
|
|
|
| |
Related issue: #11939, #12084
|
| |
|
|
|
|
|
| |
These tests should be in inheritance_test.rb since its testing a
feature which is implemented in inheritance.rb
|
|
|
|
|
|
| |
assertion for
https://github.com/rails/rails/blob/ad624345e54bd20802de67b2b5c9ef29ecf5
d5f4/activerecord/lib/active_record/inheritance.rb#L32
|
|
|
|
|
| |
It cannot find subclass because all classes are loaded automatically
when it needs.
|
| |
|
|
|
|
|
|
|
|
| |
Allows you to do BaseClass.new(:type => "SubClass") as well as
parent.children.build(:type => "SubClass") or parent.build_child
to initialize an STI subclass. Ensures that the class name is a
valid class and that it is in the ancestors of the super class
that the association is expecting.
|
|
|
|
|
|
|
|
|
|
| |
In the end I think the pain of implementing this seamlessly was not
worth the gain provided.
The intention was that it would allow plain ruby objects that might not
live in your main application to be subclassed and have persistence
mixed in. But I've decided that the benefit of doing that is not worth
the amount of complexity that the implementation introduced.
|
|
|
|
|
| |
All tests with a custom inheritance_column use the `Vegtable` model.
The field ruby_type on the Company models is no longer needed
|
|
|
|
|
|
| |
previously the tests with and without a custom `inheritance_column`
used the same models. Since the model then has both fields this can lead
to false positives.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
I had to create a new table because I needed an STI table,
which does not have both a "type" and a "custom_type"
the test fails with:
1) Error:
test_alt_becomes_works_with_sti(InheritanceTest):
NoMethodError: undefined method `type=' for #<Cabbage id: 1, name: "my cucumber", custom_type: "Cucumber">
/Users/username/Projects/rails/activemodel/lib/active_model/attribute_methods.rb:432:in `method_missing'
/Users/username/Projects/rails/activerecord/lib/active_record/attribute_methods.rb:100:in `method_missing'
/Users/username/Projects/rails/activerecord/lib/active_record/persistence.rb:165:in `becomes'
test/cases/inheritance_test.rb:134:in `test_becomes_works_with_sti'
test/cases/inheritance_test.rb:140:in `test_alt_becomes_works_with_sti'
|
|
|
|
|
| |
On reflection, it seems like a bit of a weird method to have on
ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
|
|
|
|
|
|
|
| |
It doesn't serve much purpose now that ActiveRecord::Base.all returns a
Relation.
The code is moved to active_record_deprecated_finders.
|
|
|
|
|
|
|
|
|
|
|
| |
Previously it returned an Array.
If you want an array, call e.g. `Post.to_a` rather than `Post.all`. This
is more explicit.
In most cases this should not break existing code, since
Relations use method_missing to delegate unknown methods to #to_a
anyway.
|
|
|
|
|
|
|
|
|
| |
Moved logic from class_of_active_record_descendant(class) to the
base_class method. This method was confusing because it required
an argument, but that argument was 'self'.
Moved base_class tests to inheritance_test.rb and added some test
coverage for some untested cases.
|
| |
|
| |
|
|
|
|
| |
things
|
| |
|
|
|
|
|
| |
This is the 'top level' connection, inherited by any models that include
ActiveRecord::Model or inherit from ActiveRecord::Base.
|
| |
|
| |
|
|
|
|
| |
RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases.
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
with_exclusive_scope. A few examples:
* with_scope now should be scoping:
Before:
Comment.with_scope(:find => { :conditions => { :post_id => 1 } }) do
Comment.first #=> SELECT * FROM comments WHERE post_id = 1
end
After:
Comment.where(:post_id => 1).scoping do
Comment.first #=> SELECT * FROM comments WHERE post_id = 1
end
* with_exclusive_scope now should be unscoped:
class Post < ActiveRecord::Base
default_scope :published => true
end
Post.all #=> SELECT * FROM posts WHERE published = true
Before:
Post.with_exclusive_scope do
Post.all #=> SELECT * FROM posts
end
After:
Post.unscoped do
Post.all #=> SELECT * FROM posts
end
Notice you can also use unscoped without a block and it will return an anonymous scope with default_scope values:
Post.unscoped.all #=> SELECT * FROM posts
|
|
|
|
|
|
| |
[#4652 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
|
|
|
|
| |
reflecting the previously announced Rails 3 default [DHH]
|
|\
| |
| |
| |
| |
| | |
Conflicts:
activerecord/test/cases/adapter_test.rb
activerecord/test/cases/method_scoping_test.rb
|