我正在尝试在rails中构建一个广告网络类型的应用程序,它将允许创建具有类似以下属性的活动:

我希望用户能够选择多天,地点和时间段在一天的活动运行(可以在图像中看到)。然后,给定客户端的位置、星期几和一天中的时间段,客户端将拉出具有这些相应属性的这样的广告。
我知道这是一个复杂的模型,高效地构建它至关重要。是否有关于模型应该如何布局的教程或见解?
发布于 2014-01-25 07:12:24
将计划存储为iCalendar rrule (如果您愿意,也可以存储为更规范化的版本)。
创建一个函数以返回规则的即将到来的日期。
如果需要,可以创建即将到来的日期的实体化视图,以提高性能。
PostgreSQL Functions for RRULE handling
使用表继承来模拟地理位置。你应该认为城市是州的孩子,而不是县的孩子,因为有些城市包含县。
您希望能够将单个外键指向抽象的地理位置,例如"Ohio“或"Cuyahoga County,Ohio”
使用连接表将多个位置映射到一个活动。
--postgresql syntax
create table campaigns (
campaign_id int primary key,
name text unique,
rrule text not null check ( is_valid_rrule(rrule) ) --you would need to write this
);
create table locations (
location_id int primary key,
type text not null check ( type in ('COUNTRY', 'PRIMARY_DIVISION','SECONDARY_DIVISION') ), --use a lookup table in real life
name text not null,
parent_id int null references locations (location_id) check ( type = 'COUNTRY' or parent_id is not null),
unique (name, parent_id)
);
create table campaign_locations (
campaign_id int references campaigns(campaign_id),
location_id int references locations(location_id),
primary key (campaign_id, location_id)
);
--insert some locations:
insert into locations values
(1, 'COUNTRY', 'United States of America', null),
(2, 'PRIMARY_DIVISION', 'Ohio', 1),
(3, 'SECONDARY_DIVISION', 'Cuyahoga County', 2),
(4, 'SECONDARY_DIVISION', 'Adams County', 2);
--create a campaign with a recurrence rule:
insert into campaigns values
(1, 'My Campaign', 'FREQ=WEEKLY;BYDAY=MO,WE');
--associate a campaign with Cuyahoga and Adams counties:
insert into campaign_locations values
(1, 3),
(1, 4);https://stackoverflow.com/questions/20296970
复制相似问题