gorm

How do I override the cascade delete for a relation in Grails GORM?

我怕爱的太早我们不能终老 提交于 2020-01-14 19:38:27
问题 I'm having some problems with the GORM part of Grails. I am using Grails 1.3.4, together with H2. In the database I have two tables template and report . On the GORM-level I have the two Domain classes Template and Report ; class Template { static hasMany = [reports: Report] ... } and class Report { static belongsTo = [template: Template] ... } Default behaviour seems to be that when a Template is deleted, the deletion will be cascaded so that all Report s that it has will be deleted as well.

How do I know if a Grails model was changed since its retrieval?

北城以北 提交于 2020-01-14 14:43:08
问题 I want multiple users to be able to edit models in a web browser at the same time and conflicts detected when the save (so that the first user to write doesn't have their changes overwritten without the second user explicitly saying so). Here's the example: User A retrieves object X and is looking at it in their browser. Then User B retrieves object X, looks at it in their browser, modifies it, and saves it causing a post to the REST api in Grails and a save on the model to the database. Then

How to save multiple object from one view using Grails

我的梦境 提交于 2020-01-14 06:05:11
问题 This question is in follow up to this post Grails one to many relationship view The example suggested there is not working and throwing following exception at run time null id in blog.omarello.Phone entry (don't flush the Session after an exception occurs). Stacktrace follows: Message: null id in blog.omarello.Phone entry (don't flush the Session after an exception occurs) Line | Method ->> 43 | doCall in blog.omarello.ContactController$_closure4$$ENLORkU6 - - - - - - - - - - - - - - - - - -

How to save multiple object from one view using Grails

為{幸葍}努か 提交于 2020-01-14 06:05:09
问题 This question is in follow up to this post Grails one to many relationship view The example suggested there is not working and throwing following exception at run time null id in blog.omarello.Phone entry (don't flush the Session after an exception occurs). Stacktrace follows: Message: null id in blog.omarello.Phone entry (don't flush the Session after an exception occurs) Line | Method ->> 43 | doCall in blog.omarello.ContactController$_closure4$$ENLORkU6 - - - - - - - - - - - - - - - - - -

Grails: Prevent cascading association between two domain classes with multiple relationships

人盡茶涼 提交于 2020-01-11 14:05:07
问题 Consider two domain classes; Job and Quote. A Job has many Quotes but a Job also has an accepted quote. The accepted quote is nullable and should only be set once a particular Quote has been accepted by a user. I have the relationships mapped as follows (simplified for the purpose of illustration). class Job { String title Quote acceptedQuote } class Quote { Job job BigDecimal quoteAmount } The resultant tables are exactly what I require (at least aesthetically) but the problem arises when I

Grails GORM: How do I create a composite primary key and use it for a table relationship?

倾然丶 夕夏残阳落幕 提交于 2020-01-11 10:55:28
问题 I have two tables, one of which (legacy table: A) has two fields that should serve as a composite foreign key and the other one (new table: B) should use a composite primary key for a each row:A has one row:B relationship. How do I describe these tables in terms of GORM? So far I've been able to create a domain class that reflects the legacy table:A class A { ... //composite foreign key to link B class String className; String eventName; B b; //instance of B to be related static mapping = {

Grails GORM: How do I create a composite primary key and use it for a table relationship?

删除回忆录丶 提交于 2020-01-11 10:55:25
问题 I have two tables, one of which (legacy table: A) has two fields that should serve as a composite foreign key and the other one (new table: B) should use a composite primary key for a each row:A has one row:B relationship. How do I describe these tables in terms of GORM? So far I've been able to create a domain class that reflects the legacy table:A class A { ... //composite foreign key to link B class String className; String eventName; B b; //instance of B to be related static mapping = {

Grails empty entry into the database

拥有回忆 提交于 2020-01-07 09:24:09
问题 I have been struggling with trying to create/save multiple instances at once in Grails, now I am almost there with the following code but when I hit save an empty row of options is created, can anyone help me with this please see these two questions to see what I want to achieve How to save multiple object from one view using Grails Grails one to many relationship view <g:textField name="question" value="${multipleChoiceQuestionInstance?.question}"/><br/> <div class="fieldcontain ${hasErrors

Grails changing datasource at runtime

回眸只為那壹抹淺笑 提交于 2020-01-07 06:14:23
问题 I was asked to implement a logic for having separate domains for a separate user (assuming he will have his own database) means all the domains will be mapped to different database at runtime. Sounds silly i know How can i change the datasouce(persistence configuration file) after logIn of user while datasource are supposed to load at startup time of application. Is it possible somehow? NOTE: I want to change datasource of some domain to another datasource at runtime one at a time. 回答1: You

Why is Grails hasMany List size wrong?

寵の児 提交于 2020-01-07 05:04:10
问题 I have a domain object Parent that has a hasMany relationship implemented as a List. I am getting an incorrect size of List returned and I don't know why: class Parent { List children static hasMany = [children : Child, otherHasMany : SomeOtherChildClass] static mapping = { children lazy: false } } def parent = Parent.get(someId) // parent is returned as a result of a query def numChildren = parent.children.size() I am getting a lot of null values interspersed amongst the correct Children