aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models
Commit message (Collapse)AuthorAgeFilesLines
* Don't try to get the subclass if the inheritance column doesn't existUjjwal Thaakar2014-01-141-0/+5
| | | | | | | The `subclass_from_attrs` method is called even if the column specified by the `inheritance_column` setting doesn't exist. This prevents setting associations via the attributes hash if the association name clashes with the value of the setting, typically `:type`. This worked previously in Rails 3.2.
* Remove warnings in test suiteMatthias Zirnstein2014-01-061-1/+1
| | | | | | | lib/active_record/store.rb:79: warning: method redefined; discarding old color= lib/active_record/store.rb:79: warning: previous definition of color= was here lib/active_record/store.rb:83: warning: method redefined; discarding old color lib/active_record/store.rb:83: warning: previous definition of color was here
* Fix: ActiveRecord::Store TypeError conversion when using YAML coderThales Oliveira2014-01-061-0/+1
| | | | | | | | | | Renaming the test accordingly to its behaviour Adding 'Fixes' statement to changelog Improving tests legibility & changelog Undoing mistakenly removed empty line & further improving changelog
* Remove method redefined warnings for test suiteMatthias Zirnstein2014-01-051-1/+1
| | | | | | | | | | | | | | | | | has_many definitions with "name" as singular and as plural e.g. has_many :welcome_posts_with_comment has_many :welcome_posts_with_comments Ruby mentions it with: lib/active_record/associations/builder/collection_association.rb:65: warning: method redefined; discarding old welcome_posts_with_comment_ids lib/active_record/associations/builder/collection_association.rb:65: warning: previous definition of welcome_posts_with_comment_ids was here lib/active_record/associations/builder/collection_association.rb:75: warning: method redefined; discarding old welcome_posts_with_comment_ids= lib/active_record/associations/builder/collection_association.rb:75: warning: previous definition of welcome_posts_with_comment_ids= was here
* make sure cached table name is a string. fixes #12582Aaron Patterson2013-12-121-0/+4
|
* changed update counter to act on unscoped modelheruku2013-11-261-0/+4
|
* Raise `RecordNotDestroyed` when children can't be replacedBrian Thomas Storti2013-11-252-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #12812 Raise `ActiveRecord::RecordNotDestroyed` when a child marked with `dependent: destroy` can't be destroyed. The following code: ```ruby class Post < ActiveRecord::Base has_many :comments, dependent: :destroy end class Comment < ActiveRecord::Base before_destroy do return false end end post = Post.create!(comments: [Comment.create!]) post.comments = [Comment.create!] ```` would result in a `post` with two `comments`. With this commit, the same code would raise a `RecordNotDestroyed` exception, keeping the `post` with the same `comment`.
* Fix ActiveRecord::Relation#unscopeJon Leighton2013-11-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm pretty confused about the addition of this method. The documentation says that it was intended to allow the removal of values from the default scope (in contrast to #except). However it behaves exactly the same as except: https://gist.github.com/jonleighton/7537008 (other than having a slightly enhanced syntax). The removal of the default scope is allowed by 94924dc32baf78f13e289172534c2e71c9c8cade, which was not a change we could make until 4.1 due to the need to deprecate things. However after that change #unscope still gives us nothing that #except doesn't already give us. However there *is* a desire to be able to unscope stuff in a way that persists across merges, which would allow associations to be defined which unscope stuff from the default scope of the associated model. E.g. has_many :comments, -> { unscope where: :trashed } So that's what this change implements. I've also corrected the documentation. I removed the guide references to #except as I think unscope really supercedes #except now. While we're here, there's also a potential desire to be able to write this: has_many :comments, -> { unscoped } However, it doesn't make sense and would not be straightforward to implement. While with #unscope we're specifying exactly what we want to be removed from the relation, with "unscoped" we're just saying that we want it to not have some things which were added earlier on by the default scope. However in the case of an association, we surely don't want *all* conditions to be removed, otherwise the above would just become "SELECT * FROM comments" with no foreign key constraint. To make the above work, we'd have to somehow tag the relation values which get added when evaluating the default scope in order to differentiate them from other relation values. Which is way too much complexity and therefore not worth it when most use cases can be satisfied with unscope. Closes #10643, #11061.
* Add AR::Base.to_param for convenient "pretty" URLs derived from a model's ↵Javan Makhmali2013-11-141-0/+2
| | | | attribute or method.
* define enum methods inside a `Module` to make them overwritable.Yves Senn2013-11-051-0/+5
|
* Explicit mapping for enumYury Korolev2013-11-021-0/+1
|
* Fix to work on Ruby 1.9.3, example and changelog improvementsCarlos Antonio da Silva2013-11-021-2/+2
|
* Added ActiveRecord::Base#enum for declaring enum attributes where the values ↵David Heinemeier Hansson2013-11-021-2/+4
| | | | map to integers in the database, but can be queried by name
* Skip `include_values` from through associations chains for building target scopePaul Nikitochkin2013-10-271-0/+3
| | | | Fixes: #12242, #9517, #10240
* scope_chain should not be mutated for other reflectionsNeeraj Singh2013-10-145-0/+19
| | | | | | | | | | | Currently `scope_chain` uses same array for building different `scope_chain` for different associations. During processing these arrays are sometimes mutated and because of in-place mutation the changed `scope_chain` impacts other reflections. Fix is to dup the value before adding to the `scope_chain`. Fixes #3882.
* Port test from cf1904f to avoid future regressionPrem Sichanugrist2013-10-031-0/+5
| | | | Related issue: #11939, #12084
* adding a test to demonstrate how to use STI subclasses on the far rightAaron Patterson2013-09-272-0/+3
| | | | side of a hm:t association along with preloading.
* Merge pull request #12359 from arthurnn/inverse_on_callbacksRafael Mendonça França2013-09-251-1/+5
|\ | | | | Make sure inverse_of is visible on the has_many callbacks
| * Make sure inverse_of is visible on the has_many callbacksArthur Neves2013-09-251-1/+5
| |
* | adding a test for sti on middle tables with sorting on RHSAaron Patterson2013-09-231-0/+5
|/
* Merge pull request #12011 from jetthoughts/11963_fix_join_with_association_scopeRafael Mendonça França2013-09-161-0/+7
|\ | | | | | | | | | | | | Collapse where constraints to the Arel::Nodes::And node Conflicts: activerecord/CHANGELOG.md
| * Collapse where constraints to one where constraintPaul Nikitochkin2013-09-131-0/+7
| | | | | | | | | | | | | | In order to remove duplication with joining arel where constraints with `AND`, all constraints on `build_arel` are collapsed into one head node: `Arel::Nodes::And` Closes: #11963
* | More unused associations in AR test modelsAkira Matsuda2013-09-108-13/+0
| |
* | :scissors: [ci skip]Carlos Antonio da Silva2013-09-101-1/+1
| |
* | change function def self.table_name to self.table_nameRajarshi Das2013-09-102-5/+3
| | | | | | | | | | | | change def self.primary_key to self.primary_key change def self.primary_key to self.primary_key
* | Clean up unused associations in AR test modelAkira Matsuda2013-09-101-3/+0
|/
* pk should not be required for hm:t associationsAaron Patterson2013-08-291-0/+8
|
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2013-08-1711-3/+21
|\ | | | | | | | | | | | | | | Conflicts: actionview/README.rdoc activerecord/lib/active_record/migration.rb guides/source/development_dependencies_install.md guides/source/getting_started.md
| * Revert "Merge branch 'master' of github.com:rails/docrails"Vijay Dev2013-08-1711-3/+21
| | | | | | | | | | | | | | This reverts commit 70d6e16fbad75b89dd1798ed697e7732b8606fa3, reversing changes made to ea4db3bc078fb3093ecdddffdf4f2f4ff3e1e8f9. Seems to be a code merge done by mistake.
* | Fixing multi-word automatic inverse detection.wangjohn2013-08-152-0/+3
| | | | | | | | | | Currently, ActiveRecord models with multiple words cannot have their inverse associations detected automatically.
* | Changing the def self.table_name to self.table_name in the column_name.rbKarunakar (Ruby)2013-08-031-2/+2
| |
* | this code is dead, removingAaron Patterson2013-08-011-6/+0
|/
* :scissors: [ci skip]Carlos Antonio da Silva2013-07-251-1/+1
|
* change function def self.table_name to self.table_nameRajarshi Das2013-07-252-5/+3
| | | | | | change def self.primary_key to self.primary_key change def self.primary_key to self.primary_key
* More unused associations in AR test modelsAkira Matsuda2013-07-258-13/+0
|
* Clean up unused associations in AR test modelAkira Matsuda2013-07-251-3/+0
|
* Make sure that a joins Relation can be merged with has_many :through + ↵Akira Matsuda2013-07-101-1/+5
| | | | | | association proxy Closes #11248.
* Dropped deprecated option `:restrict` for `:dependent` in associationsNeeraj Singh2013-07-031-7/+0
|
* Removed support for deprecated `delete_sql` in associations.Neeraj Singh2013-07-031-5/+0
|
* Removed support for deprecated `finder_sql` in associations.Neeraj Singh2013-07-023-16/+0
|
* Removed support for deprecated `counter_sql`Neeraj Singh2013-07-021-16/+1
|
* Do not invoke callbacks when delete_all is calledNeeraj Singh2013-06-303-0/+13
| | | | | | | | | | | Method `delete_all` should not be invoking callbacks and this feature was deprecated in Rails 4.0. This is being removed. `delete_all` will continue to honor the `:dependent` option. However if `:dependent` value is `:destroy` then the default deletion strategy for that collection will be applied. User can also force a deletion strategy by passing parameter to `delete_all`. For example you can do `@post.comments.delete_all(:nullify)`
* Ambiguous reflections are on :through relationships are no longer supported.Aaron Patterson2013-06-132-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For example, you need to change this: class Author < ActiveRecord::Base has_many :posts has_many :taggings, :through => :posts end class Post < ActiveRecord::Base has_one :tagging has_many :taggings end class Tagging < ActiveRecord::Base end To this: class Author < ActiveRecord::Base has_many :posts has_many :taggings, :through => :posts, :source => :tagging end class Post < ActiveRecord::Base has_one :tagging has_many :taggings end class Tagging < ActiveRecord::Base end
* Getting rid of the +automatic_inverse_of: false+ option in associations in favorwangjohn2013-06-085-5/+5
| | | | | of using +inverse_of: false+ option. Changing the documentation and adding a CHANGELOG entry for the automatic inverse detection feature.
* Fix the `:primary_key` option for `has_many` associations.Yves Senn2013-05-231-0/+1
| | | | | | | | | | | | | | | | | When removing records from a `has_many` association it used the `primary_key` defined on the association. Our test suite didn't fail because on all occurences of `:primary_key`, the specified column was available in both tables. This prevented the code from raising an exception but it still behaved badly. I added a test-case to prevent regressions that failed with: ``` 1) Error: HasManyAssociationsTest#test_has_many_assignment_with_custom_primary_key: ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: essays.first_name: UPDATE "essays" SET "writer_id" = NULL WHERE "essays"."writer_id" = ? AND "essays"."first_name" IS NULL ```
* Add test to AR's counter_cache_test.rbTakehiro Adachi2013-05-181-0/+1
| | | | | | | According to https://github.com/rails/rails/blob/b601399b72ab56cc01368f02615af99f45d1 4f02/activerecord/lib/active_record/counter_cache.rb#L14, u can pass more then one association to the `reset_counters` method.
* 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
|