aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/post.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fixed reselect throwing NoMethodError on ActiveRecord.Abhay Nikam2019-03-031-0/+6
|
* Use the correct model in the testRafael Mendonça França2019-03-011-1/+1
| | | | | This was using a model without a default scope what made the test don't break anymore if the code is removed.
* Fix test that was broken by adding a default scope to an existing modelRafael Mendonça França2019-02-261-0/+1
|
* Fix `order` with custom attributesRyuta Kamizono2019-02-171-0/+4
| | | | This follows up 0ee96d13de29680e148ccb8e5b68025f29fd091c.
* Fix `pluck` and `select` with custom attributesRyuta Kamizono2019-02-131-0/+1
| | | | | | | | | Currently custom attributes are always qualified by the table name in the generated SQL wrongly even if the table doesn't have the named column, it would cause an invalid SQL error. Custom attributes should only be qualified if the table has the same named column.
* Fix the scoping with query methods in the scope blockRyuta Kamizono2018-11-301-0/+1
| | | | | | | | | Follow up #33394. #33394 only fixes the case of scoping with klass methods in the scope block which invokes `klass.all`. Query methods in the scope block also need to invoke `klass.all` to be affected by the scoping.
* Generate delegation methods to named scope in the definition timeRyuta Kamizono2018-10-091-2/+6
| | | | | | | | | | | | | | | | | | | The delegation methods to named scope are defined when `method_missing` is invoked on the relation. Since #29301, the receiver in the named scope is changed to the relation like others (e.g. `default_scope`, etc) for consistency. Most named scopes would be delegated from relation by `method_missing`, since we don't allow scopes to be defined which conflict with instance methods on `Relation` (#31179). But if a named scope is defined with the same name as any method on the `superclass` (e.g. `Kernel.open`), the `method_missing` on the relation is not invoked. To address the issue, make the delegation methods to named scope is generated in the definition time. Fixes #34098.
* Permit list usage cleanup and clearer documentationKevin Deisz2018-08-271-1/+1
|
* Convert over the rest of the whitelist referencesKevin Deisz2018-08-241-1/+1
|
* Avoid extra scoping in delegating to klass methods in the `scope` blockRyuta Kamizono2018-07-191-0/+1
| | | | | | | | | | Since #29301, delegating to klass methods in the `scope` block would cause extra scoping by the receiver itself. The extra scoping would always override intermediate scoping like `unscoped` and caused the regression #33387. To keep the original scoping behavior, should avoid the extra scoping in the `scope` block. Fixes #33387.
* Avoid passing unnecessary arguments to relationDaniel Colson2018-01-241-0/+8
| | | | | | | | | | | | Most of the time the table and predicate_builder passed to Relation.new are exactly the arel_table and predicate builder of the given klass. This uses klass.arel_table and klass.predicate_builder as the defaults, so we don't have to pass them in most cases. This does change the signaure of both Relation and AssocationRelation. Are we ok with that?
* Don't update counter cache when through record was not destroyedEugene Kenny2018-01-141-0/+3
| | | | | | When removing a record from a has many through association, the counter cache was being updated even if the through record halted the callback chain and prevented itself from being destroyed.
* try using regexesBen Toews2017-11-091-5/+1
|
* allow table name and direction in string order argBen Toews2017-11-091-3/+7
|
* work around deprecation warnings in a bunch of testsBen Toews2017-11-091-4/+8
|
* delegate scope forpavel2017-10-271-0/+1
|
* Add test case for `arel_attribute` with a custom tableRyuta Kamizono2017-09-271-1/+1
| | | | Since #29301, `arel_attribute` respects a custom table name.
* Clarify base_class tests on abstract STI vs concrete STIYukio Mizuta2017-08-121-1/+6
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Merge pull request #29679 from kamipo/add_test_case_for_27724Kasper Timm Hansen2017-07-151-0/+5
|\ | | | | Add a test case for overwriting existing condition on associations
| * Add a test case for overwriting existing condition on associationsRyuta Kamizono2017-07-071-0/+5
| | | | | | | | | | | | | | | | Overwriting existing condition on associations has already supported (23bcc65 for eager loading, 2bfa2c0 for preloading). Fixes #27724. Closes #29154.
* | Extract `FakeKlass` in `relation_test.rb` and `relation/mutation_test.rb`Ryuta Kamizono2017-07-111-0/+32
|/ | | | | `FakeKlass` in `relation_test.rb` and `relation/mutation_test.rb` are almost the same.
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Remove delegating to arel in a relationRyuta Kamizono2017-06-291-0/+1
| | | | | The delegation was needed since passing `relation` with `relation.bound_attributes`. It should use `relation.arel` in that case.
* Fix association with extension issuesRyuta Kamizono2017-05-281-1/+1
| | | | | | | | This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association.
* Fix extension method with dirty target in has_many associationsRyuta Kamizono2017-03-201-0/+4
| | | | | | | Extension methods should not delegate to `scope` to respect dirty target on `CollectionProxy`. Fixes #28419.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-3/+3
|
* Merge pull request #24099 from k0kubun/preserve-readonlyRafael Mendonça França2016-08-181-0/+1
|\ | | | | | | Preserve readonly flag only for readonly association
| * Preserve readonly flag only for readonly associationTakashi Kokubun2016-07-301-0/+1
| | | | | | | | Fixes #24093
* | Add three new rubocop rulesRafael Mendonça França2016-08-161-7/+7
| | | | | | | | | | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* | modernizes hash syntax in activerecordXavier Noria2016-08-061-66/+66
| |
* | applies new string literal convention in activerecord/testXavier Noria2016-08-061-38/+38
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Skip the STI condition when evaluating a default scopeMatthew Draper2016-01-121-0/+7
| | | | | | | | | | | | | Given a default_scope on a parent of the current class, where that parent is not the base class, the parent's STI condition would become attached to the evaluated default scope, and then override the child's own STI condition. Instead, we can treat the STI condition as though it is a default scope, and skip it in this situation: the scope will be merged into the base relation, which already contains the correct STI condition. Fixes #22426.
* Fix merge conflicts from #19501Sean Griffin2015-10-291-0/+7
|\ | | | | | | | | | | | | | | I'm making this commit separately because this has failing tests and style nitpicks that I'd like to make as individual commits, to make the changes I'm making explicit. We still want a single merge commit at the end, however.
| * DRY up STI subclass logicCody Cutrer2015-03-241-0/+7
| | | | | | | | | | | | | | | | | | | | | | the newer method used for discriminating new records did not use the older and more robust method used for instantiating existing records, but did have a better post-check to ensure the sublass was in the hierarchy. so move the descendants check to find_sti_class, and then simply call find_sti_class from subclass_from_attributes now with fixed specs
* | Merge pull request #19683 from tristang/require-option-for-counter-cacheRafael Mendonça França2015-08-131-4/+4
|\ \ | | | | | | | | | Require explicit counter_cache option for has_many
| * | Require explicit counter_cache option for has_manyTristan Gamilis2015-04-071-4/+4
| |/ | | | | | | | | | | | | | | | | | | Previously has_many associations assumed a counter_cache was to be used based on the presence of an appropriately named column. This is inconsistent, since the inverse belongs_to association will not make this assumption. See issues #19042 #8446. This commit checks for the presence of the counter_cache key in the options of either the has_many or belongs_to association as well as ensuring that the *_count column is present.
* / Fix regression caused by a01d164bRafael Mendonça França2015-07-071-0/+16
|/ | | | | | | | | When preload is used in a default scope the preload_values were returning nested arrays and causing the preloader to fail because it doesn't know how to deal with nested arrays. So before calling preload! we need to splat the arguments. This is not needed to includes because it flatten its arguments.
* Added #or to ActiveRecord::RelationMatthew Draper2015-01-281-0/+3
| | | | | | | Post.where('id = 1').or(Post.where('id = 2')) # => SELECT * FROM posts WHERE (id = 1) OR (id = 2) [Matthew Draper & Gael Muller]
* 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 foreign_type option for polymorphic has_one and has_many.Ulisses Almeida + Kassio Borges2014-12-081-0/+3
| | | | | | | 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-021-1/+1
|
* Fix includes on association with a scope containing joins along with conditionssiddharth@vinsol.com2014-11-211-0/+1
| | | | on the joined assoiciation
* Use bind values for joined tables in where statementsSean Griffin2014-11-011-0/+4
| | | | | | | | | | | | | | | 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]
* 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.
* Skip StatementCache for eager loaded associations (Fixes #16761)Sammy Larbi2014-09-041-0/+6
| | | | | | 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.
* Fixes the `Relation#exists?` to work with polymorphic associations.Kassio Borges2014-08-181-0/+1
| | | | Fixes #15821.
* Deprecate automatic counter caches on has_many :throughSean Griffin2014-06-261-1/+1
| | | | | | | | | | | 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 #15078 from nbudin/fix_merger_filter_binds_comparison_masterRafael Mendonça França2014-05-141-0/+9
|\ | | | | | | | | | | | | Make filter_binds filter out symbols that are equal to strings Conflicts: activerecord/CHANGELOG.md