Skip to content

Setting dynamic attrs causes problem when mongo backed domain is using class inheritance. #14415

@aeischeid

Description

@aeischeid

Domains like Certificate and SpecialCert extends Certificate. Things work well. _class is added to each document when doing inserts.

However, since upgrade to grails 2.5.2 and 3.0.3 version of the mongo plugin I now have a problem when adding dynamic attributes before the first save. It causes the _class not to be inserted into mongo, and this in turn causes something like SpecialCert.get(id) to not return the document later.

There is a workaround. Just do the .save() first then add the props and do another .save(), but it is a definite gotcha.

if (!specialCert.hasErrors()) {
     specialCert.save()
    // for some reason if we try to stamp the markerKey before the first .save() GORM mongo
    // loses that what class this is and misses putting the _class into the DB causing probs later
    String markerKey = ourService.getMarkerKey()
    if (markerKey) specialCert['markerKey'] = markerKey
    specialCert.save()
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions