aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/pirate.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add Relation#annotate for SQL commentingMatt Yoho2019-03-211-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch has two main portions: 1. Add SQL comment support to Arel via Arel::Nodes::Comment. 2. Implement a Relation#annotate method on top of that. == Adding SQL comment support Adds a new Arel::Nodes::Comment node that represents an optional SQL comment and teachers the relevant visitors how to handle it. Comment nodes may be added to the basic CRUD statement nodes and set through any of the four (Select|Insert|Update|Delete)Manager objects. For example: manager = Arel::UpdateManager.new manager.table table manager.comment("annotation") manager.to_sql # UPDATE "users" /* annotation */ This new node type will be used by ActiveRecord::Relation to enable query annotation via SQL comments. == Implementing the Relation#annotate method Implements `ActiveRecord::Relation#annotate`, which accepts a comment string that will be appeneded to any queries generated by the relation. Some examples: relation = Post.where(id: 123).annotate("metadata string") relation.first # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 # LIMIT 1 /* metadata string */ class Tag < ActiveRecord::Base scope :foo_annotated, -> { annotate("foo") } end Tag.foo_annotated.annotate("bar").first # SELECT "tags".* FROM "tags" LIMIT 1 /* foo */ /* bar */ Also wires up the plumbing so this works with `#update_all` and `#delete_all` as well. This feature is useful for instrumentation and general analysis of queries generated at runtime.
* Call build when extend with nested attributes definedAlireza Bashiri2018-08-021-1/+7
| | | | | | | | What? From now on when `accepts_nested_attributes_for` defined and `extend` option added the overwritten `build` method being called. [Alireza Bashiri, Martins Polakovs]
* 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
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-8/+8
|
* Add three new rubocop rulesRafael Mendonça França2016-08-161-8/+8
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* modernizes hash syntax in activerecordXavier Noria2016-08-061-37/+37
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-10/+10
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Add line endings to files which are missing themSean Griffin2015-02-171-1/+1
| | | | | | These files get modified whenever someone uses a tool like `sed`. Let's just get this over with in one commit so it'd not adding diff noise to something else.
* Deprecate `false` as the way to halt AR callbacksclaudiob2015-01-021-1/+1
| | | | | | | | | | Before this commit, returning `false` in an ActiveRecord `before_` callback such as `before_create` would halt the callback chain. After this commit, the behavior is deprecated: will still work until the next release of Rails but will also display a deprecation warning. The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-2/+2
|
* Fixed custom validation context bug where childEric Chahin2014-05-011-0/+6
| | | | | | | | associations were not being saved. Fixes #13854. [Eric Chahin, Aaron Nelson, & Kevin Casey]
* Remove outdated commentRafael Mendonça França2014-04-141-1/+0
|
* Revert "context in validation goes through has many relationship"Aaron Patterson2014-02-201-8/+0
| | | | This reverts commit 5e3d466d52fa4e9a42c3a1f8773a7c31da875e48.
* context in validation goes through has many relationshipKevin Casey2014-02-081-0/+8
|
* pass `habtm :autosave` to underlying `hm:t` association. Closes #13923.Yves Senn2014-02-031-0/+1
|
* allow to pass Symbol or Proc into :limit option of ↵Mikhail Dieterle2012-08-261-1/+1
| | | | #accepts_nested_attributes_for
* Convert association macros to the new syntaxJon Leighton2012-07-201-3/+3
|
* Deprecated support for passing hashes and relations to default_scope, in ↵Jon Leighton2011-04-121-1/+1
| | | | favour of defining a 'default_scope' class method in the model. See the CHANGELOG for more details.
* We shouldn't be using scoped.scoping { ... } to build associated records, as ↵Jon Leighton2011-01-301-0/+2
| | | | this can affect validations/callbacks/etc inside the record itself [#6252 state:resolved]
* has_one should always remove the old record (properly), even if not saving ↵Jon Leighton2011-01-111-0/+4
| | | | the new record, so we don't get the database into a pickle
* use persisted? instead of new_record? wherever possibleDavid Chelimsky2010-11-091-1/+1
| | | | | | | | | | | - persisted? is the API defined in ActiveModel - makes it easier for extension libraries to conform to ActiveModel APIs without concern for whether the extended object is specifically ActiveRecord [#5927 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* Don't overwrite unsaved updates when loading an association but preserve the ↵James Le Cuirot2010-06-201-2/+2
| | | | | | | | order of the loaded records. Reapplied from before but now allows already-saved records to be refreshed. [#4830 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
* Revert "Don't overwrite unsaved updates when loading an association but ↵José Valim2010-06-111-2/+2
| | | | | | | | preserve the order of the loaded records. [#4642 state:open]" This commit introduced a regression described in ticket [#4830]. This reverts commit 0265c708b9696c3943518ad5f3dabdc22c5eba11.
* Don't overwrite unsaved updates when loading an association but preserve the ↵James Le Cuirot2010-06-091-2/+2
| | | | | | order of the loaded records. [#4642 state:resolved] Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
* Rollback the transaction when one of the autosave associations fails to ↵Eloy Duran2010-01-081-0/+6
| | | | save. [#3391 state:resolved]
* Refactored previous changes to nested attributes.Eloy Duran2009-12-281-0/+2
|
* Define autosave association callbacks when using accepts_nested_attributes_for.Eloy Duran2009-11-071-1/+1
| | | | | | | This way we don't define all the validation methods for all associations by default, but only when needed. [#3355 state:resolved]
* Allow accepts_nested_attributes_for :reject_if option accept symbols for ↵Pratik Naik2009-10-071-0/+4
| | | | | | | | using a method Conflicts: activerecord/lib/active_record/nested_attributes.rb
* Define autosave association validation methods only when needed. [#3161 ↵Alexey Kovyrin2009-09-121-3/+6
| | | | | | state:resolved] Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com>
* Allow you to pass :all_blank to :reject_if option to automatically create a ↵Mike Breen2009-05-101-0/+2
| | | | Proc that will reject any record with blank attributes.
* Ensure AutosaveAssociation runs remove callbacks [#2146 state:resolved]Luca Guidi2009-03-121-1/+48
| | | | | Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com> Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
* Changed API of NestedAttributes to take an array, or hash with index keys, ↵Lance Ivy2009-02-131-1/+1
| | | | | | | | of hashes that have the id on the inside of the attributes hash and updated the FormBuilder to produce such hashes. Also fixed NestedAttributes with composite ids. Signed-off-by: Michael Koziarski <michael@koziarski.com> Signed-off-by: Eloy Duran <eloy.de.enige@gmail.com> [#1892 state:committed]
* Add support for nested object forms to ActiveRecord and the helpers in ↵Eloy Duran2009-02-011-0/+7
| | | | | | | | ActionPack Signed-Off-By: Michael Koziarski <michael@koziarski.com> [#1202 state:committed]
* Dirty attributes aren't cleared if save fails. [#174 state:resolved]Xavier Noria2008-05-121-0/+2
| | | | Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* Fix has_many :through a polymorphic has_many. Closes #10529 [Aleksey ↵Jeremy Kemper2008-02-021-1/+3
| | | | | | Kondratenko] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8776 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
* move assets and modelsJeremy Kemper2008-01-181-0/+5
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8657 5ecf4fe2-1ee6-0310-87b1-e25e094e27de