Permalink
Browse files

Merge pull request #5887 from mcrowe/document-relation-merge

Add documentation to the SpawnMethods#merge method.
  • Loading branch information...
2 parents 5b80667 + 43946ee commit 5f6ef504b12dc2540461ff2d3414aba68215cb56 @vijaydev vijaydev committed Apr 23, 2012
Showing with 14 additions and 0 deletions.
  1. +14 −0 activerecord/lib/active_record/relation/spawn_methods.rb
@@ -5,6 +5,20 @@
module ActiveRecord
module SpawnMethods
+
+ # Merges in the conditions from <tt>other</tt>, if <tt>other</tt> is an <tt>ActiveRecord::Relation</tt>.
+ # Returns an array representing the union of the resulting records with <tt>other</tt>, if <tt>other</tt> is an array.
+ #
+ # ==== Examples
+ #
+ # Post.where(:published => true).joins(:comments).merge( Comment.where(:spam => false) )
+ # # Performs a single join query with both where conditions.
+ #
+ # recent_posts = Post.order('created_at DESC').first(5)
+ # Post.where(:published => true).merge(recent_posts)
+ # # Returns the union of all published posts with the 5 most recently created posts.
+ # # (This is just an example. You'd probably want to do this with a single query!)
+ #
def merge(other)
if other.is_a?(Array)
to_a & other

0 comments on commit 5f6ef50

Please sign in to comment.