grails-domain-class

Grails BootStrap: No signature of method: *.addTo* applicable

放肆的年华 提交于 2019-12-12 02:05:15
问题 I have two domain classes: User class User { String username String password String email Date dateCreated Date lastUpdated // static belongsTo = [profile: Profile] static constraints = { username size: 3..20, unique: true, nullable: false, validator: { _username -> _username.toLowerCase() == _username } password size: 6..100, nullable: false, validator: { _password, user -> _password != user.username } email email: true, blank: false // profile nullable: true } } and Profile: class Profile {

Grails + Mongo: GORM mysteriously thinks a object referenced by an embedded field has a changed propery

别说谁变了你拦得住时间么 提交于 2019-12-11 12:30:09
问题 I have a domain class called Form which has an embedded field called union of type Organization which is embedded. Organization has the field createdByUser . User has a field organization of type Organization added by AST transformation. So, whenever i try to save a Form object, it tries to change the user reference by createdByUser to an organization id of 1 for mysterious reasons. 来源: https://stackoverflow.com/questions/30714307/grails-mongo-gorm-mysteriously-thinks-a-object-referenced-by

Grails read from existing DB

寵の児 提交于 2019-12-11 12:17:14
问题 I want to fetch data from already existing database from another project into my Grails project and list the data. Should I be creating a domain controller for the already existing db? I know how to create domain-controller and use data migration plugin to update db but none of the books I read had any information on how to setup and read from an existing database. I'm using MySQL for my database. 回答1: Use the Reverse Engineer plugin to create domain classes from your existing database: http:

Using a legacy Neo4j database with Grails

爷,独闯天下 提交于 2019-12-11 10:48:59
问题 I would like to use the ENRON GraphML dataset, loaded into Neo4j, as a database for my Grails 2.0 application. The use-case for the data is read-only. I have had no trouble loading the dataset and creating a database in a stand-alone application, and now would like to use the Grails plugin to manage access to the database. Looking at the Neo4J plugin documentation on mapping domain classes, I see that it requires subreference nodes for each type of vertex. My data doesn't have that. I can see

grails domain class .list() method with params

走远了吗. 提交于 2019-12-11 09:27:24
问题 I have two domains that are connected with one-to-many relation - One User may have many Associations. I want to view all associations that belong to this user. I'm using scaffolding plugin. So code that should return list of Associations in AssociationController looks lile this: def index(Integer max) { respond Association.list(params), model:[associationInstanceCount: Association.count()] } And on the User view page I have the following code: <g:form controller="Association" > <fieldset

can GORM duplicate whole object?

我的梦境 提交于 2019-12-11 08:36:16
问题 we are using grails to develop some web application For Domain class that have child class , I'm wondering if we can duplicate whole object including all child object that belong to Parent ? Thank you 回答1: As given in the comments, you can extend gorm with a clone method. However, a very simple solution if you don't want to mess with the gorm api is to detach the existing object and just "resave" it. Note that this won't perform a deepClone . Steps: Null the id. Update fields that should

Overriding default `maxSize` in domain class

拥有回忆 提交于 2019-12-11 06:35:26
问题 I've set a default value, for maxSize constraint, to all my domains, using config.grails.gorm.default.constraints = { ... '*'(..., maxSize: 80) ... } Now, I want to override this value inside my domain class; I can do that by defining it there static constraints = { ... prop maxSize: 120 ... } But how could I make it unlimited, for instance? I wish it could have been done by providing -1 . Or the String and other Collection s could have been handled differently, by using two different

How to avoid loss of DB when changing Grails domain class in development

坚强是说给别人听的谎言 提交于 2019-12-10 18:17:27
问题 One of the advantages of Grails 2.0 is that you can change domain classes in development without needing to restart the application server. This works, however when I change domain classes I lose all my bootstrap data, which basically defeats the purpose. I'm using the default h2 database. What is the best way to get around this? Do I have to go to an external DB like Postgres? 回答1: The default DataSource.groovy in a newly-created Grails 2 app has environments { development { dataSource {

How to implement Self-Referencing Relationships in Grails?

落花浮王杯 提交于 2019-12-10 17:34:59
问题 Given the following User class: class User { String name static hasMany = [friends: User] } I want that a User can have many friends which are instances of the user domain class. How do I have to implement the friend relationship of a user? 回答1: 1. How Do you Define the relathionship class User { static hasMany = [ friends: User ] static mappedBy = [ friends: 'friends' ] //this how you refer to it using GORM as well as Database String name String toString() { name } def static constrains () {

How to unit test grails domain class that has a relational mapping?

牧云@^-^@ 提交于 2019-12-10 16:37:47
问题 The output of my test gives com.example.book.Book : null . When I debug the test, b object is created with "MyBook" as its name . But since its has a static mapping belongsTo , the test fails. How do I make this work. When I comment the belongsTo mapping in the Books.groovy, the test passes. So how do I test Domain classes with mappings. Should I instantiate a Library object and add a Book object to it? But that doesn't make testing the domain class in isolation as it is meant to be in a unit