aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
Commit message (Collapse)AuthorAgeFilesLines
* Improve consistency of counter caches updating in memorySean Griffin2015-01-261-1/+1
| | | | | | | | | | | | | | | | | When we made sure that the counter gets updated in memory, we only did it on the has many side. The has many side only does the update if the belongs to cannot. The belongs to side was updated to update the counter cache (if it is able). This means that we need to check if the belongs_to is able to update in memory on the has_many side. We also found an inconsistency where the reflection names were used to grab the association which should update the counter cache. Since reflection names are now strings, this means it was using a different instance than the one which would have the inverse instance set. Fixes #18689 [Sean Griffin & anthonynavarre]
* remove deprecated support to preload instance-dependent associaitons.Yves Senn2015-01-051-4/+0
| | | | Addresses https://github.com/rails/rails/commit/ed56e596a0467390011bc9d56d462539776adac1#commitcomment-9145960
* Add has_secure_token to Active Recordrobertomiranda2015-01-041-0/+4
| | | | | | Update SecureToken Docs Add Changelog entry for has_secure_token [ci skip]
* Deprecate `false` as the way to halt AR callbacksclaudiob2015-01-025-5/+5
| | | | | | | | | | Before this commit, returning `false` in an ActiveRecord `before_` callback such as `before_create` would halt the callback chain. After this commit, the behavior is deprecated: will still work until the next release of Rails but will also display a deprecation warning. The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
* Merge pull request #15309 from iantropov/issue_12698_build_throughRafael Mendonça França2015-01-021-0/+2
|\ | | | | | | | | | | | | | | Add setting of FK for throgh associations while building Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * Add setting of FK for throgh associations while buildingIvan Antropov2014-05-251-0/+2
| |
* | Fix error message when trying to create an associated recordRafael Mendonça França2014-12-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | This error only happens when the foreign key is missing. Before this fix the following exception was being raised: NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218> Now the message is: ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
* | AR specific length validator to respect `marked_for_destruction`.Yves Senn2014-12-301-0/+2
| | | | | | | | | | | | | | | | Closes #7247. Conflicts: activerecord/CHANGELOG.md activerecord/test/models/owner.rb
* | Remove all cases of manuallly wrapping `Arel::Nodes::Quoted`Sean Griffin2014-12-291-1/+1
| | | | | | | | | | | | | | | | | | | | 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.
* | Inform Arel we don't need additional type casting in testsSean Griffin2014-12-261-1/+1
| | | | | | | | | | | | | | Part of the larger refactoring to remove type casting from Arel. We can inform it that we already have the right type by wrapping the value in an `Arel::Nodes::Quoted`. This commit can be reverted when we have removed type casting from Arel in Rail 5.1
* | Don't perform statement caching for `find` when called from a scopeSean Griffin2014-12-221-0/+8
| | | | | | | | | | | | | | | | If there is a method defined such as `find_and_do_stuff(id)`, which then gets called on an association, we will perform statement caching and the parent ID will not change on subsequent calls. Fixes #18117
* | Add foreign_type option for polymorphic has_one and has_many.Ulisses Almeida + Kassio Borges2014-12-082-0/+6
| | | | | | | | | | | | | | To be possible to use a custom column name to save/read the polymorphic associated type in a has_many or has_one polymorphic association, now users can use the option :foreign_type to inform in what column the associated object type will be saved.
* | Fix "nonexistent" typo in testsMelissa Xie2014-12-022-4/+4
| |
* | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-293-4/+4
| |
* | Fix includes on association with a scope containing joins along with conditionssiddharth@vinsol.com2014-11-211-0/+1
| | | | | | | | on the joined assoiciation
* | Ensure HABTM relationships produce valid class names (Fixes #17119)Sammy Larbi2014-11-091-0/+2
| |
* | Use bind values for joined tables in where statementsSean Griffin2014-11-012-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In practical terms, this allows serialized columns and tz aware columns to be used in wheres that go through joins, where they previously would not behave correctly. Internally, this removes 1/3 of the cases where we rely on Arel to perform type casting for us. There were two non-obvious changes required for this. `update_all` on relation was merging its bind values with arel's in the wrong order. Additionally, through associations were assuming there would be no bind parameters in the preloader (presumably because the where would always be part of a join) [Melanie Gilman & Sean Griffin]
* | Raise an error for has_one associations which try to go :through a ↵Tu Hoang2014-10-151-0/+3
| | | | | | | | polymorphic association [#17263]
* | make sure cache is not used for collection assocations tooAaron Patterson2014-10-141-0/+1
| | | | | | | | follow up for #17052
* | Autosave callbacks shouldn't be `after_save`Agis-2014-10-131-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | 068f092ced8483e557725542dd919ab7c516e567 registered autosave callbacks as `after_save` callbacks. This caused the regression described in #17209. Autosave callbacks should be registered as `after_update` and `after_create` callbacks, just like before. This is a partial revert of 068f092ced8483e557725542dd919ab7c516e567. Fixes #17209.
* | Better regression test for Fixtures with fk as a symbolArthur Neves2014-09-221-1/+1
| |
* | Dynamically modified schema and association would not be correctly resetAkira Matsuda2014-09-062-0/+6
| | | | | | | | | | This fixes <"SQLite3::SQLException: no such column: legacy_things.person_id: SELECT \"legacy_things\".* FROM \"legacy_things\" WHERE \"legacy_things\".\"person_id\" = ?"> in OptimisticLockingTest#test_lock_destroy
* | Skip StatementCache for eager loaded associations (Fixes #16761)Sammy Larbi2014-09-042-0/+11
| | | | | | | | | | | | Eagerly loaded collection and singular associations are ignored by the StatementCache, which causes errors when the queries they generate reference columns that were not eagerly loaded. This commit skips the creation of the StatementCache as a fix for these scenarios.
* | Move association definition to the model fileAkira Matsuda2014-08-281-0/+1
| |
* | Only merge scopes with zero arity in has_many throughAgis-2014-08-202-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with dynamic conditions. Fixes #16128 This bug was introduced in https://github.com/rails/rails/commit/c35e438620f2d56562251571377995359546393d so it's present from 4.1.2-rc1 and after. https://github.com/rails/rails/commit/c35e438620f2d56562251571377995359546393d merges any relation scopes passed as proc objects to the relation, but does *not* take into account the arity of the lambda. To reproduce: https://gist.github.com/Agis-/5f1f0d664d2cd08dfb9b
* | Fixes the `Relation#exists?` to work with polymorphic associations.Kassio Borges2014-08-181-0/+1
| | | | | | | | Fixes #15821.
* | Address ORA-00972: identifier is too long when tested with OracleYasuo Honda2014-07-142-2/+3
| | | | | | | | by using shorter attribute names.
* | Move writing unknown column exception to null attributeSean Griffin2014-06-261-0/+1
| | | | | | | | | | | | Making this change revealed several subtle bugs related to models with no primary key, and anonymous classes. These have been fixed as well, with regression tests added.
* | Deprecate automatic counter caches on has_many :throughSean Griffin2014-06-262-2/+2
| | | | | | | | | | | | | | | | | | | | | | Reliant on https://github.com/rails/rails/pull/15747 but pulled to a separate PR to reduce noise. `has_many :through` associations have the undocumented behavior of automatically detecting counter caches. However, the way in which it does so is inconsistent with counter caches everywhere else, and doesn't actually work consistently. As with normal `has_many` associations, the user should specify the counter cache on the `belongs_to`, if they'd like it updated.
* | Merge pull request #15772 from nbudin/sti_through_bugRafael Mendonça França2014-06-191-0/+7
|\ \ | | | | | | | | | Don't include inheritance column in the through_scope_attributes
| * | Don't include inheritance column in the through_scope_attributesNat Budin2014-06-171-1/+8
| | |
* | | Fix has_and_belongs_to_many in a namespaced model pointing to a non ↵Rafael Mendonça França2014-06-191-0/+1
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | namespaced model Now the following case will work fine class Tag < ActiveRecord::Base end class Publisher::Article < ActiveRecord::Base has_and_belongs_to_many :tags end Fixes #15761
* | Merge pull request #15343 from dontfidget/fix_polymorphic_automatic_inverse_ofRafael Mendonça França2014-06-132-0/+2
|\ \ | | | | | | prevent bad automatic inverse_of association
| * | use name specified by 'as' for automatic inverse association to avoid ↵Andrew S. Brown2014-06-102-0/+2
| |/ | | | | | | reflecting on wrong association
* / Fix regression on eager loading association based on SQL query ratherLauro Caetano2014-06-031-0/+12
|/ | | | | | than existing column. Fixes #15480.
* Revert "Merge pull request #14544 from jefflai2/named_scope_sti"Rafael Mendonça França2014-05-212-5/+0
| | | | | | | | | | | | This reverts commit 9a1abedcdeecd9464668695d4f9c1d55a2fd9332, reversing changes made to c72d6c91a7c0c2dc81cc857a1d6db496e84e0065. Conflicts: activerecord/CHANGELOG.md activerecord/test/models/comment.rb This change break integration with activerecord-deprecated_finders so I'm reverting until we find a way to make it work with this gem.
* build fix, use lambda syntax that ruby 1.9.3 understands.Yves Senn2014-05-211-1/+1
|
* Fix polymorphic eager load with foreign_key as String.Lauro Caetano2014-05-201-0/+3
| | | | | | | | | The foreign_key could be `String` and just doing `owners_map[owner_key]` could return `nil`. To prevent this bug, we should `to_s` both keys if their types are different. Fixes #14734.
* Merge pull request #14544 from jefflai2/named_scope_stiRafael Mendonça França2014-05-202-0/+5
|\ | | | | | | | | | | | | Fixes Issue #13466. Conflicts: activerecord/CHANGELOG.md
| * Fixes Issue #13466.Jefferson Lai2014-04-232-0/+5
| | | | | | | | | | | | Changed the call to a scope block to be evaluated with instance_eval. The result is that ScopeRegistry can use the actual class instead of base_class when caching scopes so queries made by classes with a common ancestor won't leak scopes.
* | test, inline `DeveloperWithAggregate`, which is used by a single test.Yves Senn2014-05-191-6/+0
| |
* | Merge pull request #14871 from kassio/kb-fixes-namespaced-habtmRafael Mendonça França2014-05-143-0/+8
|\ \ | | | | | | | | | | | | | | | | | | Fix how to compute class name on habtm namespaced. Conflicts: activerecord/CHANGELOG.md
| * | Fix how to compute class name on habtm namespaced.Kassio Borges2014-05-133-0/+8
| | | | | | | | | | | | | | | | | | Thank's for @laurocaetano for the help with tests. :smiley: Fixes #14709
* | | Merge pull request #15078 from nbudin/fix_merger_filter_binds_comparison_masterRafael Mendonça França2014-05-142-0/+17
|\ \ \ | |/ / |/| | | | | | | | | | | | | | Make filter_binds filter out symbols that are equal to strings Conflicts: activerecord/CHANGELOG.md
| * | Make filter_binds filter out symbols that are equal to stringsNat Budin2014-05-142-0/+17
|/ / | | | | | | | | | | | | | | | | | | | | | | | | ActiveRecord::Relation::Merger's filter_binds method does not filter out bind variables when one of the attribute nodes has a string name, but the other has a symbol name, even when those names are actually equal. This can result in there being more bind variables than placeholders in the generated SQL. This is particularly an issue for PostgreSQL, where this is treated as an error. This patch changes the filter_binds method to make it convert both attribute names to strings before comparing.
* | Fix broken proc syntax for 1.9.3Arthur Neves2014-05-091-1/+1
| |
* | test, regression test for has_many with instance dependent scope.Yves Senn2014-05-091-0/+2
| |
* | Fixed HABTM's CollectionAssociation sizeFred Wu2014-05-081-0/+2
| | | | | | | | | | HABTM should fall back to using the normal CollectionAssociation's size calculation if the collection is not cached or loaded. This addresses both #14913 and #14914 for master.
* | Add support for module-level table_suffix in modelsJenner LaFave2014-05-051-0/+18
| | | | | | | | | | This makes table_name_suffix work the same as table_name_prefix when using namespaced models. Pretty much the same as 67d1cec.
* | Merge pull request #14978 from bogdan/relation-joinRafael Mendonça França2014-05-051-0/+4
|\ \ | | | | | | | | | [Regression 4.0 -> 4.1] Put back Relation#join method as a delegate to Array