[英]Creating DB views in Ruby on Rails
I'm adding reporting functionality to a project. 我正在向项目添加报告功能。
3 roles here: 这里有3个角色:
1) Volunteers (they report what hours they volunteered) 1)志愿者(他们报告他们自愿参加的时间)
2) Supervisors (they look at the reported stuff, note: one supervisor can view all projects) 2)主管(他们查看报告的内容,注意:一位主管可以查看所有项目)
3) Projects (Represents a work project that some collection of volunteers work on) 3)项目(代表一些志愿者参与的工作项目)
To explain what it does: 要解释它的作用:
A report will be specified by the supervisor to generate based on a query of what he needs. 主管将指定一份报告,以根据他的需求查询生成报告。
These could be plausible reports: 这些可能是合理的报告:
1) The total number of volunteers, and the total amount of volunteer hours on this project 1)此项目的志愿者总数和志愿者工时总数
2) All the volunteer's names and emails associated with a project 2)与项目相关的所有志愿者的姓名和电子邮件
3) The number of active projects vs. the total number of projects 3)活动项目数与项目总数
I was thinking maybe that creating a database view in Rails and storing the name of that view so Rails will just check the view whenever a supervisor wants to pull up the report. 我在想,也许是在Rails中创建数据库视图并存储该视图的名称,因此,每当主管想要提取报告时,Rails都只会检查视图。
Is a view really the answer or is it better to just save a query? 视图真的是答案吗?还是仅保存查询会更好?
Can Rails do this or is there an even better or more simple way of achieving this functionality? Rails可以做到这一点吗?或者有更好或更简单的方法来实现此功能?
Edit: A report is essentially a sql query in the back. 编辑:报告本质上是后面的sql查询。 We want supervisors to be able to create their own reports as well.
我们希望主管也能够创建自己的报告。 We intend to build some front end UI to make it easier.
我们打算构建一些前端UI来简化它。
I just thought that having a table storing the views would be more descript (ReportID, ViewName) than a table storing the SQL query (ReportID, SQLQuery). 我只是认为拥有一个存储视图的表比存储SQL查询(ReportID,SQLQuery)的表更具描述性(ReportID,ViewName)。 Also I was thinking of saving space very specialized SQL queries get very large and confusing.
我还想节省空间,非常专业的SQL查询变得非常大且令人困惑。 I apologize for being confusing since I am really new to Ruby and Rails
我很困惑,因为我是Ruby和Rails的新手
For example: I was thinking what could be powering the #2 report would be this query (or equivalent code for view: select v.volunteerName, v.volunteerEmail from volunteers v,volunteering vg where v.volunteerId = vg.volunteerId AND vg.projectId = (Some Arguement passed by user) 例如:我在想#2报告可能是该查询(或等效的视图代码:选择v.volunteerName,v.volunteerEmail来自自愿者v,志愿者vg,其中v.volunteerId = vg.volunteerId和vg。 projectId =(用户传递的某些参数)
Note that the volunteering database is a relationship database as a volunteer can volunteer for more than one project. 请注意,志愿者数据库是一个关系数据库,因为志愿者可以为多个项目提供志愿者。
Cheers, -Jeremiah Tantongco 干杯,耶利米·坦通科(Jeremiah Tantongco)
Your question is a bit confusing confusing, but I think you need to: 您的问题有点令人困惑,但我认为您需要:
Kevin 凯文
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.