我有一个PostgreSQL表
CREATE TABLE reservation_table (
idreservation SERIAL NOT NULL,
entry_datetime TIMESTAMPTZ NOT NULL DEFAULT 'NOW',
start_end_dates DATERANGE NOT NULL ,
property_id INT NOT NULL REFERENCES property_table,
...
)
以及防止在同一日期对同一财产进行2次保留的限制
ALTER TABLE ONLY reservation_table
ADD CONSTRAINT reservation_double_booking_constraint
EXCLUDE USING gist
(property_id WITH =, start_end_dates WITH &&)
;
我可以在Grails保留域中强制执行SQL约束吗?
我正在考虑使用视图访问预订,以避免groovy 中postgresql范围的问题
create view resView as
select idReservation,
lower(start_end_dates) AS startDate,
upper(start_end_dates) AS endDate,
property_id
from reservation_table
好的,但你指定了非常少的信息来解决这类问题,因为我还没有完全理解,所以我有以下建议。
在grails上使用before和after拦截器怎么样。
class Reservation {
Date startDate ...
def beforeInterceptor = {
//do some date validation here start data or end date
//for exmaple you might check that we have
//any start date currently existing on db
//by findbyStartDate or endDate
//then reject the reservation or saving of this model
println "validation error here , cancel save"
}
static constraints = {
//do some validation here related to ur constraint
startDate max: new Date()
}
}
如果你需要更多帮助,请告诉我。