Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
61bcc318
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,发现更多精彩内容 >>
提交
61bcc318
编写于
11月 27, 2011
作者:
J
Josh Susser
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use GeneratedFeatureMethods module for associations
上级
9cdf33af
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
57 addition
and
15 deletion
+57
-15
activerecord/lib/active_record/associations/builder/association.rb
...ord/lib/active_record/associations/builder/association.rb
+5
-3
activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
...ve_record/associations/builder/has_and_belongs_to_many.rb
+8
-4
activerecord/lib/active_record/attribute_methods.rb
activerecord/lib/active_record/attribute_methods.rb
+0
-6
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+14
-0
activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
...associations/has_and_belongs_to_many_associations_test.rb
+21
-1
activerecord/test/cases/base_test.rb
activerecord/test/cases/base_test.rb
+9
-0
activerecord/test/models/author.rb
activerecord/test/models/author.rb
+0
-1
未找到文件。
activerecord/lib/active_record/associations/builder/association.rb
浏览文件 @
61bcc318
...
...
@@ -6,7 +6,7 @@ class Association #:nodoc:
# Set by subclasses
class_attribute
:macro
attr_reader
:model
,
:name
,
:options
,
:reflection
,
:mixin
attr_reader
:model
,
:name
,
:options
,
:reflection
def
self
.
build
(
model
,
name
,
options
)
new
(
model
,
name
,
options
).
build
...
...
@@ -14,8 +14,10 @@ def self.build(model, name, options)
def
initialize
(
model
,
name
,
options
)
@model
,
@name
,
@options
=
model
,
name
,
options
@mixin
=
Module
.
new
@model
.
__send__
(
:include
,
@mixin
)
end
def
mixin
@model
.
generated_feature_methods
end
def
build
...
...
activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
浏览文件 @
61bcc318
...
...
@@ -15,10 +15,14 @@ def build
def
define_destroy_hook
name
=
self
.
name
mixin
.
send
(
:define_method
,
:destroy_associations
)
do
association
(
name
).
delete_all
super
()
end
model
.
send
(
:include
,
Module
.
new
{
class_eval
<<-
RUBY
,
__FILE__
,
__LINE__
+
1
def destroy_associations
association(
#{
name
.
to_sym
.
inspect
}
).delete_all
super
end
RUBY
})
end
# TODO: These checks should probably be moved into the Reflection, and we should not be
...
...
activerecord/lib/active_record/attribute_methods.rb
浏览文件 @
61bcc318
...
...
@@ -8,12 +8,6 @@ module AttributeMethods #:nodoc:
include
ActiveModel
::
AttributeMethods
module
ClassMethods
def
inherited
(
child_class
)
# force creation + include before accessor method modules
child_class
.
generated_attribute_methods
super
end
# Generates all the attribute related methods for columns in the database
# accessors, mutators and query methods.
def
define_attribute_methods
...
...
activerecord/lib/active_record/base.rb
浏览文件 @
61bcc318
...
...
@@ -450,6 +450,20 @@ class << self # Class methods
:having
,
:create_with
,
:uniq
,
:to
=>
:scoped
delegate
:count
,
:average
,
:minimum
,
:maximum
,
:sum
,
:calculate
,
:to
=>
:scoped
def
inherited
(
child_class
)
#:nodoc:
# force attribute methods to be higher in inheritance hierarchy than other generated methods
child_class
.
generated_attribute_methods
child_class
.
generated_feature_methods
super
end
def
generated_feature_methods
unless
const_defined?
(
:GeneratedFeatureMethods
,
false
)
include
const_set
(
:GeneratedFeatureMethods
,
Module
.
new
)
end
const_get
(
:GeneratedFeatureMethods
)
end
# Executes a custom SQL query against your database and returns all the results. The results will
# be returned as an array with columns requested encapsulated as attributes of the model you call
# this method from. If you call <tt>Product.find_by_sql</tt> then the results will be returned in
...
...
activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
浏览文件 @
61bcc318
...
...
@@ -77,7 +77,7 @@ class DeveloperWithCounterSQL < ActiveRecord::Base
class
HasAndBelongsToManyAssociationsTest
<
ActiveRecord
::
TestCase
fixtures
:accounts
,
:companies
,
:categories
,
:posts
,
:categories_posts
,
:developers
,
:projects
,
:developers_projects
,
:parrots
,
:pirates
,
:treasures
,
:price_estimates
,
:tags
,
:taggings
:parrots
,
:pirates
,
:
parrots_pirates
,
:
treasures
,
:price_estimates
,
:tags
,
:taggings
def
setup_data_for_habtm_case
ActiveRecord
::
Base
.
connection
.
execute
(
'delete from countries_treaties'
)
...
...
@@ -445,6 +445,26 @@ def test_destroy_all
assert
david
.
projects
(
true
).
empty?
end
def
test_destroy_associations_destroys_multiple_associations
george
=
parrots
(
:george
)
assert
!
george
.
pirates
.
empty?
assert
!
george
.
treasures
.
empty?
assert_no_difference
"Pirate.count"
do
assert_no_difference
"Treasure.count"
do
george
.
destroy_associations
end
end
join_records
=
Parrot
.
connection
.
select_all
(
"SELECT * FROM parrots_pirates WHERE parrot_id =
#{
george
.
id
}
"
)
assert
join_records
.
empty?
assert
george
.
pirates
(
true
).
empty?
join_records
=
Parrot
.
connection
.
select_all
(
"SELECT * FROM parrots_treasures WHERE parrot_id =
#{
george
.
id
}
"
)
assert
join_records
.
empty?
assert
george
.
treasures
(
true
).
empty?
end
def
test_deprecated_push_with_attributes_was_removed
jamis
=
developers
(
:jamis
)
assert_raise
(
NoMethodError
)
do
...
...
activerecord/test/cases/base_test.rb
浏览文件 @
61bcc318
...
...
@@ -69,6 +69,15 @@ def setup
class
BasicsTest
<
ActiveRecord
::
TestCase
fixtures
:topics
,
:companies
,
:developers
,
:projects
,
:computers
,
:accounts
,
:minimalistics
,
'warehouse-things'
,
:authors
,
:categorizations
,
:categories
,
:posts
def
test_generated_methods_modules
modules
=
Computer
.
ancestors
assert
modules
.
include?
(
Computer
::
GeneratedFeatureMethods
)
assert_equal
(
Computer
::
GeneratedFeatureMethods
,
Computer
.
generated_feature_methods
)
assert
(
modules
.
index
(
Computer
.
generated_attribute_methods
)
>
modules
.
index
(
Computer
.
generated_feature_methods
),
"generated_attribute_methods must be higher in inheritance hierarchy than generated_feature_methods"
)
assert_not_equal
Computer
.
generated_feature_methods
,
Post
.
generated_feature_methods
end
def
test_column_names_are_escaped
conn
=
ActiveRecord
::
Base
.
connection
classname
=
conn
.
class
.
name
[
/[^:]*$/
]
...
...
activerecord/test/models/author.rb
浏览文件 @
61bcc318
...
...
@@ -128,7 +128,6 @@ def testing_proxy_target
belongs_to
:author_address
,
:dependent
=>
:destroy
belongs_to
:author_address_extra
,
:dependent
=>
:delete
,
:class_name
=>
"AuthorAddress"
has_many
:post_categories
,
:through
=>
:posts
,
:source
=>
:categories
has_many
:category_post_comments
,
:through
=>
:categories
,
:source
=>
:post_comments
has_many
:misc_posts
,
:class_name
=>
'Post'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录