0

我有一个来自审计日志插件的默认审计日志表,如下所示:

审计日志: id | class_name | event_name | ...

我想为记录的事件提供人类可读的描述。我决定添加另一个带有描述的表:

审核事件: id | class_name | event_name | description

并将这些描述映射到 和 上的第一个class_nameevent_name

我有以下域类:

class AuditLog {

Integer id;
String actor;
String className;
Date dateCreated;
String eventName;
Date lastUpdated;
String newValue;
String oldValue;
Integer persistedObjectId;
String persistedObjectVersion;
String propertyName;
String uri;
AuditEvent event;

static mapping = {
    table 'audit_log';
    version false;
    cache usage: 'read-only';

    id column: 'id';
    actor column: 'actor';
    className column: 'class_name';
    dateCreated column: 'date_created';
    eventName column: 'event_name';
    lastUpdated column: 'last_updated';
    newValue column: 'new_value';
    oldValue column: 'old_value';
    persistedObjectId column: 'persisted_object_id';
    persistedObjectVersion column: 'persisted_object_version';
    propertyName column: 'property_name';
    uri column: 'uri';

}

但我不知道如何为AuditEvent event. 在这里,我想使用现有字段class_name | event_name作为复合外键与audit_event表链接。将感谢您的帮助。

upd:假设 AuditEvent 具有字段auditedClassevent

4

1 回答 1

0

I'm not sure whether I really understood your question, but from the question how to write mapping for the AuditEvent event, I think you can map the AuditEvent class separately, just as what you have done to class AuditLog:

Class AuditEvent {
    String auditedClass
    String event
    String description
    ....

    static mapping = {
        table 'audited_event'
        auditedClass column: 'class_name'
        event column: 'event_name'
    }
}
于 2013-01-24T10:20:37.690 回答