gorm

Cannot find node using graphDatabaseService when it is created in the same test

风流意气都作罢 提交于 2019-12-11 16:21:10
问题 as continuation of Trying out neo4j grails plugin, but it does not mach the docs I have a test now looks like this: package com.iibs.graph import groovy.util.GroovyTestCase import com.iibs.graph.Node public class NodeTests extends GroovyTestCase { def graphDatabaseService void testCRUD() { Node.deleteAll(Node.list()) Node node = new Node(name: "Name") node.save(flush: true, failOnError: true) Node found = Node.findByName("Name") assert found instanceof Node assert found.getName() == "Name"

Grails - Can't add child record to parent

前提是你 提交于 2019-12-11 14:11:54
问题 Trying to follow the example shown here I am trying to create a record which links to a parent record. In my case I have two classes: Sensor, and Readings. I can create Sensors without any issues, but no matter how I try to create readings I seem to fail :( I've been spinning my wheels for long enough, I'm throwing in the towel and hoping someone can spot my silly mistake(s). One more thing - I want to post the data using JSON. But through the debugging process I'm not even looking at the

Grails3 unit test for domain class with derived property

岁酱吖の 提交于 2019-12-11 12:36:55
问题 I have the following Domain class with derived property lowercaseTag . class Hashtag { String tag String lowercaseTag static mapping = { lowercaseTag formula: 'lower(tag)' } } If I run the following unit test, it will fail on the last line, because lowercaseTag property is null and by default all properties have nullable: false constraint. @TestFor(Hashtag) class HashtagSpec extends Specification { void "Test that hashtag can not be null"() { when: 'the hashtag is null' def p = new Hashtag

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

Cloning an instance of domain in Grails

坚强是说给别人听的谎言 提交于 2019-12-11 12:26:22
问题 I'm wondering how I would go about adding the functionality of cloning to my grails application. I've attached an image below that explains how my domain classes are associated. One template has many steps and those steps each have many inputs and or outputs. Currently I can view my templates on the index.gsp page but I want to be able to clone entire templates along with their steps/inputs/outputs that they contain aswell. Is this possible and if so how? 回答1: Here is a version of deep

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:

Grails createCriteria on abstract domain

痴心易碎 提交于 2019-12-11 11:45:12
问题 I am quite curious how one would use the criteria builder to access fields of an inherited class. Let's assume we have the following class: class A { String fieldOne String fieldTwo static hasMany = [childs: AbstractChildClass] } and the abstract child class would look like this: abstract class AbstractChildClass { Integer valueOne Integer valueTwo A a static mapping tablePerHierarchy false } } of course there are several extending classes such as: class ExtendingClassOne extends

Relationships between Grails domain classes with inheritance

假装没事ソ 提交于 2019-12-11 11:19:46
问题 I have the following class. In src/groovy , class Profile { String firstName String middleName String lastName byte[] photo String bio } The domain classes BasicProfile and AcademicProfile extend Profile . class BasicProfile extends Profile { User user Date dateCreated Date lastUpdated static constraints = { firstName blank: false middleName nullable: true lastName blank: false photo nullable: true, maxSize: 2 * 1024**2 bio nullable: true, maxSize: 500 } static mapping = { tablePerSubclass

How can I use more than one set of constraints on a single domain class in Grails?

…衆ロ難τιáo~ 提交于 2019-12-11 11:16:37
问题 I need to choose a set of validation rules at save time. Ideally I would like to be able to define more than one set of constraints in the domain class: class Account { ... static constraints = { ... } static constraints2 = { ... } } I know I can do my own validation in code (account.errors.rejectValue(...) etc) but I am looking to save some time by using the built in Grails validation if possible. 回答1: This is what Command Objects are for. The reason you can't just swap out validation is