如何创建“视图” Grails 中的域对象
我正在尝试使遗留数据库适应 grails 应用程序,但我不确定如何在 grails 上做到这一点。我有一个巨大的表(包含列 colA、colB、...、colZ),我只想将其中一些映射为字段(例如 colA、colC、colE),就像数据库视图一样,该域类旨在被读取-只有这样,没有保存、更新和删除操作才不会出现问题。
我应该如何创建我的域类?
编辑
我需要调整一个域对象的查询,这个查询有很多分组依据表达式(最大、最小、计数等),我想调整这个查询,以便每次我调用 DomainObj.list() Grails 将运行此查询并从 GORM 代理内的数据库加载所有数据。
I'm trying to adapt a legacy database to a grails application and I'm not sure how can I do it on grails. I have a huge table (with columns colA, colB, ..., colZ) that I only want to map some of them as fields (say colA, colC, colE) like a database view, this domain class is intended to be read-only so it would not be a problem to not have the save, update and delete operations.
How should I create my domain class?
EDIT
I need to adapt a query to a domain object, this query has a lot of group by expressions (max, min, count, etc.) and I would like to adapt this query so that everytime I call DomainObj.list() Grails would run this query and load all the data from the database within the GORM proxy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果它是只读的,只需创建一个包含您感兴趣的字段的域对象。这应该没问题。
但请记住,GORM 将默认创建一个“版本”列,但这可以禁用:
If it is read only, just create a domain object containing the fields you are interested in. That should be no problem.
Remember however that GORM will create a "version" column as default, but this can be disabled: