Foreign key may refer to different classes

Posts   
 
    
ww
User
Posts: 83
Joined: 01-Oct-2004
# Posted on: 02-Apr-2007 02:00:24   

Any recommendations on the preferred way to handle this scenario:

I have a class Folder that is a collection of objects that derive from a "Document" base. In the old architecture, the FolderItem table had columns to store both a class ID and an identity for the Document that comprised that item. So when the Folder was instantiated, the collection would read each FolderItem and then, based on the class ID, go get the right object, which could be one of several different classes, each stored in a different table. Thus in the database the FolderItem's "DocumentID" column isn't a foreign key to a single table.

What's the best practice for implementing this in LLBLGen? Reproduce the same logic in the generated classes, or add a column to the FolderItem table for each kind of document it could store? For example, instead of DocumentClassID and DocumentID columns, FolderItem would have DocumentKind1ID, DocumentKind2ID, DocumentKind3ID, etc., with only one of them populated, based on what kind of document was being held.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 02-Apr-2007 09:35:51   

If you have different kinds of Documents, then maybe you need to consider Inheritance. refer to LLBLGen Pro manual: "Concepts -> Entity inheritance and relational models"

So you FolderItem would reference the MainDocument table (with FK-PK relation), this table should have common fields of different Documents Types. Then each Document Type should have 1:1 relation with MainDocument.

ww
User
Posts: 83
Joined: 01-Oct-2004
# Posted on: 02-Apr-2007 22:43:24   

Thanks--I missed that in the new version.