gorm

Grails one to many relationship view

好久不见. 提交于 2019-12-01 12:57:07
I have two grails domain classes Class MultipleChoiceQuestion { String question static constraints = { ... } static hasMany = [options:MultipleChoiceOption] } and class MultipleChoiceOption{ String answerOption boolean correctOption MultipleChoiceQuestion question static constraints = { ... } } I want my users to be able to create a question then add atleast 3 options without navigating/clicking on different screens. My first question is must I generate view and start editing code? And if the answer to question above is yes then my second question is, what's the best way to save a question

Grails one to many relationship view

核能气质少年 提交于 2019-12-01 12:02:08
问题 I have two grails domain classes Class MultipleChoiceQuestion { String question static constraints = { ... } static hasMany = [options:MultipleChoiceOption] } and class MultipleChoiceOption{ String answerOption boolean correctOption MultipleChoiceQuestion question static constraints = { ... } } I want my users to be able to create a question then add atleast 3 options without navigating/clicking on different screens. My first question is must I generate view and start editing code? And if the

GORM prevent creation of a foreign key constraint for a Domain

梦想与她 提交于 2019-12-01 10:49:43
I am developing a web based application in Grails. I have come across a situation where I would like to try and suppress GORM from creating a foreign key constraint on a field in a table. I have a domain class which is part of a class hierarchy. The domain class essentially acts as a link to a target domain. The target domain can be of different types and each of the subclasses of this link domain is designed to provide the link for each specific type of linked item. These linked items have certain behaviour in common i.e. implement the same interface but otherwise are different to the point

Custom event listener example in Grails documentation

偶尔善良 提交于 2019-12-01 09:50:31
I'm trying to add a custom GORM event listener class in Bootstrap.groovy , as described in the Grails documentation but its not working for me. Here is the code straight from the docs: def init = { application.mainContext.eventTriggeringInterceptor.datastores.each { k, datastore -> applicationContext.addApplicationListener new MyPersistenceListener(datastore) } } When I run it, the compiler complains that application and applicationContext are null. I've tried adding them as class level members but they don't get magically wired up service-style. The closest I've got so far is: def

GORM fails to realize Domain classes from a plugin are GORM classes

大憨熊 提交于 2019-12-01 07:39:00
I am trying to use a Grails Project as a Plugin to basically have my domain classes in the Plugin and then use them in multiple Grails projects. I've done this: grails create-app web grails create-app plugin create a settings.gradle in the root directory of both projects with include 'plugin', 'web' then I added spring security to the plugin and used s2-quickstart to create a user and a role domain class and added some default users to the Bootstrap.groovy. Starting the plugin project alone doesn't show any issues. Now I added the plugin as a dependency to the web project: compile (':plugin')

Custom event listener example in Grails documentation

◇◆丶佛笑我妖孽 提交于 2019-12-01 06:49:05
问题 I'm trying to add a custom GORM event listener class in Bootstrap.groovy , as described in the Grails documentation but its not working for me. Here is the code straight from the docs: def init = { application.mainContext.eventTriggeringInterceptor.datastores.each { k, datastore -> applicationContext.addApplicationListener new MyPersistenceListener(datastore) } } When I run it, the compiler complains that application and applicationContext are null. I've tried adding them as class level

Using Hibernate HQL Named Queries in Grails?

微笑、不失礼 提交于 2019-12-01 05:59:14
问题 Is there a way to use Hibernate Named Queries in Grails, using HQL? I've been reading about them in the Harnessing Hibernate book, and wondered if there was a way to use them in Grails. Named queries are included, along with the class mappings, in a <class-name>.hbm.xml mapping files like so: <query name="com.oreilly.hh.tracksNoLongerThan"> <![CDATA[ from Track as track where track.playTime <= :length ]> </query> Now I'm certain that an <class-name>.hbm.xml hibernate mapping file can be

GORM fails to realize Domain classes from a plugin are GORM classes

别等时光非礼了梦想. 提交于 2019-12-01 05:59:08
问题 I am trying to use a Grails Project as a Plugin to basically have my domain classes in the Plugin and then use them in multiple Grails projects. I've done this: grails create-app web grails create-app plugin create a settings.gradle in the root directory of both projects with include 'plugin', 'web' then I added spring security to the plugin and used s2-quickstart to create a user and a role domain class and added some default users to the Bootstrap.groovy. Starting the plugin project alone

Sort by association count in Grails

隐身守侯 提交于 2019-12-01 05:43:53
问题 I have many Topic objects and each Topic hasMany posts:Post How can I order all Topic objects based on their posts count?? 回答1: You can do it, but it requires two queries. This is because to order by the size of a collection, you need to use a 'group by' but this requires that you enumerate all of your Topic properties. If you add or remove one the query will break. So the solution is to run one query that finds ordered ids, and a second that gets the instances for those ids: String hql = '''

Grails Entity without persist

孤街浪徒 提交于 2019-12-01 04:38:41
问题 I have a domain class in grails... How do I get gorm to leave out this entity when it create the db? Just leave it alone. 回答1: If i understood, u want not create table from domain class? If yes, use this code inside domain class: static mapWith = "none" // disable persisting into database 回答2: Sounds like you don't need it to be a domain class then. You could just make it a POGO in the src/groovy file. If my assumptions here are wrong please explain further what you're trying to accomplish.