aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/inheritance.rb
Commit message (Collapse)AuthorAgeFilesLines
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-1/+1
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* [ci skip] Update Documentation on ActiveRecord::InheritanceAlex Kitchens2016-06-231-1/+2
|
* Defer Arel attribute lookup to the model classMatthew Draper2016-02-041-1/+1
| | | | | This still isn't as separated as I'd like, but it at least moves most of the burden of alias mapping in one place.
* Do not use default attributes for STI when instantiating a subclassSean Griffin2016-01-271-1/+5
| | | | | | | | | | The commit which originally added this behavior did not consider that doing `Subclass.new` does not actually populate the `type` field in the attributes (though perhaps it should). We simply need to not use the defaults for STI related things unless we are instantiating the base class. Fixes #23285.
* run `type` column through attribtues API type casting.Yves Senn2016-01-191-0/+1
| | | | | | | Closes #21986. This makes it possible to write custom types that define a different mapping for STI columns.
* Remove old comment about AC::Parameters>subclassesclaudiob2015-12-021-2/+0
| | | | | | | | | | | | [ci skip] Q: What happens if you initialize an AR model by passing Parameters that have not been whitelisted with `permit`? A: An `ActiveModel::ForbiddenAttributesError` is raised. I think this behavior is correct, and it's better than what used to happen, with unpermitted parameter being simply ignored.
* don't rely on the columns hash to get defaults. follow-up to #17169.Yves Senn2015-12-021-7/+1
| | | | | | This will also get the defaults from attribute definitions like: attribute :type, :string, default: "SomethingElse"
* add `ActiveRecord::Base.has_attribute?`Yves Senn2015-12-021-2/+2
| | | | `has_attribute?` method to check wether a given attribute has been defined.
* Merge pull request #17169 from kuldeepaggarwal/fix-STI-default-typeYves Senn2015-12-021-9/+13
|\ | | | | | | STI cast new instances to `default type` on initialize.
| * STI cast new instances to `default type` on initialize.Kuldeep Aggarwal2015-12-021-0/+12
|/ | | | fixes #17121
* Update and fix forbidden attributes testsThomas Walpole2015-11-031-1/+2
| | | | Add AC::Parameters tests for WhereChain#not
* Fix a stylistic nitpick in #19501Sean Griffin2015-10-291-3/+3
| | | | | | | We don't need to use `String#+` or create all the intermediate strings to break a string into multiple lines. We can just write a c-style multiline string literal. This is by no means a hotpath, but this is clearer to me anyway.
* Fix test failures caused by #19501Sean Griffin2015-10-291-1/+1
| | | | | | | | | | | | | | | | | | | | | The first one is quite straightforward. We want to give the proper error message in the case where a top level constant exists, but we're looking for a nested one. We just need to port over the change to use `subclass.name` into these changes. The second set of failures, which are only present in the mysql adapter tests, are stranger to me. The failure occurs because we were previously comparing `subclass.name == self.name` instead of `subclass == self`. However, I don't think that we need to support creating anonymous classes which share a table with a class that uses STI, overrides `name` to return the same name as athe class that we have no other relationship with, when not assigned to a constant so it could never be used anyway... The commits around why that exist give no context, and I think they're just poorly written tests (WTF does `test_schema` mean anyway, and why does calling `.first` on some anonymous class test it?). We'll just disable STI on that class.
* Fix merge conflicts from #19501Sean Griffin2015-10-291-20/+18
|\ | | | | | | | | | | | | | | I'm making this commit separately because this has failing tests and style nitpicks that I'd like to make as individual commits, to make the changes I'm making explicit. We still want a single merge commit at the end, however.
| * DRY up STI subclass logicCody Cutrer2015-03-241-19/+19
| | | | | | | | | | | | | | | | | | | | | | the newer method used for discriminating new records did not use the older and more robust method used for instantiating existing records, but did have a better post-check to ensure the sublass was in the hierarchy. so move the descendants check to find_sti_class, and then simply call find_sti_class from subclass_from_attributes now with fixed specs
* | Replace AR with ActiveRecord to make it more readable [ci skip]arvind2015-09-081-1/+1
| |
* | invalid sti error message contains the full class name.Yves Senn2015-05-131-1/+1
| | | | | | | | | | | | | | This can resolve confusing situation when a top level constant exists but a namespaced version is identified. Related to #19531.
* | allow setting of a demodulized class name when using STIAlex Robbin2015-05-111-6/+8
|/ | | | | | | | | | | | | | | | | | | | | 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.
* Revert "Merge pull request #19500 from ccutrer/dry_sti_subclass_finding"Rafael Mendonça França2015-03-241-19/+19
| | | | | | | This reverts commit 5cfa6a8ab997089c3012a82052c8c317b2e095f5, reversing changes made to bfd5bf8313e6ea0bb2eccb68ee5076bb63f0b2db. Reason: This broken travis build.
* DRY up STI subclass logicCody Cutrer2015-03-241-19/+19
| | | | | | | | | the newer method used for discriminating new records did not use the older and more robust method used for instantiating existing records, but did have a better post-check to ensure the sublass was in the hierarchy. so move the descendants check to find_sti_class, and then simply call find_sti_class from subclass_from_attributes
* Attribute assignment and type casting has nothing to do with columnsSean Griffin2015-01-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's finally finished!!!!!!! The reason the Attributes API was kept private in 4.2 was due to some publicly visible implementation details. It was previously implemented by overloading `columns` and `columns_hash`, to make them return column objects which were modified with the attribute information. This meant that those methods LIED! We didn't change the database schema. We changed the attribute information on the class. That is wrong! It should be the other way around, where schema loading just calls the attributes API for you. And now it does! Yes, this means that there is nothing that happens in automatic schema loading that you couldn't manually do yourself. (There's still some funky cases where we hit the connection adapter that I need to handle, before we can turn off automatic schema detection entirely.) There were a few weird test failures caused by this that had to be fixed. The main source came from the fact that the attribute methods are now defined in terms of `attribute_names`, which has a clause like `return [] unless table_exists?`. I don't *think* this is an issue, since the only place this caused failures were in a fake adapter which didn't override `table_exists?`. Additionally, there were a few cases where tests were failing because a migration was run, but the model was not reloaded. I'm not sure why these started failing from this change, I might need to clear an additional cache in `reload_schema_from_cache`. Again, since this is not normal usage, and it's expected that `reset_column_information` will be called after the table is modified, I don't think it's a problem. Still, test failures that were unrelated to the change are worrying, and I need to dig into them further. Finally, I spent a lot of time debugging issues with the mutex used in `define_attribute_methods`. I think we can just remove that method entirely, and define the attribute methods *manually* in the call to `define_attribute`, which would simplify the code *tremendously*. Ok. now to make this damn thing public, and work on moving it up to Active Model.
* Remove deprecated `symbolized_base_class` and `symbolized_sti_name`Rafael Mendonça França2015-01-041-10/+0
|
* Remove all cases of manuallly wrapping `Arel::Nodes::Quoted`Sean Griffin2014-12-291-1/+0
| | | | | | | | | | This is no longer required now that we are injecting a type caster object into the Arel table, with the exception of uniqueness validations. Since it calls `ConnectionAdapter#type_cast`, the value has already been cast for the database. We don't want Arel to attempt to cast it further, so we need to continue wrapping it in a quoted node. This can potentially go away when this validator is refactored to make better use of `where` or the predicate builder.
* We don't need to perform type casting on the STI conditionSean Griffin2014-12-261-0/+1
| | | | | | | We will always have the correct type for this query, so no casting is needed. We inform Arel that we already have the right type by wrapping it in an `Arel::Nodes::Quoted` (which we will no longer need to do in Rails 5.1)
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* Revert "Improve performance of AR object instantiation"Sean Griffin2014-11-141-8/+4
| | | | | | | | | | This reverts commit 8fee923888192a658d8823b31e77ed0683dfd665. Conflicts: activerecord/lib/active_record/attribute_set/builder.rb This solution sucks, and is hard to actually apply across the board. Going to try other solutions
* Improve performance of AR object instantiationSean Griffin2014-11-051-4/+8
| | | | | | | We introduced a performance hit by adding an additional iteration through a model's attributes on creation. We don't actually need the values from `Result` to be a hash, we can separate the columns and values and zip them up ourself during the iteration that we have to do.
* edit pass over all warningsXavier Noria2014-10-281-2/+2
| | | | | | | | | | | | | | | This patch uniformizes warning messages. I used the most common style already present in the code base: * Capitalize the first word. * End the message with a full stop. * "Rails 5" instead of "Rails 5.0". * Backticks for method names and inline code. Also, converted a few long strings into the new heredoc convention.
* Merge pull request #15762 from arthurnn/better_error_on_bad_alias_methodMatthew Draper2014-07-181-8/+2
|\ | | | | | | Dont swallow errors when bad alias_method
| * Dont swallow errors when bad alias_methodArthur Neves2014-06-241-8/+2
| |
* | Tiny follow-up to #15987 and 088b4c3e [ci skip]Robin Dupret2014-07-021-4/+4
| |
* | Move STI docs off of the main Base document, leaving a noteSean Griffin2014-06-301-0/+31
|/
* Move changed_attributes into dirty.rbKeenan Brock2014-01-221-0/+10
| | | Move serialization dirty into serialization.rb
* Don't try to get the subclass if the inheritance column doesn't existUjjwal Thaakar2014-01-141-7/+15
| | | | | | | 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.
* Set NameError#nameChulki Lee2014-01-131-1/+1
|
* Change all "can not"s to the correct "cannot".T.J. Schuck2014-01-031-1/+1
|
* Deprecate unused `symbolized_base_class` and `symbolized_sti_name`.Yves Senn2014-01-031-0/+2
| | | | | | | These methods were only used for the `IdentityMap` which was removed. They are no longer used internally and should be removed without replacement. As they were not `:nodoc:`'ed it's better to deprecate them before removal.
* no need to to_symAaron Patterson2013-10-091-1/+1
|
* minor comments cleanupNeeraj Singh2013-05-271-3/+4
|
* let Ruby do the is_a check for usAaron Patterson2013-05-161-3/+4
|
* Fix #new with an STI object with complex inheritanceNate Berkopec2013-04-021-1/+1
|
* Avoid short-circuit returnRafael Mendonça França2013-03-081-5/+9
|
* Merge pull request #9497 from route/subclass_from_attrsRafael Mendonça França2013-03-081-2/+3
|\ | | | | | | | | | | | | Fix ActiveRecord `subclass_from_attrs` when eager_load is false. Conflicts: activerecord/CHANGELOG.md
| * Fix ActiveRecord `subclass_from_attrs` when eager_load is false.Dmitry Vorotilin2013-03-061-2/+3
| | | | | | | | | | It cannot find subclass because all classes are loaded automatically when it needs.
* | More helpful error message when instantiating an abstract classAaron Weiner2013-03-031-0/+3
|/ | | | | | | | | | Calling a literal ActiveRecord::Base.new raises NoMethodError, since it ends up calling Class.abstract_class? which does not exist. Similarly, instantiating an actual abstract class hits the database, when conventionally it should immediately throw NotImplementedError. ActiveRecord::Base can't be made abstract without breaking many, many things, so check for it separately.
* Missing requireAkira Matsuda2013-01-071-0/+2
|
* Move instantiation responsibilities from Inheritance to Persistence. Have ↵Jeremy Kemper2012-11-291-24/+24
| | | | Inheritance#discriminate_class_for_record handle STI lookup duties.
* Added STI support to init and building associationsJason Rush2012-11-291-0/+26
| | | | | | | | 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.
* Remove ActiveRecord::ModelJon Leighton2012-10-261-29/+12
| | | | | | | | | | 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.
* Revert "Get rid of the ActiveRecord::Model::DeprecationProxy thing."Jeremy Kemper2012-10-201-1/+1
| | | | This reverts commit 83846838252397b3781eed165ca301e05db39293.