cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Menard <nirvd...@gmail.com>
Subject Re: Mapping fake FKs as relationships?
Date Mon, 11 Jan 2010 01:08:26 GMT
This actually something I've been meaning to add in to the DB importer.  I
have a few Rails apps I'd like to try to get going with Cayenne.

ActiveRecord kills me in that it doesn't create FKs at all.  The idea is
that AR maintains the relationships at all times and it may actually use
several queries to do what could otherwise be done in one.  So, in AR, the
most common relationship is just a column of type "other_table_name_id" and
then AR just knows to join using that column.  It is customizable, but in
practice it doesn't happen that often.

More complicated would be AR's notion of polymorphic relationships, which I
guess were added as a way to avoid join tables.

Suffice it to say, I've had many arguments with people over the design of
AR.  I usually point to Cayenne as an example of an ORM that can work with
FKs just fine.  Of course, many in the Ruby community are not familiar with
Cayenne, so it tends not to be the best example.

-- 
Kevin


On Sun, Jan 10, 2010 at 5:21 PM, Aristedes Maniatis <ari@maniatis.org>wrote:

> Having actually done this the first way Andrus mentions, my advice is to do
> it the second way (as an inheritance) if you can. The first way is pretty
> easy, but you don't end up with actual SQL JOIN statements when (say) you
> try to find all records Tagged with a certain tag. You end up with very long
> SELECT IN.... across the join. Which works fine until you try to join 10,000
> records.
>
> George, could you point us to the documentation for how ActiveRecord
> implements this? I'd be interested in their approach.
>
> Ari
>
>
>
> On 11/01/10 1:35 AM, Andrus Adamchik wrote:
>
>> Not directly, but you can emulate that with entity qualifiers by
>> filtering the generic entity on the value of the column that is not
>> participating in a join. You can even map that as an inheritance
>> hierarchy.
>>
>> Andrus
>>
>>
>> On Jan 10, 2010, at 4:05 PM, 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.
>>>
>>> Thanks in advance,
>>>
>>> George.
>>>
>>
> --
> -------------------------->
> Aristedes Maniatis
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message