Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b2816ae9
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b2816ae9
编写于
7月 08, 2011
作者:
A
Akira Matsuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
:joins => joins
上级
c4bd4777
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
12 addition
and
12 deletion
+12
-12
activerecord/lib/active_record/associations.rb
activerecord/lib/active_record/associations.rb
+12
-12
未找到文件。
activerecord/lib/active_record/associations.rb
浏览文件 @
b2816ae9
...
@@ -763,43 +763,43 @@ def association_instance_set(name, association)
...
@@ -763,43 +763,43 @@ def association_instance_set(name, association)
# second time, the table is aliased as <tt>#{reflection_name}_#{parent_table_name}</tt>.
# second time, the table is aliased as <tt>#{reflection_name}_#{parent_table_name}</tt>.
# Indexes are appended for any more successive uses of the table name.
# Indexes are appended for any more successive uses of the table name.
#
#
# Post.
all :joins => :comments
# Post.
joins(:comments)
# # => SELECT ... FROM posts INNER JOIN comments ON ...
# # => SELECT ... FROM posts INNER JOIN comments ON ...
# Post.
all :joins => :special_comments
# STI
# Post.
joins(:special_comments)
# STI
# # => SELECT ... FROM posts INNER JOIN comments ON ... AND comments.type = 'SpecialComment'
# # => SELECT ... FROM posts INNER JOIN comments ON ... AND comments.type = 'SpecialComment'
# Post.
all :joins => [:comments, :special_comments]
# special_comments is the reflection name, posts is the parent table name
# Post.
joins(:comments, :special_comments)
# special_comments is the reflection name, posts is the parent table name
# # => SELECT ... FROM posts INNER JOIN comments ON ... INNER JOIN comments special_comments_posts
# # => SELECT ... FROM posts INNER JOIN comments ON ... INNER JOIN comments special_comments_posts
#
#
# Acts as tree example:
# Acts as tree example:
#
#
# TreeMixin.
all :joins => :children
# TreeMixin.
joins(:children)
# # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ...
# # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ...
# TreeMixin.
all :joins => {:children => :parent}
# TreeMixin.
joins(:children => :parent)
# # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ...
# # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ...
# INNER JOIN parents_mixins ...
# INNER JOIN parents_mixins ...
# TreeMixin.
all :joins => {:children => {:parent => :children}}
# TreeMixin.
joins(:children => {:parent => :children})
# # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ...
# # => SELECT ... FROM mixins INNER JOIN mixins childrens_mixins ...
# INNER JOIN parents_mixins ...
# INNER JOIN parents_mixins ...
# INNER JOIN mixins childrens_mixins_2
# INNER JOIN mixins childrens_mixins_2
#
#
# Has and Belongs to Many join tables use the same idea, but add a <tt>_join</tt> suffix:
# Has and Belongs to Many join tables use the same idea, but add a <tt>_join</tt> suffix:
#
#
# Post.
all :joins => :categories
# Post.
joins(:categories)
# # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ...
# # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ...
# Post.
all :joins => {:categories => :posts}
# Post.
joins(:categories => :posts)
# # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ...
# # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ...
# INNER JOIN categories_posts posts_categories_join INNER JOIN posts posts_categories
# INNER JOIN categories_posts posts_categories_join INNER JOIN posts posts_categories
# Post.
all :joins => {:categories => {:posts => :categories}}
# Post.
joins(:categories => {:posts => :categories})
# # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ...
# # => SELECT ... FROM posts INNER JOIN categories_posts ... INNER JOIN categories ...
# INNER JOIN categories_posts posts_categories_join INNER JOIN posts posts_categories
# INNER JOIN categories_posts posts_categories_join INNER JOIN posts posts_categories
# INNER JOIN categories_posts categories_posts_join INNER JOIN categories categories_posts_2
# INNER JOIN categories_posts categories_posts_join INNER JOIN categories categories_posts_2
#
#
# If you wish to specify your own custom joins using
a <tt>:joins</tt> option
, those table
# If you wish to specify your own custom joins using
<tt>joins</tt> method
, those table
# names will take precedence over the eager associations:
# names will take precedence over the eager associations:
#
#
# Post.
all :joins => :comments, :joins => "inner join comments ..."
# Post.
joins(:comments).joins("inner join comments ...")
# # => SELECT ... FROM posts INNER JOIN comments_posts ON ... INNER JOIN comments ...
# # => SELECT ... FROM posts INNER JOIN comments_posts ON ... INNER JOIN comments ...
# Post.
all :joins => [:comments, :special_comments], :joins => "inner join comments ..."
# Post.
joins(:comments, :special_comments).joins("inner join comments ...")
# # => SELECT ... FROM posts INNER JOIN comments comments_posts ON ...
# # => SELECT ... FROM posts INNER JOIN comments comments_posts ON ...
# INNER JOIN comments special_comments_posts ...
# INNER JOIN comments special_comments_posts ...
# INNER JOIN comments ...
# INNER JOIN comments ...
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录