gsartori commented on code in PR #15599:
URL: https://github.com/apache/grails-core/pull/15599#discussion_r3164034672
##########
grails-doc/src/en/guide/GORM/quickStartGuide/basicCRUD.adoc:
##########
@@ -91,6 +136,128 @@ def p = Person.get(1)
p.delete()
----
+If a delete operation fails (for example due to database constraints), an
exception is thrown.
+
+You can handle this using a `try/catch` block:
+
+[source,groovy]
+----
+def p = Person.get(1)
+try {
+ p.delete(flush: true)
+
+} catch (Exception e) {
+ println "Delete failed: ${e.message}"
+}
+----
+
+Unlike the link:{domainClassesRef}save.html[save] method, the `delete` method
does not support a `failOnError` parameter. Instead, errors are propagated as
exceptions.
+
+Using `flush: true` ensures the delete is executed immediately, so any errors
are raised at that point.
+
+=== Querying
+
+To dynamically build queries based on optional parameters a common pattern is
to use `DetachedCriteria` and progressively compose filters depending on the
provided inputs.
+
+==== Properties
+
+Consider the following example using the `Person` domain class:
+
+[source,groovy]
+----
+import grails.gorm.DetachedCriteria
+
+private DetachedCriteria<Person> buildQuery(Map filterParams) {
+ def query = Person.where {}
+
+ if (filterParams.containsKey('id')) query = query.where {
+ id == filterParams.id
+ }
Review Comment:
Same here, styling, it was made like that to give more space to meaningful
code while inlining redundant low-value code. Okay to reformat it the standard
way.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]