aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/post.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
| * Make filter_binds filter out symbols that are equal to stringsNat Budin2014-05-141-0/+9
|/ | | | | | | | | | | | | 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.
* Get rid of unused method in AR Post test modelCarlos Antonio da Silva2014-05-051-4/+0
|
* Merge branch 'master' into adequaterecordAaron Patterson2014-04-251-0/+4
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * master: (28 commits) move AR length validation tests into separate test-case. No need for trailing slash on migration path. reset `@arel` when modifying a Relation in place. PostgreSQL Timestamps always map to `:datetime`. [ci skip] Improve formatting and yml Fix a typo in the doc of forty_two AR FinderMethod Improve readability of contributing to rails guide. [ci skip] Precompile the image we're referencing, too. `ActiveRecord::Base.no_touching` no longer triggers callbacks or start empty transactions. Fixed an issue with migrating legacy json cookies. Correct comment [ci skip] Perfer to define methods instead of calling test Fix syntax error Add CHANGELOG entry for #14757 [ci skip] Fix run-on sentences and improve grammar [skip ci] Add test for using ActionView::Helpers::FormHelper.label with block and html select! renamed to avoid name collision Array#select! Rearrange deck chairs on the titanic. Organize connection handling test cases. Change favicon_link_tag helper mimetype from image/vnd.microsoft.icon to image/x-icon. ActionController::Renderers documentation fix ...
| * Merge pull request #14573 from habermann24/has_many_through_fixRafael Mendonça França2014-04-221-0/+4
| |\ | | | | | | | | | | | | | | | | | | | | | Properly handle scoping with has_many :through. Fixes #14537. Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| | * Properly handle scoping with has_many :through. Fixes #14537.Jan Habermann2014-04-031-0/+4
| | |
* | | propogate bind values collected in arel to SQL generationAaron Patterson2014-04-111-0/+2
|/ /
* / CollectionProxy uses the arel of its association's scope.Jefferson Lai2014-04-021-0/+4
|/ | | | | | CollectionProxy should be able to reuse the behavior (methods) of its parent class, but with its own state. This change allows CollectionProxy to use the arel object corresponding to its association's scope.
* Skip `include_values` from through associations chains for building target scopePaul Nikitochkin2013-10-271-0/+3
| | | | Fixes: #12242, #9517, #10240
* More unused associations in AR test modelsAkira Matsuda2013-09-101-1/+0
|
* pk should not be required for hm:t associationsAaron Patterson2013-08-291-0/+8
|
* Revert "Merge branch 'master' of github.com:rails/docrails"Vijay Dev2013-08-171-0/+1
| | | | | | | This reverts commit 70d6e16fbad75b89dd1798ed697e7732b8606fa3, reversing changes made to ea4db3bc078fb3093ecdddffdf4f2f4ff3e1e8f9. Seems to be a code merge done by mistake.
* More unused associations in AR test modelsAkira Matsuda2013-07-251-1/+0
|
* Fix cases where delete_records on a has_many association caused errorsDerek Kraan2013-01-271-0/+5
| | | | | | | | | | | | | because of an ambiguous column name. This happened if the association model had a default scope that referenced a third table, and the third table also referenced the original table (with an identical foreign_key). Mysql requires that ambiguous columns are deambiguated by using the full table.column syntax. Postgresql and Sqlite use a different syntax for updates altogether (and don't tolerate table.name syntax), so the fix requires always including the full table.column and discarding it later for Sqlite and Postgresql.
* Unused test modelAkira Matsuda2013-01-241-5/+0
|
* Goodbye there, very special rubbish!Akira Matsuda2013-01-241-5/+1
|
* Unused model DeprecatedPostWithCommentAkira Matsuda2013-01-241-7/+0
|
* Merge pull request #8913 from ↵Carlos Antonio da Silva2013-01-201-0/+3
|\ | | | | | | | | seejee/regression_test_for_chained_preloaded_scopes Added test case to prevent regression of chained, preloaded scopes.
| * Added test case to prevent regression of chained, preloaded scopes. (#7490)Chris Geihsler2013-01-191-0/+3
| |
* | Undeprecate the :extend optionJon Leighton2013-01-181-0/+14
|/ | | | | | | Suggested by @dhh. It doesn't affect the generated SQL, so seems reasonable to continue to allow it as an association option.
* Revert "Fix find_in_batches with customized primary_key"Santiago Pastorino2012-09-211-5/+0
| | | | | | | This reverts commit 761bc751d31c22e2c2fdae2b4cdd435b68b6d783. This commit wasn't fixing any issue just using the same table for different models with different primary keys.
* Fix find_in_batches with customized primary_keyToshiyuki Kawanishi2012-09-161-0/+5
|
* Add a test to make sure preloading properly merges association and default ↵Pratik Naik2012-08-281-0/+3
| | | | scope conditions
* Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-271-3/+4
| | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* rm unnecessary testJon Leighton2012-07-201-4/+0
| | | | | interpolation is no longer a thing separate from "normal" assoc conditions.
* Convert association macros to the new syntaxJon Leighton2012-07-201-16/+17
|
* %s/find(:\(first\|last\|all\), \([^()]*\))/scoped(\2).\1/gcI amongst other ↵Jon Leighton2012-04-271-3/+3
| | | | things
* remove deprecated scope stuffJon Leighton2012-04-261-8/+1
|
* Deprecate eager-evaluated scopes.Jon Leighton2012-03-211-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Don't use this: scope :red, where(color: 'red') default_scope where(color: 'red') Use this: scope :red, -> { where(color: 'red') } default_scope { where(color: 'red') } The former has numerous issues. It is a common newbie gotcha to do the following: scope :recent, where(published_at: Time.now - 2.weeks) Or a more subtle variant: scope :recent, -> { where(published_at: Time.now - 2.weeks) } scope :recent_red, recent.where(color: 'red') Eager scopes are also very complex to implement within Active Record, and there are still bugs. For example, the following does not do what you expect: scope :remove_conditions, except(:where) where(...).remove_conditions # => still has conditions
* Add test case to has_many through association when mass_assignment_sanitizer isRafael Mendonça França2012-03-051-0/+2
| | | | :strict
* Fix #3890. (Calling proxy_association in scope chain.)Jon Leighton2011-12-081-1/+5
|
* don't change class definition in test caseJosh Susser2011-11-291-0/+4
|
* We need to recorder here. Need to drop the order from default scope.Arun Agrawal2011-09-051-0/+10
| | | Fixes #2832
* Test added for namedscope target.Arun Agrawal2011-06-031-0/+4
|