提交 43946ee8 编写于 作者: M Mitch Crowe

Add documentation to the SpawnMethods#merge method.

上级 e9f778af
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册