aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/model_schema.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Remove unused `@relation` instance variableSean Griffin2014-12-261-2/+0
| | | | We don't memoize the relation instance
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* Reduce the amount of work performed when instantiating AR modelsSean Griffin2014-11-141-1/+1
| | | | | | | | | | We don't know which attributes will or won't be used, and we don't want to create massive bottlenecks at instantiation. Rather than doing *any* iteration over types and values, we can lazily instantiate the object. The lazy attribute hash should not fully implement hash, or subclass hash at any point in the future. It is not meant to be a replacement, but instead implement its own interface which happens to overlap.
* Don't modify the columns hash to set defaults from the attributes APISean Griffin2014-10-311-1/+5
| | | | | Nothing is directly using the columns for the default values anymore. This step helps us get closer not not mutating the columns hash.
* Rename `default_attributes` to `_default_attributes`Sean Griffin2014-10-311-2/+2
| | | | | It is internal use only. This is to avoid conflicting with users' method names. Fixes #17458
* Change `gsub` to `tr` where possibleAlexander Balashov2014-10-061-1/+1
|
* Remove defunct ivarsBen Woosley2014-09-281-10/+7
| | | | @column_names_with_alias, @dynamic_methods_hash, @time_zone_column_names, and @cached_time_zone
* create_join_table uses same logic as HABTM reflectionsStefan Kanev2014-07-181-0/+11
| | | | | | | | Before this change, create_join_table would not remove the common prefix in the join table name, unlike ActiveRecord::Reflections. A HABTM between Music::Artist and Music::Record would use a table music_artists_records, while create_join table would create music_artists_music_records.
* Simplify creation of default attributes on AR instanceSean Griffin2014-06-291-13/+7
| | | | `AttributeSet#dup` has all the behavior we need.
* Merge pull request #15801 from sgrif/sg-column-defaultsRafael Mendonça França2014-06-191-2/+2
|\ | | | | Don't use column object when calculating type cast defaults
| * Don't use column object when calculating type cast defaultsSean Griffin2014-06-181-2/+2
| | | | | | | | Moves towards removing type casting knowledge from the column entirely
* | Introduce an object to aid in creation and management of `@attributes`Sean Griffin2014-06-191-2/+8
|/ | | | | Mostly delegation to start, but we can start moving a lot of behavior in bulk to this object.
* Don't type cast the default on the columnSean Griffin2014-06-171-4/+6
| | | | | | | If we want to have type decorators mess with the attribute, but not the column, we need to stop type casting on the column. Where possible, we changed the tests to test the value of `column_defaults`, which is public API. `Column#default` is not.
* Promote time zone aware attributes to a first class type decoratorSean Griffin2014-06-161-19/+1
| | | | | | | | | | | | | This refactoring revealed the need for another form of decoration, which takes a proc to select which it applies to (There's a *lot* of cases where this form can be used). To avoid duplication, we can re-implement the old decoration in terms of the proc-based decoration. The reason we're `instance_exec`ing the matcher is for cases such as time zone aware attributes, where a decorator is defined in a parent class, and a method called in the matcher is overridden by a child class. The matcher will close over the parent, and evaluate in its context, which is not the behavior we want.
* Ensure `column_types` returns a type object, and not a columnSean Griffin2014-06-111-6/+10
|
* Make `_before_type_cast` actually be before type castSean Griffin2014-06-091-1/+7
| | | | | | | | | | | | | - The following is now true for all types, all the time - `model.attribute_before_type_cast == given_value` - `model.attribute == model.save_and_reload.attribute` - `model.attribute == model.dup.attribute` - `model.attribute == YAML.load(YAML.dump(model)).attribute` - Removes the remaining types implementing `type_cast_for_write` - Simplifies the implementation of time zone aware attributes - Brings tz aware attributes closer to being implemented as an attribute decorator - Adds additional point of control for custom types
* Keep column defaults in type cast formSean Griffin2014-06-031-0/+9
| | | | | | | | | | The contract of `_field_changed?` assumes that the old value is always type cast. That is not the case for the value in `Column#default` as things are today. It appears there are other public methods that assume that `Column#default` is type cast, as well. The reason for this change originally was because the value gets put into `@raw_attributes` in initialize. This reverts to the old behavior on `Column`, and updates `initialize` to make sure that the values are in the right format.
* Remove unused `initialize_attributes` methodSean Griffin2014-06-021-7/+0
| | | | | This was previously a hook for a special case related to `serialize`, which has since been removed.
* Refactor serialized types to be partially defined as custom propertiesSean Griffin2014-05-291-9/+0
| | | | | | | Many of the methods defined in `AttributeMethods::Serialization` can be refactored onto this type as well, but this is a reasonable small step. Removes the `Type` class, and the need for `decorate_columns` to handle serialized types.
* Add a public API to allow users to specify column typesSean Griffin2014-05-261-10/+0
| | | | | | | | | | | | | | | | | | | | | | | | As a result of all of the refactoring that's been done, it's now possible for us to define a public API to allow users to specify behavior. This is an initial implementation so that I can work off of it in smaller pieces for additional features/refactorings. The current behavior will continue to stay the same, though I'd like to refactor towards the automatic schema detection being built off of this API, and add the ability to opt out of automatic schema detection. Use cases: - We can deprecate a lot of the edge cases around types, now that there is an alternate path for users who wish to maintain the same behavior. - I intend to refactor serialized columns to be built on top of this API. - Gem and library maintainers are able to interact with `ActiveRecord` at a slightly lower level in a more stable way. - Interesting ability to reverse the work flow of adding to the schema. Model can become the single source of truth for the structure. We can compare that to what the database says the schema is, diff them, and generate a migration.
* Remove `Column#primary`Sean Griffin2014-05-231-9/+3
| | | | | | | | 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.
* Remove dead test code for unsupported adaptersSean Griffin2014-05-171-1/+1
|
* Add support for module-level table_suffix in modelsJenner LaFave2014-05-051-1/+10
| | | | | This makes table_name_suffix work the same as table_name_prefix when using namespaced models. Pretty much the same as 67d1cec.
* added schema_migrations_table_name to ActiveRecord::Base in order that the ↵Jerad Phelps2013-10-271-0/+6
| | | | | | | | | | | | | | | | | | | | name of the schema migrations table can be configured. consolidated test_schema_migrations_table_name tests Added changelog entry edited changelog removed commented lines removed reader ensure the schema migrations table is reset at end of test added entry to configuration guide guides typo and changelog order
* Perf: memoize serialized column list and time zone column listSam2013-08-271-17/+27
|
* add a specific factory method rather than using newAaron Patterson2013-07-231-1/+1
|
* removes the obsolete private method column_methods_hash [Closes #11406]Xavier Noria2013-07-161-13/+0
|
* safely publish columns and columns hash infoAaron Patterson2013-03-141-1/+1
|
* Fix decorating columns for serialized attributesitzki2012-12-101-4/+3
|
* 1.9 Syntax related changesAvnerCohen2012-11-101-1/+1
|
* Remove ActiveRecord::ModelJon Leighton2012-10-261-24/+23
| | | | | | | | | | 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.
* Get rid of the ActiveRecord::Model::DeprecationProxy thing.Jon Leighton2012-10-191-1/+1
| | | | | | | | | | | | | | | | | I think it's going to be too much pain to try to transition the :active_record load hook from executing against Base to executing against Model. For example, after Model is included in Base, and modules included in Model will no longer get added to the ancestors of Base. So plugins which wish to be compatible with both Model and Base should use the :active_record_model load hook which executes *before* Base gets loaded. In general, ActiveRecord::Model is an advanced feature at the moment and probably most people will continue to inherit from ActiveRecord::Base for the time being.
* Minor refactoring in Active Record model schema methodsCarlos Antonio da Silva2012-08-211-5/+3
| | | | | | * Use each_key instead of generating intermediate keys array. * Use each_with_object instead of inject to build hash. * Use ternary to return instead of if + assignment.
* The default value can be set once in #column_defaultsJon Leighton2012-08-171-0/+7
| | | | Rather than doing it every time an instance is instantiated.
* load active_support/concern in active_support/railsXavier Noria2012-08-021-1/+0
|
* Refactor to reset_table_nameDmitry Vorotilin2012-07-281-8/+4
|
* Simplify AR configuration code.Jon Leighton2012-06-151-9/+14
| | | | | Get rid of ActiveModel::Configuration, make better use of ActiveSupport::Concern + class_attribute, etc.
* Fix wrong return value from reset_sequence_name method.kennyj2012-04-141-1/+1
|
* Don't reset inheritance_column when setting explicitly.kennyj2012-03-081-1/+2
|
* Revert table_name= needs connection now, so just stub table_namekennyj2012-03-071-1/+1
|
* tidy up formattingJon Leighton2012-03-041-10/+11
|
* Don't clear sequence name when we explicitly assign it.kennyj2012-03-041-2/+4
|
* Fix GH #4674. Reset column information and sequence name when setting ↵kennyj2012-03-041-4/+11
| | | | table_name.
* Remove unusused variablesJon Leighton2012-03-041-9/+6
|
* give each PG type a `type` method and decortate tz attributesAaron Patterson2012-02-071-5/+17
|
* wrap and cache columns for typecastingAaron Patterson2012-02-071-3/+18
|
* call to_s on value passed to table_name=Sergey Nartimov2012-01-261-1/+1
|
* Fix table_name in ActiveRecord with more than one abstract ancestorsPiotr Sarnacki2012-01-121-3/+7
| | | | | | | | | | | | | | | | | When subclassing abstract_class table_name should be always computed based on class name, no matter if superclass is subclassing base or another abstract_class. So: class FirstAbstract < ActiveRecord::Base self.abstract_class = true end class SecondAbstract < FirstAbstract self.abstract_class = true end class Post < SecondAbstract self.table_name #=> 'posts' (not 'second_abstracts') end
* Support establishing connection on ActiveRecord::Model.Jon Leighton2011-12-281-5/+1
| | | | | This is the 'top level' connection, inherited by any models that include ActiveRecord::Model or inherit from ActiveRecord::Base.