Hi folks :slightly_smiling_face: I'd like to devel...
# questions
g
Hi folks 🙂 I'd like to develop a scaffolding feature for my framework but I cannot find a way to execute a query having the Domain artefect, something I got like this:
Copy code
def domain = grailsApplication.getArtefact('Domain', 'MyDomainClass')
Is there a way to do it? Am I in the wrong direction?
m
Hi, I might be missing some context here, but this seems to work:
Copy code
class Book {
    String title
}
Copy code
def domainClass = grailsApplication.getArtefact('Domain', 'Book').clazz
domainClass.withTransaction {
    def book = domainClass.declaredConstructors[0].newInstance([title: 'Grails in Action'])
    book.save()
    book.list().each {
        println it.title
    }
}
g
Thank you @mattias_reichel I’ll give it a try 😎 👍🏻
Okay I've tried it but I need to call
list()
without creating a new instance of a Book. I still havent find a way, any suggestion?
m
Copy code
def domainClass = grailsApplication.getArtefact('Domain', 'Book').clazz
domainClass.withTransaction {
    domainClass.list().each {
        println it.id
    }
}
g
Thank you @mattias_reichel but I must be missing something, your code is not working for me, there is no
list()
method on the class. I'm on Grails 6
m
You cannot use
@CompileStatic
. Have you tried without that?