Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f5ecb133
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,发现更多精彩内容 >>
提交
f5ecb133
编写于
3月 16, 2013
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9747 from macksmind/refactor_friend_follower
Refactor Person/Friendship relationships to be more intuitive
上级
07703169
1d6eabb6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
15 addition
and
6 deletion
+15
-6
activerecord/test/cases/counter_cache_test.rb
activerecord/test/cases/counter_cache_test.rb
+1
-1
activerecord/test/fixtures/friendships.yml
activerecord/test/fixtures/friendships.yml
+2
-2
activerecord/test/fixtures/people.yml
activerecord/test/fixtures/people.yml
+3
-0
activerecord/test/models/friendship.rb
activerecord/test/models/friendship.rb
+3
-1
activerecord/test/models/person.rb
activerecord/test/models/person.rb
+4
-1
activerecord/test/schema/schema.rb
activerecord/test/schema/schema.rb
+2
-1
未找到文件。
activerecord/test/cases/counter_cache_test.rb
浏览文件 @
f5ecb133
...
...
@@ -118,7 +118,7 @@ class ::SpecialReply < ::Reply
test
"reset the right counter if two have the same foreign key"
do
michael
=
people
(
:michael
)
assert_nothing_raised
(
ActiveRecord
::
StatementInvalid
)
do
Person
.
reset_counters
(
michael
.
id
,
:f
ollowers
)
Person
.
reset_counters
(
michael
.
id
,
:f
riends_too
)
end
end
...
...
activerecord/test/fixtures/friendships.yml
浏览文件 @
f5ecb133
Connection 1
:
id
:
1
person_id
:
1
friend_id
:
2
\ No newline at end of file
friend_id
:
1
follower_id
:
2
activerecord/test/fixtures/people.yml
浏览文件 @
f5ecb133
...
...
@@ -5,6 +5,7 @@ michael:
number1_fan_id
:
3
gender
:
M
followers_count
:
1
friends_too_count
:
1
david
:
id
:
2
first_name
:
David
...
...
@@ -12,6 +13,7 @@ david:
number1_fan_id
:
1
gender
:
M
followers_count
:
1
friends_too_count
:
1
susan
:
id
:
3
first_name
:
Susan
...
...
@@ -19,3 +21,4 @@ susan:
number1_fan_id
:
1
gender
:
F
followers_count
:
1
friends_too_count
:
1
activerecord/test/models/friendship.rb
浏览文件 @
f5ecb133
class
Friendship
<
ActiveRecord
::
Base
belongs_to
:friend
,
class_name:
'Person'
belongs_to
:follower
,
foreign_key:
'friend_id'
,
class_name:
'Person'
,
counter_cache: :followers_count
# friend_too exists to test a bug, and probably shouldn't be used elsewhere
belongs_to
:friend_too
,
foreign_key:
'friend_id'
,
class_name:
'Person'
,
counter_cache: :friends_too_count
belongs_to
:follower
,
class_name:
'Person'
end
activerecord/test/models/person.rb
浏览文件 @
f5ecb133
...
...
@@ -8,7 +8,10 @@ class Person < ActiveRecord::Base
has_many
:posts_with_no_comments
,
->
{
includes
(
:comments
).
where
(
'comments.id is null'
).
references
(
:comments
)
},
:through
=>
:readers
,
:source
=>
:post
has_many
:followers
,
foreign_key:
'friend_id'
,
class_name:
'Friendship'
has_many
:friendships
,
foreign_key:
'friend_id'
# friends_too exists to test a bug, and probably shouldn't be used elsewhere
has_many
:friends_too
,
foreign_key:
'friend_id'
,
class_name:
'Friendship'
has_many
:followers
,
through: :friendships
has_many
:references
has_many
:bad_references
...
...
activerecord/test/schema/schema.rb
浏览文件 @
f5ecb133
...
...
@@ -280,7 +280,7 @@ def create_table(*args, &block)
create_table
:friendships
,
:force
=>
true
do
|
t
|
t
.
integer
:friend_id
t
.
integer
:
person
_id
t
.
integer
:
follower
_id
end
create_table
:goofy_string_id
,
:force
=>
true
,
:id
=>
false
do
|
t
|
...
...
@@ -494,6 +494,7 @@ def create_table(*args, &block)
t
.
integer
:lock_version
,
:null
=>
false
,
:default
=>
0
t
.
string
:comments
t
.
integer
:followers_count
,
:default
=>
0
t
.
integer
:friends_too_count
,
:default
=>
0
t
.
references
:best_friend
t
.
references
:best_friend_of
t
.
integer
:insures
,
null:
false
,
default:
0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录