我怎样才能给出别名includes()?以下是:
这里有一些例子:
第一个案例(更多STI协会)
Project.all.includes(:students, :teachers).order('teachers_projects.name ASC') # order on teachers
Project.all.includes(:students, :teachers).order('users.name ASC') # order on students
Run Code Online (Sandbox Code Playgroud)
Rails的自动使用别名teachers_projects为:teachers在SQL.我怎样才能覆盖这个,以便我可以使用别名teachers而不是teachers_projectsSQL?:students获取别名users.
这个例子失败了:
Project.all.includes(:students, :teachers).order('teachers.name ASC')
Project.all.includes(:students, :teachers).order('students.name ASC')
Project.all.includes(:students, :teachers).order('students_projects.name ASC')
Run Code Online (Sandbox Code Playgroud)
第二个案例(一个STI协会)
如果我只使用:students(不:teachers)方法includes(),Rails使用STI基类名称的名称别名users(没有_projects附加):students:
Project.all.includes(:students).order('users.name ASC') # order on students
Run Code Online (Sandbox Code Playgroud)
这个例子失败了:
Project.all.includes(:students).order('students.name ASC')
Project.all.includes(:students).order('students_projects.name ASC')
Run Code Online (Sandbox Code Playgroud)
题
可能存在类似于:
Project.all.includes(:students).alias(students: :my_alias)
Run Code Online (Sandbox Code Playgroud)
RAILS ALIAS TRACKER
测试应用程序 …
activerecord ruby-on-rails arel ruby-on-rails-3 ruby-on-rails-4
如何在rails中动态配置验证?例如,如果我有
validates_length_of :name, within => dynamic
Run Code Online (Sandbox Code Playgroud)
变量"dynamic"将由用户设置.在保存时,验证应使用变量"dynamic"的值来配置内部配置.
我试图用上帝监视redis但是上帝试图重新启动它,即使它已经在运行.这是我的.god脚本(移植自http://blog.thomasmango.com/post/636319317/resque-in-production):
# Redis
%w{6379}.each do |port|
God.watch do |w|
w.name = "redis-server"
w.interval = 30.seconds
w.start = "/etc/init.d/redis-server start"
w.stop = "/etc/init.d/redis-server stop"
w.restart = "/etc/init.d/redis-server restart"
w.start_grace = 10.seconds
w.restart_grace = 10.seconds
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = 5.seconds
c.running = false
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
现在当我像这样开始上帝:
god -c /home/phlegx/workspace/projectx/config/god/config.god -D --log-level debug
Run Code Online (Sandbox Code Playgroud)
我得到以下输出:
I [2011-04-28 18:32:10] INFO: Loading /home/phlegx/workspace/projectx/config/god/config.god
I [2011-04-28 18:32:10] INFO: Syslog enabled.
I [2011-04-28 18:32:10] INFO: Using pid file directory: /var/run/god …Run Code Online (Sandbox Code Playgroud) 我想订购一些与另一个模型有关系的模型的记录(带有翻译的属性).这是一个例子:
现在,我想通过其任务名称来订购所有项目.我怎么写这个范围?如何在Rails中加入转换表,如gem globalize中的方法with_translation(https://github.com/globalize/globalize/blob/eccb924ac9641b52399f22525b0e3ec004739f4c/lib/globalize/active_record/class_methods.rb),但是来自相关对象Project?
> Project.all.joins(:tasks) ... (how to include task translation table) ...
Run Code Online (Sandbox Code Playgroud) ruby-on-rails relationship has-many-through ruby-on-rails-4 globalize
我的情况:
每个工人的查询:
BEGIN;
INSERT INTO "test_tbl" ("id",...) VALUES
(...),(...),...[1000 entries]... RETURNING id;
COMMIT;
Run Code Online (Sandbox Code Playgroud)
表test_tbl仅PRIMARY KEY (id)具有索引约束CREATE UNIQUE INDEX formulas_pkey ON formulas USING btree (id)
问题
经过许多小时的分析,它接缝的是工人等另一个工人完成了插入。为什么工人不能同时将新数据插入同一张表?
我删除了所有约束和所有索引(主键,外键等),但仍然存在相同的问题。没有并行化。
补充说明:
postgresql parallel-processing multithreading bulkinsert sql-insert
activerecord ×1
arel ×1
bulkinsert ×1
dynamic ×1
globalize ×1
god ×1
monitoring ×1
postgresql ×1
redis ×1
relationship ×1
sql-insert ×1
validation ×1