aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/model_schema.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Implement ActiveRecord::Base.ignored_columnsJean Boussier2015-09-241-1/+8
|
* introduce `conn.data_source_exists?` and `conn.data_sources`.Yves Senn2015-09-221-2/+2
| | | | | | | | | | | | | | | | | These new methods are used from the Active Record model layer to determine which relations are viable to back a model. These new methods allow us to change `conn.tables` in the future to only return tables and no views. Same for `conn.table_exists?`. The goal is to provide the following introspection methods on the connection: * `tables` * `table_exists?` * `views` * `view_exists?` * `data_sources` (views + tables) * `data_source_exists?` (views + tables)
* Replace AR with ActiveRecord to make it more readable [ci skip]arvind2015-09-081-1/+1
|
* Return a `Point` object from the PG Point typeSean Griffin2015-06-051-0/+23
| | | | | | | | | | | | | | | | | | | This introduces a deprecation cycle to change the behavior of the default point type in the PostgreSQL adapter. The old behavior will continue to be available for the immediate future as `:legacy_point`. The current behavior of returning an `Array` causes several problems, the most significant of which is that we cannot differentiate between an array of points, and a point itself in the case of a column with the `point[]` type. The attributes API gives us a reasonable way to have a proper deprecation cycle for this change, so let's take advantage of it. If we like this change, we can also add proper support for the other geometric types (line, lseg, box, path, polygon, and circle), all of which are just aliases for string today. Fixes #20441
* remove duplicatesKoen Punt2015-04-031-4/+0
|
* rm `Column#cast_type`Sean Griffin2015-02-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The type from the column is never used, except when being passed to the attributes API. While leaving the type on the column wasn't necessarily a bad thing, I worry that it's existence there implies that it is something which should be used. During the design and implementation process of the attributes API, there have been plenty of cases where getting the "right" type object was hard, but I had easy access to the column objects. For any contributor who isn't intimately familiar with the intents behind the type casting system, grabbing the type from the column might easily seem like the "correct" thing to do. As such, the goal of this change is to express that the column is not something that should be used for type casting. The only places that are "valid" (at the time of this commit) uses of acquiring a type object from the column are fixtures (as the YAML file is going to mirror the database more closely than the AR object), and looking up the type during schema detection to pass to the attributes API Many of the failing tests were removed, as they've been made obsolete over the last year. All of the PG column tests were testing nothing beyond polymorphism. The Mysql2 tests were duplicating the mysql tests, since they now share a column class. The implementation is a little hairy, and slightly verbose, but it felt preferable to going back to 20 constructor options for the columns. If you are git blaming to figure out wtf I was thinking with them, and have a better idea, go for it. Just don't use a type object for this.
* Attribute assignment and type casting has nothing to do with columnsSean Griffin2015-01-311-20/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Restore useful documentation removed atRafael Mendonça França2015-01-271-0/+6
| | | | | | 3729103e17e00494c8eae76e8a4ee1ac990d3450 [ci skip]
* Update model_schema.rb [ci skip]Takehiro Adachi2015-01-271-20/+0
| | | | | | | Overriding these methods may cause unexpected results since "table_name=" does more then just setting the "@table_name". ref: https://github.com/rails/rails/pull/18622#issuecomment-70874358
* Extract an explicit type caster classSean Griffin2014-12-291-0/+1
|
* Inject the `PredicateBuilder` into the `Relation` instanceSean Griffin2014-12-261-0/+1
| | | | | | | Construction of relations can be a hotspot, we don't want to create one of these in the constructor. This also allows us to do more expensive things in the predicate builder's constructor, since it's created once per AR::Base subclass
* 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
|