[fpc-pascal] tiOPF: automapping for m-n relationships

Graeme Geldenhuys graemeg.lists at gmail.com
Mon Apr 2 13:56:49 CEST 2012


On 2 April 2012 00:33, leledumbo <leledumbo_cool@****> wrote:
>
> they're mapped with:
>
> with gTIOPFManager.ClassDBMappingMgr do begin
>  RegisterMapping(TUser,'users','OID','id',[pktDB]);
>  RegisterMapping(TUser,'users','Name','name');
>  RegisterMapping(TUser,'users','Password','password');
>  RegisterMapping(TUser,'users_roles','Roles','???'); // <-- what should I
> fill it with?
>  RegisterCollection(TUsers,TUser);
> end;


The "auto-mapping" feature of tiOPF is very limited, so I personally
never use it. There are other options though:

1) Use "hard-coded" visitors for this area of your application (yes
you can use auto-mapping and hard-coded visitors in the same
application). Many developers start off using auto-mapping, and when
they hit the limitations of auto-mapping, switch over to hard-coded
visitors for those areas.

2) Use something like the Relationship Manager (RM) design pattern for
that area of your application. There is an implementation of RM in
tiOPF, or create your own. Here are two links describing the
Relationship Manager design pattern:

      http://opensoft.homeip.net:8080/articles/
   or
      http://www.andypatterns.com/index.php/design_patterns/relationship_manager



For option (2), this is normally the steps to follow. The basic approach is to:

a) Read in the first object hierarchy (the from objects)
b) Read in the second object hierarchy (the to objects)
c) Read in the mappings, which are stored in a table with three columns: OID,
OID_From and OID_To. For each row in this table, I search for the
matching object
in the From list and To list by OID. I then add a mapping object to the list
of mappings that is described in the 'Relationship Manager' patter.

There are some methods on TtiObject and TtiObjectList to make it easy to find
an owned object by OID.


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://fpgui.sourceforge.net



More information about the fpc-pascal mailing list