Say I've got a User table, and I want to have a Likes relationship
between users: any user can like another user, but the affection isn't
necessarily mutual.
So I have a LikesPivot table with two columns, User1 and User2 (both
of which point to IDs in the User table), representing a relationship
where User1 likes User2. And I have a property in the User class
listing all the other users that this one likes:
public virtual IList<User> Likes { get; set; }
And for this I set up a relationship in my UserMappingOverride.cs
class:
mapping.HasManyToMany(x => x.Likes)
.WithTableName("LikesPivot")
.WithParentKeyColumn("User1")
.WithChildKeyColumn("User2");
All of this works fine.
Here's the challenge: I also want a property in the User class listing
all the other users who like this one:
public virtual IList<User> IsLikedBy { get; set; }
This would use the same LikesPivot table, but in reverse: User2 is
liked by User1.
How do I set up a relationship to use the same table? I tried doing:
mapping.HasManyToMany(x => x.IsLikedBy)
.WithTableName("LikesPivot")
.WithParentKeyColumn("User2")
.WithChildKeyColumn("User1");
but all this does is create double rows when I set up a Likes
relationship.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" 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/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---