Print Page | Close Window

Emitting ManyValuedAssociation

Printed From: TMS Software
Category: Business Tools
Forum Name: Data Modeler
Forum Discription:
Printed Date: 22 Nov 2019 at 6:13pm

Topic: Emitting ManyValuedAssociation
Posted By: Byrne William
Subject: Emitting ManyValuedAssociation
Date Posted: 19 Jul 2014 at 1:07pm
What are the minimum Data Modeler and schema requirements (let's say for MSSQL) to emit the [ManyValuedAssociation] attribute for entity relationships exported by DM for Aurelius? 

I'd like to take advantage of the TAureluisDataset.DatasetField property thinking master-detail relationships will be automatically synchronized. I'm hoping this would eliminate the necessity of manually detecting row changes to the parent with a corresponding refresh to the child. The implementation in this particular scenario is using the classic TDataSource, TDBGrid, and TDBNavigator configuration.

Posted By: Byrne William
Date Posted: 20 Jul 2014 at 1:47am
Partial success...

I discovered the Many-Valued Associations option on DM's Aurelius export dialog. Specifically, I selected the parent table in the Mappings section, then enabled the MVA property for the child table located in the Many-Value Associations section. With this option enabled, the expected ManyValuedAssociation attribute was emitted thereby providing the anticipated master-detail code support I mentioned in my initial post.

I'm now noticing that it's necessary to manually assign the parent entity to the child's FK field in the dataset's BeforePost handler. If this isn't done, the native CheckRequiredFields method in Data.DB.pas triggers a "Field Required" exception (because the given FK field was never set and remains Null.) When this native check is bypassed (via debugging,) the process continues until SQL complains about a Null value in the child's FK column. This seems to indicate the FK is never set by the ORM. The child's FK column in this scenario is not permitted to be Null in the SQL schema.

The Data Modeler version is

Posted By: Wagner R. Landgraf
Date Posted: 20 Jul 2014 at 5:41pm
If the ManyValuedAssociation is bidirectional (i.e, if you have a property "Parent" (or whatever) in the detail class pointing back to the master class), then you must set that property yourself. If the association is unidirectional, then Aurelius fills that field automatically for you.

Print Page | Close Window