我一直在反反复复地思考如何构建这个架构。我使用rails,一开始是单表继承,然后改变了主意,现在我不确定了。
BusinessHours business_id,主板,day_of_week,start_time,主板,stop_time
StaffHours staff_id,主板,day_of_week,start_time,主板,stop_time
显然,工作人员属于企业,但是他们的工作时间表是相同的。
我是否应该将它们存储在一个表中,并添加一个类似'keeper_id‘的字段来存储员工或企业的id,以及一个存储'staff_hours’或'business_hours‘的'type’字段来区分这两者(员工和企业可能具有相同的id,因此我需要区分)
但我觉得我就快回到STI了??
有什么想法?
发布于 2010-10-10 03:24:59
但是,您应该将相似的数据放在一起,仅仅因为列看起来相同并不意味着数据相似。我会说你在模拟两个不同的东西,所以使用两个表。此外,当您添加两组小时共有的列时,您还会允许这些表随时间的推移而不同,比如休息时间、午餐时间、最低员工要求或经理要求,或者……
发布于 2010-10-10 03:56:00
在我看来,你似乎是在模拟一些东西(员工,业务,无论什么)和它的工作时间。
因此,我将有一个业务,员工和工时模型。随着小时模型与业务、员工和其他任何你可能需要它的东西之间的多态关系,你可以:
http://guides.rubyonrails.org/association_basics.html#polymorphic-associations
小时模型将具有指向业务或员工记录的hourable_id和hourable_type字段。
发布于 2010-10-10 03:58:05
我更倾向于这样想:
A table defining Businesses:
create table Businesses
(
Business_Id integer,
Business_Name varchar(100),
etc...
)
A table defining Employees:
create table Employees
(
Business_Id integer,
Employee_Id integer,
Employee_Name varchar(100),
etc...
)
A table defining the type of work shifts the businesses will use:
create table Shifts
(
Business_Id integer,
Shift_Id integer,
Shift_Name varchar(100),
StartTime datetime, -- Just the time of day the shift starts
Duration datetime, -- Duration of the shift
etc ...
)
Then a table defining the Schedule:
create table Schedule
(
Business_Id integer,
Shift_Id integer,
Employee_id integer,
WorkDate datetime, -- just the date, time comes from Shift table
etc ...
)
Then your query to display the work calendar for everyone would be:
select
b.Business_Name,
e.Employee_Name,
s.WorkDate + sh.StartTime as ShiftStart,
s.WorkDate + sh.StartTime + sh.Duration as ShiftEnd,
etc ...
from
Businesses b
JOIN Schedule s
on ( s.Business_Id = b.Business_Id )
JOIN Employees e
on ( e.Business_Id = s.Business_Id
and e.Employee_id = s.Employee_Id )
JOIN Shifts sh
on ( sh.Business_Id = s.Business_Id
and sh.Shift_Id = s.Shift_Id )然后是另一个跟踪实际打卡/打卡时间的表。
诸如此类的事情。
https://stackoverflow.com/questions/3897519
复制相似问题