cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aristedes Maniatis <...@maniatis.org>
Subject Re: Mapping fake FKs as relationships?
Date Thu, 21 Jan 2010 09:18:01 GMT
On 11/01/10 1:05 AM, George Stan wrote:
> Hi,
>
> Is it possible to map fake foreign keys with CM?
>
> In many DBs for webapps there seem to be quite a few tables (for entities like Tags,
Comments, Attachments, Events) to have relationships to many other tables, and instead of
a FK, a combination of two fields is used (target_table_name and target_row_id).
>
> I know that other ORMs (like ActiveRecord from RoR) have this feature, but I'm not sure
about Cayenne.


Hi George,

There is another option which I should have pointed out. Say you have an Attachments table.
And an AttachmentsRelation table which is the many many join. Then make AttachmentsRelation
a "single table inheritance" entity with children:

AttachmentsRelation_Contact
AttachmentsRelation_Room
AttachmentsRelation_Building
AttachmentsRelation_Painting

Then each of these children is mapped with a join in Cayenne modeler to the appropriate Contact,
Room, etc entities. There will be a qualifier in the single table inheritance setup which
will be something like "contact", "room", etc as needed.

That really should do everything you wanted.


Cheers
Ari



-- 
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Mime
View raw message