aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/company.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #33378 from numbata/subclass-redefine-autosave-callbacksRafael Mendonça França2018-09-131-0/+6
|\ | | | | | | Allow subclasses to redefine autosave callbacks for associated records
| * Allow subclasses to redefine autosave callbacks for associated recordsAndrey Subbota2018-07-271-0/+6
| |
* | Fix regression setting children record in parent before_save callback.Guo Xiang Tan2018-09-031-0/+8
|/
* Fix `collection.create` to could be rolled back by `after_save`Ryuta Kamizono2018-06-071-0/+10
| | | | | | | | | | | In `_create_record`, explicit `transaction` block requires rollback handling manually when `insert_record` is failed. We need to handle it in `_create_record`, not in `insert_record`, since our test cases expect a record added to target and returned even if `insert_record` is failed, Closes #31488.
* Rollback parent transaction when children fails to update (#32796)Guillaume Malette2018-05-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Rollback parent transaction when children fails to update Rails supports autosave associations on the owner of a `has_many` relationship. In certain situation, if the children of the association fail to save, the parent is not rolled back. ```ruby class Employee < ActiveRecord::Base end class Company < ActiveRecord::Base has_many(:employees) end company = Company.new employee = company.employees.new company.save ``` In the previous example, if the Employee failed to save, the Company will not be rolled back. It will remain in the database with no associated Employee. I expect the `company.save` call to be atomic, and either create all or none of the records. The persistance of the Company already starts a transaction that nests it's children. However, it didn't track the success or failure of it's children in this very situation, and the outermost transaction is not rolled back. This PR makes the change to track the success of the child insertion and rollback the parent if any of the children fail. * Change the test to reflect what we expect Once #32862 is merged, rolling back a record will rollback it's state to match the state before the database changes were applied * Use only the public API to express the tests * Refactor to avoid reassigning saved for nested reflections [Guillaume Malette + Rafael Mendonça França]
* Merge pull request #27561 from fishbrain/count-all-in-has-many-associationRyuta Kamizono2018-01-031-0/+2
|\ | | | | | | Use `count(:all)` in HasManyAssociation#count_records
| * Use `count(:all)` in HasManyAssociation#count_recordsKlas Eskilson2017-02-071-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Problem: Calling `count` on an association can cause invalid SQL queries to be created where the `SELECT COUNT(a, b, c)` function receives multiple columns. This will cause a `StatementInvalid` exception later on. Solution: Use `count(:all)`, which generates a `SELECT COUNT(*)...` query independently of the association. This also includes a test case that, before the fix, broke.
* | Extract `Account` model to the dedicated fileRyuta Kamizono2017-07-221-34/+1
| |
* | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
| |
* | 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
| |
* | Correct a has_many association testKoichi ITO2017-06-011-0/+1
| |
* | Remove useless test caseRyuta Kamizono2017-04-261-8/+0
|/ | | | | Cannot call private methods in `@klass` against `CollectionProxy` (inherites `Relation`) because using `public_send` in `method_missing`.
* Privatize unneededly protected methods in Active RecordAkira Matsuda2017-01-051-3/+1
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-2/+2
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-11/+11
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-58/+58
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-22/+22
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Revert "Merge pull request #21994 from mtodd/inherit-scopes"Rafael Mendonça França2015-10-271-1/+1
| | | | | | | This reverts commit 60c9701269f5b412849f1a507df61ba4735914d7, reversing changes made to 6a25202d9ea3b4a7c9f2d6154b97cf8ba58403db. Reason: Broken build
* Make inherited scope test failMatt Todd2015-10-261-1/+1
| | | | | | | | | | | | | | This triggers the JoinDependency work to reflect on the associations and trigger an error as follows: ActiveRecord::ConfigurationError: Association named 'account' was not found on Company; perhaps you misspelled it? Fix Company.of_first_firm joins association name Should be `Company.joins(:accounts)` not `Company.joins(:account)`. Do the same for Client.of_first_firm
* Refactor Calculations#execute_grouped_calculation and clean AR test caseRafael Sales2015-10-221-1/+0
| | | | | | | | | | | | | * When tried to use `Company#accounts` test/models/company.rb I got: ``` ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: accounts.company_id: SELECT COUNT(*) AS count_all, "companies"."firm_id" AS companies_firm_id FROM "companies" INNER JOIN "accounts" ON "accounts"."company_id" = "companies"."id" GROUP BY "companies"."firm_id" ``` * The refactor on Calculations class was just to simplify the code
* Fix regression in inverse_of on through associationseileencodes2015-09-261-0/+3
| | | | | | | | | | | | | | | | | | | `inverse_of` on through associations was accidently removed/caused to stop working in commit f8d2899 which was part of a refactoring on `ThroughReflection`. To fix we moved `inverse_of` and `check_validity_of_inverse!` to the `AbstractReflection` so it's available to the `ThroughReflection` without having to dup any methods. We then need to delegate `inverse_name` method in `ThroughReflection`. `inverse_name` can't be moved to `AbstractReflection` without moving methods that set the instance variable `@automatic_inverse_of`. This adds a test that ensures that `inverse_of` on a `ThroughReflection` returns the correct class name, and the correct record for the inverse relationship. Fixes #21692
* allow setting of a demodulized class name when using STIAlex Robbin2015-05-111-0/+3
| | | | | | | | | | | | | | | | | | | | | If your STI class looks like this: ```ruby class Company < ActiveRecord::Base self.store_full_sti_class = false class GoodCo < Company end class BadCo < Company end end ``` The expectation (which is valid) is that the `type` in the database is saved as `GoodCo` or `BadCo`. However, another expectation should be that setting `type` to `GoodCo` would correctly instantiate the object as a `Company::GoodCo`. That second expectation is what this should fix.
* Deprecate `ActiveModel::Errors` `add_on_empty` and `add_on_blank` methodsWojciech Wnętrzak2015-02-191-1/+1
| | | | without replacement.
* 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.
* Move association definition to the model fileAkira Matsuda2014-08-281-0/+1
|
* Add AR::Base.to_param for convenient "pretty" URLs derived from a model's ↵Javan Makhmali2013-11-141-0/+2
| | | | attribute or method.
* Port test from cf1904f to avoid future regressionPrem Sichanugrist2013-10-031-0/+5
| | | | Related issue: #11939, #12084
* Make sure inverse_of is visible on the has_many callbacksArthur Neves2013-09-251-1/+5
|
* More unused associations in AR test modelsAkira Matsuda2013-09-101-2/+0
|
* Revert "Merge branch 'master' of github.com:rails/docrails"Vijay Dev2013-08-171-0/+2
| | | | | | | 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-2/+0
|
* Dropped deprecated option `:restrict` for `:dependent` in associationsNeeraj Singh2013-07-031-7/+0
|
* Removed support for deprecated `finder_sql` in associations.Neeraj Singh2013-07-021-4/+0
|
* Removed support for deprecated `counter_sql`Neeraj Singh2013-07-021-16/+1
|
* Ambiguous reflections are on :through relationships are no longer supported.Aaron Patterson2013-06-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* 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*
* Added STI support to init and building associationsJason Rush2012-11-291-0/+1
| | | | | | | | 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.
* Remove mass assignment security from ActiveRecordGuillermo Iguaran2012-09-161-1/+0
|
* test cleanup, remove ruby_type because it's no longer neededYves Senn2012-09-031-4/+0
| | | | | All tests with a custom inheritance_column use the `Vegtable` model. The field ruby_type on the Company models is no longer needed
* Remove the dependent_restrict_raises option.Jon Leighton2012-08-101-2/+14
| | | | | | | | | | | | | | | It's not really a good idea to have this as a global config option. We should allow people to specify the behaviour per association. There will now be two new values: * :dependent => :restrict_with_exception implements the current behaviour of :restrict. :restrict itself is deprecated in favour of :restrict_with_exception. * :dependent => :restrict_with_error implements the new behaviour - it adds an error to the owner if there are dependent records present See #4727 for the original discussion of this.
* Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-08-011-16/+20
|
* Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."Jon Leighton2012-08-011-1/+14
| | | | | | | | | This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370. Conflicts: activerecord/CHANGELOG.md It will be deprecated only in 4.0, and removed properly in 4.1.
* Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-07-201-14/+1
|
* Convert association macros to the new syntaxJon Leighton2012-07-201-27/+27
|
* Fix issue with private kernel methods and collection associations. Closes #2508Carlos Antonio da Silva2012-05-021-0/+5
| | | | | | | | Change CollectionProxy#method_missing to use scoped.public_send, to avoid a problem described in issue #2508 when trying to use class methods with names like "open", that clash with private kernel methods. Also changed the dynamic matcher instantiator to send straight to scoped, to avoid another roundtrip to method_missing.
* test_get_ids_for_ordered_association fixedgregolsen2012-01-311-1/+1
|
* ids_reader method fixed, test added to has_many associationgregolsen2012-01-311-0/+1
|
* Deprecate inferred JOINs with includes + SQL snippets.Jon Leighton2012-01-161-0/+2
| | | | | | See the CHANGELOG for details. Fixes #950.
* Deprecate set_sequence_name in favour of self.sequence_name=Jon Leighton2011-11-291-1/+1
|