Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d1516519
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,发现更多精彩内容 >>
提交
d1516519
编写于
10月 02, 2013
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
define the join model without using closures on the methods
上级
636a9099
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
18 deletion
+31
-18
activerecord/lib/active_record/associations.rb
activerecord/lib/active_record/associations.rb
+31
-18
未找到文件。
activerecord/lib/active_record/associations.rb
浏览文件 @
d1516519
...
...
@@ -1598,36 +1598,49 @@ def self.build(rhs_class, name, options)
end
end
def
belongs_to_options
(
options
)
rhs_options
=
{}
if
options
.
key?
:class_name
rhs_options
[
:foreign_key
]
=
options
[
:class_name
].
foreign_key
rhs_options
[
:class_name
]
=
options
[
:class_name
]
end
if
options
.
key?
:association_foreign_key
rhs_options
[
:foreign_key
]
=
options
[
:association_foreign_key
]
end
rhs_options
end
def
has_and_belongs_to_many1
(
name
,
scope
=
nil
,
options
=
{},
&
extension
)
# temporarily
habtm
=
JoinTableResolver
.
build
self
,
name
,
options
join_class_name
=
"HABTM_
#{
name
.
to_s
.
camelize
}
"
this_class
=
self
rhs_name
=
name
.
to_s
.
singularize
.
to_sym
join_model
=
Class
.
new
(
ActiveRecord
::
Base
)
{
define_singleton_method
(
:name
)
{
join_class_name
}
define_singleton_method
(
:table_name
)
{
habtm
.
join_table
}
define_singleton_method
(
:compute_type
)
{
|
class_name
|
this_class
.
compute_type
class_name
}
belongs_to
:left_side
,
:class
=>
this_class
rhs_options
=
{}
if
options
.
key?
:class_name
rhs_options
[
:foreign_key
]
=
options
[
:class_name
].
foreign_key
rhs_options
[
:class_name
]
=
options
[
:class_name
]
class
<<
self
;
attr_accessor
:class_resolver
attr_accessor
:name
attr_accessor
:table_name_resolver
end
if
options
.
key?
:association_foreign_key
rhs_options
[
:foreign_key
]
=
options
[
:association_foreign_key
]
def
self
.
table_name
table_name_resolver
.
join_table
end
belongs_to
rhs_name
,
rhs_options
def
self
.
compute_type
(
class_name
)
class_resolver
.
compute_type
class_name
end
}
join_model
.
name
=
"HABTM_
#{
name
.
to_s
.
camelize
}
"
join_model
.
table_name_resolver
=
habtm
join_model
.
class_resolver
=
self
join_model
.
belongs_to
:left_side
,
:class
=>
self
join_model
.
belongs_to
rhs_name
,
belongs_to_options
(
options
)
middle_name
=
[
self
.
name
.
downcase
.
pluralize
,
name
].
join
(
'_'
).
gsub
(
/::/
,
'_'
).
to_sym
#middle_options = options.dup
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录