I don't want to start a new topic regarding this but I was able to fix
my problem. By putting a HasAndBelongsToMany Attribute on my three
entities owning the last entity, I was able to force ActiveRecord and
hbm2ddl to use a join table so the schema looks like this
(ParentEntityTable x ParentChildEntityJoinTable x ChildEntityTable).
This solved my issue completely; however, I was reading some use cases
where if you put a Unique attribute on the many-to-many relationship
you force it to become a one-to-many relationship with a join table. I
do not see the unique attribute on the HasAndBelongsToMany attribute
and I cannot think of any other way to get ActiveRecord to create this
schema. Any ideas if this will be implemented or how to do it?

On May 27, 4:22 pm, Markus Zywitza <[email protected]> wrote:
> It might work with an explicit Any-Property in D. You must never
> forget that even unidirectional relations are relations. And on the
> database, one-to-many relations are implemented with FKs on the
> one-side, regardless of whether AR hides that from the model or not.
>
> -Markus
>
> 2009/5/27 Hexedit <[email protected]>:
>
>
>
> > I apologize I worded my first message improperly. D should have no
> > knowledge
> > of the Entities A, B or C. In my object there is no Property for
> > linking back to
> > any one of the other entities. So it is a one sidedHasManywith no
> > related BelongsTo.
> > I suppose an Any tag would work well in this situation but I'm not
> > sure how to configure
> > it or if it even works with aHasManyon the other side of the
> > relation. Assuming that
> > my domains A, B, and C never have conflicting integer primary keys,
> > this shouldn't be
> > an issue correct?
>
> > On May 27, 10:56 am, Markus Zywitza <[email protected]> wrote:
> >> You have A, B and C pointing to D: Ergo, D has an implicit many-to-one
> >> to A, B and C, which is hidden in AR due to the unidirectional
> >> relation. Now you want that D only has one many-to-one connection,
> >> which will direct to A, B or C. This seems impossible: How should AR
> >> know from an integer to which of the classes A, B or C it belongs? If
> >> you use Identity, the same key might be used in A, B and C, leaving AR
> >> clueless of what to load.
>
> >> You need three FK columns in D if A, B and C are not related. If they
> >> belong to the same base class, you can define theHasManythere, but
> >> with unrelated classes your scenario is impossible.
>
> >> -Markus
>
> >> 2009/5/27 Hexedit <[email protected]>:
>
> >> > I have three unique entity classes that each have a collection of a
> >> > fourth entity via theHasManyattribute. The mappings should be one-to-
> >> > many unidirectional relationships from entities A, B, and C to entity
> >> > D. EachHasManyattribute references the same table and the same
> >> > column for the foreign key. Since the referenced column is an integer
> >> > it should not matter that it could be pointing to objects from 3
> >> > tables. The problem is that the generation tool non-deterministically
> >> > picks one of the first three entities and creates a foreign key
> >> > relationship from the reference column in the 4th entity table to the
> >> > entity that owns that relation. Is there any way for me to override
> >> > this behavior and make it so that the Many side of theHasMany
> >> > relationship doesn't foreign key back to the first table?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to