我有以下效果很好:
with_in_schemas :only => %w{schema1 schema2} do
@user = User.count
end
和输出如
@user => 14
我想从帐户中获取架构名称,我有这个:
@accounts = Account.all
@accounts.each do |t|
with_in_schemas :only => t.schema do
@user = User.count
end
end
但输出为零
@user => 0
有schema1
14 个user
和schema2
0 个用户。
更新
我尝试添加 1 个用户schema2
现在schema1
有 14 个user
和schema2
1 个用户。
在控制器上
@accounts = Account.all
@accounts.each do |t|
with_in_schemas :only => t.schema do
@user = User.count
end
end
和输出
@user => 1
我想计算来自schema1
和的用户schema2
@accounts = Account.all
@count_user = 0
@accounts.each do |t|
with_in_schemas :only => t.schema do
@user = User.count
end
@count_user = @count_user + @user
end
和输出
@count_user => 2
为什么只有最后一个模式得到用户表的计数?