AuditReferenceOfRelatedEntity question

Posts   
 
    
LukeO
User
Posts: 58
Joined: 23-Jul-2007
# Posted on: 04-Feb-2008 21:19:34   

I have two questions about the AuditReferenceOfRelatedEntity method.

1) I have a parent and child table where the child table has a foreign key to the parent that is enforced by the database using the usual referential integrity rules. So here is my thinking:

a. I create a parent entity, save it to the database and refetch to the get the ID. b. I create a child entity. Add this child to the parent's children and save the child.

The AuditReferenceOfRelatedEntity method does not know of the child's primary key value since it was accessed somewhere between steps a and b above. Obviously I cannot save the child first before assigning the parent. Is there a way AuditReferenceOfRelatedEntity can get access to the child entity primary key value(s)?

2) The mapped field name parameter seems to give me mapped entity name and NOT the mapped field name as the parameter name seem to suggest.

Thanks, -Luke

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 05-Feb-2008 11:55:38   

a. I create a parent entity, save it to the database and refetch to the get the ID.

You don't have to refetch btw.

b. I create a child entity. Add this child to the parent's children and save the child.

The AuditReferenceOfRelatedEntity method does not know of the child's primary key value since it was accessed somewhere between steps a and b above. Obviously I cannot save the child first before assigning the parent. Is there a way AuditReferenceOfRelatedEntity can get access to the child entity primary key value(s)?

If the ID is autogenerated at the database, How would the method know the value before the entity gets saved?

LukeO
User
Posts: 58
Joined: 23-Jul-2007
# Posted on: 05-Feb-2008 17:50:29   

That is correct but if the entity got refetched before the audit was saved then it would... right?

Walaa wrote:

a. I create a parent entity, save it to the database and refetch to the get the ID.

You don't have to refetch btw.

b. I create a child entity. Add this child to the parent's children and save the child.

The AuditReferenceOfRelatedEntity method does not know of the child's primary key value since it was accessed somewhere between steps a and b above. Obviously I cannot save the child first before assigning the parent. Is there a way AuditReferenceOfRelatedEntity can get access to the child entity primary key value(s)?

If the ID is autogenerated at the database, How would the method know the value before the entity gets saved?

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 06-Feb-2008 15:18:07   

That is correct but if the entity got refetched before the audit was saved then it would... right?

Yes (I guess you mean if it was saved, before the audit was saved).