aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
Commit message (Collapse)AuthorAgeFilesLines
* Created a method to automatically find inverse associations and cachewangjohn2013-05-075-5/+5
| | | | | | the results. Added tests to check to make sure that inverse associations are automatically found when has_many, has_one, or belongs_to associations are defined.
* Handle aliased attributes in ActiveRecord::Relation.Godfrey Chan2013-05-011-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database: With the model class Topic alias_attribute :heading, :title end The call Topic.where(heading: 'The First Topic') should yield the same result as Topic.where(title: 'The First Topic') This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`. This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`. Github #7839 *Godfrey Chan*
* Fix scope chaining + STIJon Leighton2013-04-051-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | See #9869 and #9929. The problem arises from the following example: class Project < ActiveRecord::Base scope :completed, -> { where completed: true } end class MajorProject < Project end When calling: MajorProject.where(tasks_count: 10).completed This expands to: MajorProject.where(tasks_count: 10).scoping { MajorProject.completed } However the lambda for the `completed` scope is defined on Project. This means that when it is called, `self` is Project rather than MajorProject. So it expands to: MajorProject.where(tasks_count: 10).scoping { Project.where(completed: true) } Since the scoping was applied on MajorProject, and not Project, this fails to apply the tasks_count condition. The solution is to make scoping apply across STI classes. I am slightly concerned about the possible side-effects of this, but no tests fail and it seems ok. I guess we'll see.
* failing test for #9869Neeraj Singh2013-04-051-0/+1
|
* has_many through obeys order on through associationNeeraj Singh2013-04-041-1/+1
| | | | fixes #10016
* Add missing require to inheritance testCarlos Antonio da Silva2013-04-031-2/+0
|
* Update other counter caches on destroyIan Young2013-03-202-4/+6
|
* Refactor Person/Friendship relationships to be more intuitiveMack Earnhardt2013-03-172-2/+7
| | | | | | | | PR #5210 added a Friendship model to illustrate a bug, but in doing so created a confusing structure because both belongs_to declarations in Friendship referred to the same side of the join. The new structure maintains the integrity of the bug test while changing the follower relationship to be more useful for other testing.
* rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works.Yves Senn2013-03-154-11/+10
| | | | | | | | The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our Relation API is close to SQL terms I renamed `#uniq` to `#distinct`. There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue to work. I also updated the documentation to promote the use of `#distinct`.
* Merge pull request #9497 from route/subclass_from_attrsRafael Mendonça França2013-03-081-0/+2
|\ | | | | | | | | | | | | Fix ActiveRecord `subclass_from_attrs` when eager_load is false. Conflicts: activerecord/CHANGELOG.md
| * Fix ActiveRecord `subclass_from_attrs` when eager_load is false.Dmitry Vorotilin2013-03-061-0/+2
| | | | | | | | | | It cannot find subclass because all classes are loaded automatically when it needs.
* | test case for `serialize` default values.Yves Senn2013-03-071-0/+1
|/ | | | Closes #9110
* test case to prevent duplicated associations with custom PK.Yves Senn2013-02-241-0/+2
| | | | closes #9201
* define Active Record Store accessors in a moduleSergey Nartimov2013-02-111-0/+9
| | | | | | | | | | | | | Allow store accessors to be overrided like other attribute methods, e.g.: class User < ActiveRecord::Base store :settings, accessors: [ :color, :homepage ], coder: JSON def color super || 'red' end end
* Prevent Relation#merge from collapsing wheres on the RHSJon Leighton2013-01-272-0/+2
| | | | | | | | | | | | | | | | | | | | | | | This caused a bug with the new associations implementation, because now association conditions are represented as Arel nodes internally right up to when the whole thing gets turned to SQL. In Rails 3.2, association conditions get turned to raw SQL early on, which prevents Relation#merge from interfering. The current implementation was buggy when a default_scope existed on the target model, since we would basically end up doing: default_scope.merge(association_scope) If default_scope contained a where(foo: 'a') and association_scope contained a where(foo: 'b').where(foo: 'c') then the merger would see that the same column is representated on both sides of the merge and collapse the wheres to all but the last: where(foo: 'c') Now, the RHS of the merge is left alone. Fixes #8990
* Fix cases where delete_records on a has_many association caused errorsDerek Kraan2013-01-272-0/+6
| | | | | | | | | | | | | 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.
* Describing the reason for defining BlankTopic#blank? which will never be calledAkira Matsuda2013-01-241-0/+1
|
* Revert "Unused methods, module, etc."Akira Matsuda2013-01-244-0/+28
| | | | | | This reverts commit 4e05bfb8e254c3360a3ca4a6cb332995314338fe. Reason: BlankTopic#blank? should not be removed to check that dynamic finder with a bang can find a model that responds to `blank?`
* Unused methods, module, etc.Akira Matsuda2013-01-244-28/+0
|
* Unused test modelAkira Matsuda2013-01-241-5/+0
|
* Goodbye there, very special rubbish!Akira Matsuda2013-01-244-19/+1
|
* proxy_{owner,reflection,target} are no more availableAkira Matsuda2013-01-241-11/+1
|
* Unused model DeprecatedPostWithCommentAkira Matsuda2013-01-241-7/+0
|
* Remove warning by using a custom coderAndrew White2013-01-231-2/+16
| | | | | | | | | | | | | | The native JSON library bypasses the `to_json` overrides in active_support/core_ext/object/to_json.rb by calling its native implementation directly. However `ActiveRecord::Store` uses a HWIA so `JSON.dump` will call our `to_json` instead with a `State` object for options rather than a `Hash`. This generates a warning when the `:encoding`, `:only` & `:except` keys are accessed in `Hash#as_json` because the `State` object delegates unknown keys to `instance_variable_get` in its `:[]` method. Workaround this warning in the test by using a custom coder that calls `ActiveSupport::JSON.encode` directly.
* 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
| |
* | Merge pull request #8994 from Springest/fix_default_scope_update_all_delete_allJon Leighton2013-01-181-0/+9
|\ \ | | | | | | Fix .update_all and .delete_all when using a condition on a joined table in a default_scope
| * | Fix .update_all and .delete_all when using a condition on a joined tableDerek Kraan2013-01-111-0/+9
| |/ | | | | | | | | | | | | | | | | in a default_scope. `Model.joins(...).where(condition_on_joined_table).update_all` / `delete_all` worked, but the same operation implemented with a default_scope generated a SQL error because ActiveRecord ignored the join but implemented the where condition anyways.
* / 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.
* Rename update_attributes method to update, keep update_attributes as an aliasAmparo Luna + Guillermo Iguaran2013-01-031-1/+1
|
* unused scopeAkira Matsuda2013-01-021-2/+0
|
* Fix broken test for postgresqlRafael Mendonça França2012-12-211-1/+1
| | | | | | For some reason postgresql doesn't pass an integer value to load. cc @tenderlove
* Serialized attribute can be serialized in an integer columnRafael Mendonça França2012-12-211-0/+21
| | | | Fix #8575
* Allow users to choose the timestamp format in the cache keyRafael Mendonça França2012-12-101-0/+5
| | | | | | | This can be done using the class attribute cache_timestamp_format Conflicts: railties/guides/source/configuring.textile
* Make sure the tests pass in the case closer to described in #8195Rafael Mendonça França2012-12-101-1/+1
| | | | | | Conflicts: activerecord/test/models/bulb.rb activerecord/test/schema/schema.rb
* Do not instantiate intermediate AR objects when eager loading.Yves Senn2012-12-041-0/+10
| | | | Closes #3313
* Added STI support to init and building associationsJason Rush2012-11-292-0/+2
| | | | | | | | Allows you to do BaseClass.new(:type => "SubClass") as well as parent.children.build(:type => "SubClass") or parent.build_child to initialize an STI subclass. Ensures that the class name is a valid class and that it is in the ancestors of the super class that the association is expecting.
* Initialize accessors to remove some warnings in Ruby 2.0Carlos Antonio da Silva2012-11-191-3/+2
|
* Regression test for #7238Nikita Afanasenko2012-11-131-0/+6
|
* :counter_cache option for to support custom named counter caches. Closes #7993Yves Senn2012-11-041-0/+1
|
* Remove ActiveRecord::ModelJon Leighton2012-10-261-35/+0
| | | | | | | | | | In the end I think the pain of implementing this seamlessly was not worth the gain provided. The intention was that it would allow plain ruby objects that might not live in your main application to be subclassed and have persistence mixed in. But I've decided that the benefit of doing that is not worth the amount of complexity that the implementation introduced.
* fix warning: method redefinedkennyj2012-10-021-1/+1
|
* Fix reset_counters() crashing on has_many :through associations.lulalala2012-10-021-1/+1
| | | | | The counter column name in the intermediate model need to be access via the through reflection.
* 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.
* Remove mass_assignment_options from ActiveRecordGuillermo Iguaran2012-09-161-3/+3
|
* Remove mass assignment security from ActiveRecordGuillermo Iguaran2012-09-166-20/+0
|
* Fix find_in_batches with customized primary_keyToshiyuki Kawanishi2012-09-161-0/+5
|
* refactor store_accessorMatt Jones2012-09-131-1/+9
|
* Fix nested association referencesJon Leighton2012-09-121-0/+1
| | | | | Previously the reflection would be looked up on the wrong class. However the test passed because the examples referred back to themselves.
* Accept belongs_to assoc. keys in ActiveRecord queriesbeerlington2012-09-111-0/+3
| | | | | | | | | | | | | Allows you to specify the model association key in a belongs_to relationship instead of the foreign key. The following queries are now equivalent: Post.where(:author_id => Author.first) Post.where(:author => Author.first) PriceEstimate.where(:estimate_of_type => 'Treasure', :estimate_of_id => treasure) PriceEstimate.where(:estimate_of => treasure)