aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
Commit message (Collapse)AuthorAgeFilesLines
* have an actual `NullColumn` object and update docs accordingly.Yves Senn2014-06-041-4/+5
| | | | | | Follow up to #15438 and #15502. /cc @sgrif
* Use null column for association key typesSean Griffin2014-06-041-19/+21
|
* Return a null column when no column exists for an attributeSean Griffin2014-06-031-7/+9
|
* Remove most code related to serialized propertiesSean Griffin2014-06-011-5/+0
| | | | | | | | | | | Nearly completely implemented in terms of custom properties. `_before_type_cast` now stores the raw serialized string consistently, which removes the need to keep track of "state". The following is now consistently true: - `model.serialized == model.reload.serialized` - A model can be dumped and loaded infinitely without changing - A model can be saved and reloaded infinitely without changing
* Don't change values in `@raw_attributes` during serializationSean Griffin2014-06-011-1/+1
| | | | | | During `init_with`, the attributes given to the coder will be placed into `@raw_attributes`. As such, we should read from `@raw_attributes` when encoding, rather than `@attributes`, which has been type cast.
* Rename attribute related instance variables to better express intentSean Griffin2014-05-301-5/+5
| | | | | | | | | `@attributes` was actually used for `_before_type_cast` and friends, while `@attributes_cache` is the type cast version (and caching is the wrong word there, but I'm working on removing the conditionals around that). I opted for `@raw_attributes`, because `_before_type_cast` is also semantically misleading. The values in said hash are in the state given by the form builder or database, so raw seemed to be a good word.
* Merge pull request #15261 from hbin/missing_parametersRafael Mendonça França2014-05-231-1/+5
|\ | | | | Bring the missing parameters back.
| * Bring the missing parameters back.Bin Huang2014-05-231-1/+5
| |
* | Merge pull request #15282 from sgrif/sg-remove-column-primaryRafael Mendonça França2014-05-231-1/+1
|\ \ | | | | | | Remove `Column#primary`
| * | Remove `Column#primary`Sean Griffin2014-05-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | Avoid slowing down AR object initializationGodfrey Chan2014-05-221-0/+1
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 2d73f5a forces AR to enter the `define_attribute_methods` method whenever it instantiate a record from the `init_with` entry point. This is a potential performance hotspot, because `init_with` is called from all `find*` family methods, and `define_attribute_methods` is slow because it tries to acquire a lock on the mutex everytime it is entered. By using [DCL](http://en.wikipedia.org/wiki/Double-checked_locking), we can avoid grabbing the lock most of the time when the attribute methods are already defined (the common case). This is made possible by the fact that reading an instance variable is an atomic operation in Ruby. Credit goes to Aaron Patterson for pointing me to DCL and filling me in on the atomicity guarantees in Ruby. [*Godfrey Chan*, *Aaron Patterson*]
* | fix test from 7537057888d2d63c3b6c2019d5828bc445fbd6c9Aaron Patterson2014-05-221-0/+1
|/
* [ci skip]add updated information, ref[#522c0fd]Kuldeep Aggarwal2014-05-141-0/+2
|
* Update attribute_methods.rbGuillermo Iguaran2014-05-111-1/+1
| | | Improve documentation
* correcting method documentation [ci skip]Chris Beer2014-05-111-7/+7
|
* Block a few default Class methods as scope name.Arthur Neves2014-04-031-1/+3
| | | | | | Add tests to make sure scopes cannot be create with names such as: private, protected, public. Make sure enum values don't collide with those methods too.
* Fixes STI when 2+ levels deep.Arthur Neves2014-03-101-3/+3
| | | | | | PR #14052 Added a regression where it was only looking for methods in one level up, So when the method was defined in a 2+ levels up the inheritance chain, the method was not found as defined.
* Fixed STI classes not defining an attribute method if there is aGodfrey Chan2014-02-231-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | conflicting private method defined on its ancestors. The problem is that `method_defined_within?(name, klass, superklass)` only works correclty when `klass` and `superklass` are both `Class`es. If both `klass` and `superklass` are both `Class`es, they share the same inheritance chain, so if a method is defined on `klass` but not `superklass`, this method must be introduced at some point between `klass` and `superklass`. This does not work when `superklass` is a `Module`. A `Module`'s inheritance chain contains just itself. So if a method is defined on `klass` but not on `superklass`, the method could still be defined somewhere upstream, e.g. in `Object`. This fix works by avoiding calling `method_defined_within?` with a module while still fufilling the requirement (checking that the method is defined withing `superclass` but not is not a generated attribute method). 4d8ee288 is likely an attempted partial fix for this problem. This unrolls that fix and properly check the `superclass` as intended. Fixes #11569.
* Fixing issue with activerecord serialization not being able to dump a record ↵Mauricio Linhares2014-01-291-0/+5
| | | | after loading it from YAML - fixes #13861
* `scope` now raises on "dangerous" name conflictsGodfrey Chan2014-01-291-4/+22
| | | | | | | | | | Similar to dangerous attribute methods, a scope name conflict is dangerous if it conflicts with an existing class method defined within `ActiveRecord::Base` but not its ancestors. See also #13389. *Godfrey Chan*, *Philippe Creux*
* fix typos and grammar mistake [ci skip]nishant-cyro2013-12-191-1/+1
|
* Merge pull request #12403 from thedarkone/attr-method-missing-fixRafael Mendonça França2013-12-041-1/+18
|\ | | | | | | | | | | | | Fix AR#method_missing re-dispatching into overwritten attribute methods Conflicts: activerecord/lib/active_record/attribute_methods.rb
| * Fix AR#method_missing re-dispatching into overwritten attribute methods.thedarkone2013-09-291-1/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This was happening when a `super` call in an overwritten attribute method was triggering a method_missing fallback, because attribute methods haven't been generated yet. class Topic < ActiveRecord::Base def title # `super` would re-invoke this method if define_attribute_methods # hasn't been called yet resulting in double '!' appending super + '!' end end
* | short arrays in inspectJan Bernacki2013-10-301-3/+10
| |
* | always check to see if methods exist after calling define_attribute_methodsMatt Jones2013-10-241-6/+3
|/
* Use TS::Cache instead of Mutex + Hash.thedarkone2013-09-281-12/+8
| | | | TS::Cache#compute_if_absent guarantees that only a single thread will get to execute the provided block for a given key.
* Remove deprecation warning from attribute_missing Arun Agrawal2013-07-151-14/+0
| | | for attributes that are columns.
* Avoid creating an extra Range instanceAkira Matsuda2013-07-101-1/+1
|
* Fix: attribute_for_inspect truncate upto (51 => 50) characters.namusyaka2013-07-091-2/+2
|
* refactor the method cache objects to have a superclassAaron Patterson2013-07-031-0/+25
|
* move the reader method cache in to the read moduleAaron Patterson2013-07-031-48/+0
|
* keep a cache of the reader methods so we can reuse themAaron Patterson2013-07-031-0/+48
|
* freeze the constant value so it isn't duped when used as a hash keyAaron Patterson2013-07-021-1/+1
|
* stop storing multiple copies of a particular attribute nameAaron Patterson2013-07-021-12/+10
|
* eagerly assign the attribute name cache, remove const_missingAaron Patterson2013-07-021-2/+5
|
* initialize generated modules on inclusion and on inheritenceAaron Patterson2013-07-021-1/+1
|
* push attribute constant cache in to the attribute methods moduleAaron Patterson2013-07-021-1/+9
|
* lock around mutating the generated methods moduleAaron Patterson2013-07-021-2/+4
|
* remove private attribute readerAaron Patterson2013-07-021-6/+2
|
* define attribute methods in a thread safe mannerAaron Patterson2013-07-021-5/+4
|
* we don't need to use active support *everwhere* common.Aaron Patterson2013-07-021-1/+1
|
* initialize ivars so we don't have to constantly check themAaron Patterson2013-07-021-1/+3
|
* eagerly initialize the attributes module to avoid check-then-set race conditionsAaron Patterson2013-07-021-1/+12
|
* fixes a test, and explains why AR::AttributeMethods checks ↵Xavier Noria2013-04-281-0/+3
| | | | defined?(@attributes) in some places
* ActiveRecord -> Active RecordXavier Noria2013-04-251-1/+1
|
* fixes warning in the AR test suiteXavier Noria2013-04-251-1/+1
|
* if singletons belong to the contract, test themXavier Noria2013-04-201-1/+1
| | | | | | Object#respond_to? returns singletons and thus we inherit that contract. The implementation of the predicate is good, but the test is only checking boolean semantics, which in this case is not enough.
* fix respond_to? for non selected columnNeeraj Singh2013-04-191-1/+13
| | | | | | | | | | | | | | | | | | | | | | | fixes #4208 If a query selects only a few columns and gives custom names to those columns then respond_to? was returning true for the non selected columns. However calling those non selected columns raises exception. post = Post.select("'title' as post_title").first In the above case when `post.body` is invoked then an exception is raised since `body` attribute is not selected. Howevere `respond_to?` did not behave correctly. pos.respond_to?(:body) #=> true Reason was that Active Record calls `super` to pass the call to Active Model and all the columns are defined on Active Model. Fix is to actually check if the data returned from the db contains the data for column in question.
* Fixed typos in activerecordPrathamesh Sonpatki2013-03-271-1/+1
|
* When we pass id to update_attributes it will try to set new id for that recordDmitry Vorotilin2013-03-221-1/+1
|