aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attributes.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add docs and changelog entry for 73aab03 [ci skip]Sean Griffin2015-05-301-1/+10
|
* Persist user provided default values, even if unchangedSean Griffin2015-05-281-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a usability change to fix a quirk from our definition of partial writes. By default, we only persist changed attributes. When creating a new record, this is assumed that the default values came from the database. However, if the user provided a default, it will not be persisted, since we didn't see it as "changed". Since this is a very specific case, I wanted to isolate it with the other quirks that come from user provided default values. The number of edge cases which are presenting themselves are starting to make me wonder if we should just remove the ability to assign a default, in favor of overriding `initialize`. For the time being, this is required for the attributes API to not have confusing behavior. We had to delete one test, since this actually changes the meaning of `.changed?` on Active Record models. It now specifically means `changed_from_database?`. While I think this will make the attributes API more ergonomic to use, it is a subtle change in definition (though not a backwards incompatible one). We should probably figure out the right place to document this. (Feel free to open a PR doing that if you're reading this). /cc @rafaelfranca @kirs @senny This is an alternate implementation of #19921. Close #19921. [Sean Griffin & Kir Shatrov]
* Allow proc defaults with the Attributes APISean Griffin2015-05-281-1/+7
| | | | | | | | | | | | This is a variant implementation of the changes proposed in #19914. Unlike that PR, the change in behavior is isolated in its own class. This is to prevent wonky behavior if a Proc is assigned outside of the default, and it is a natural place to place the behavior required by #19921 as well. Close #19914. [Sean Griffin & Kir Shatrov]
* Some documentation edits [ci skip]Robin Dupret2015-03-051-9/+11
| | | | | | * Fix a few typos * Wrap some lines around 80 chars * Rephrase some statements
* Add docs for the type registrySean Griffin2015-02-171-3/+11
|
* `type_cast_from_user` -> `cast`Sean Griffin2015-02-171-4/+4
|
* `type_cast_for_database` -> `serialize`Sean Griffin2015-02-171-2/+2
|
* `Type#type_cast_from_database` -> `Type#deserialize`Sean Griffin2015-02-171-3/+3
|
* Register adapter specific types with the global type registrySean Griffin2015-02-151-1/+1
| | | | | | We do this in the adapter classes specifically, so the types aren't registered if we don't use that adapter. Constants under the PostgreSQL namespace for example are never loaded if we're using mysql.
* Missing `@` [ci skip]Ryuta Kamizono2015-02-081-1/+1
|
* Document the usage of the default option to attributeSean Griffin2015-02-061-0/+14
|
* A symbol can be passed to `attribute`, which should be documentedSean Griffin2015-02-061-3/+4
|
* Grammar and RDoc formattingSean Griffin2015-02-061-21/+23
|
* Docs pass for the attributes APISean Griffin2015-02-061-16/+112
|
* Allow a symbol to be passed to `attribute`, in place of a type objectSean Griffin2015-02-061-3/+10
| | | | | | | | | | | | | | | | | | The same is not true of `define_attribute`, which is meant to be the low level no-magic API that sits underneath. The differences between the two APIs are: - `attribute` - Lazy (the attribute will be defined after the schema has loaded) - Allows either a type object or a symbol - `define_attribute` - Runs immediately (might get trampled by schema loading) - Requires a type object This was the last blocker in terms of public interface requirements originally discussed for this feature back in May. All the implementation blockers have been cleared, so this feature is probably ready for release (pending one more look-over by me).
* Rename `user_provided_types` to something more meaningfulSean Griffin2015-02-021-4/+4
| | | | | | | `attributes_to_define_after_schema_loads` better describes the difference between `attribute` and `define_attribute`, and doesn't conflate terms since we no longer differentiate between "user provided" and "schema provided" types.
* Attribute assignment and type casting has nothing to do with columnsSean Griffin2015-01-311-57/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Change 'a' to 'an' for 'attribute' word [ci skip]Santosh Wadghule2015-01-211-1/+1
|
* Don't attempt to save dirty attributes which are not persistableSean Griffin2015-01-101-0/+7
| | | | | | | | | | | | | | | | This sets a precident for how we handle `attribute` calls, which aren't backed by a database column. We should not take this as a conscious decision on how to handle them, and this can change when we make `attribute` public if we have better ideas in the future. As the composed attributes API gets fleshed out, I expect the `persistable_attributes` method to change to `@attributes.select(&:persistable).keys`, or some more performant variant there-of. This can probably go away completely once we fully move dirty checking into the attribute objects once it gets moved up to Active Model. Fixes #18407
* Extract an explicit type caster classSean Griffin2014-12-291-0/+1
|
* docs, replace ` with + for proper rdoc output. [ci skip]Yves Senn2014-12-231-2/+2
|
* Don't modify the columns hash to set defaults from the attributes APISean Griffin2014-10-311-3/+20
| | | | | Nothing is directly using the columns for the default values anymore. This step helps us get closer not not mutating the columns hash.
* Simplify creation of default attributes on AR instanceSean Griffin2014-06-291-2/+1
| | | | `AttributeSet#dup` has all the behavior we need.
* add missing `:nodoc:` for recent refactorings. [ci skip]Yves Senn2014-06-241-1/+1
| | | | | | | | | | Adding `# :nodoc:` to the parent `class` / `module` is not going to ignore nested classes or modules. There is a modifier `# :nodoc: all` but sadly the containing class or module will continue to be in the docs. /cc @sgrif
* Small typoAnton Cherepanov2014-06-231-1/+1
|
* Introduce an object to aid in creation and management of `@attributes`Sean Griffin2014-06-191-4/+5
| | | | | Mostly delegation to start, but we can start moving a lot of behavior in bulk to this object.
* Rename `property` to `attribute`Sean Griffin2014-06-071-0/+122
| | | | For consistency with https://github.com/rails/rails/pull/15557
* Revert "Refactoring attributes/types" [#3348 state:open]Pratik Naik2010-01-221-37/+0
| | | | | | | | | | | | | | | | | This reverts commit f936a1f100e75082081e782e5cceb272885c2df7. Conflicts: activerecord/lib/active_record.rb activerecord/lib/active_record/base.rb Revert "Fixed: #without_typecast should only disable typecasting on the duplicated attributes" [#3387 state:open] This reverts commit 2831996483c6a045f1f38d8030256eb58d9771c3. Reason : It's not generating attribute methods properly, making object.column 5x slower.
* Refactoring attributes/types [#3348 state:resolved]Eric Chapweske2009-10-171-0/+37
Signed-off-by: Joshua Peek <josh@joshpeek.com>