繁体   English   中英

grails域约束映射到postgresql Gist约束

[英]grails domain constraints mapping to postgresql Gist constraint

我有一个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,
 ...
)

和一个约束,以防止在同一日期进行两次相同属性的保留

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上使用拦截器之前和之后。

 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()
     }
  }

如果您需要更多帮助,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM