How to organise a many to many relationship in MongoDB

What I’ve seen done, and what I currently use are embedded arrays with node id’s in each document. So document user1 has property groups: [id1,id2] And document group1 has property users: [user1]. Document group2 also has property users: [user1]. This way you get a Group object and easily select all related users, and the same … Read more

Entity Framework 4.1+ many-to-many relationships change tracking

Here is how to find all the changed many-to-many relationships. I’ve implemented the code as extension methods: public static class IaExtensions { public static IEnumerable<Tuple<object, object>> GetAddedRelationships( this DbContext context) { return GetRelationships(context, EntityState.Added, (e, i) => e.CurrentValues[i]); } public static IEnumerable<Tuple<object, object>> GetDeletedRelationships( this DbContext context) { return GetRelationships(context, EntityState.Deleted, (e, i) => e.OriginalValues[i]); … Read more

Self-referencing many-to-many recursive relationship code first Entity Framework

By convention, Code First will take uni-directional associations as one to many. Therefore you need to use fluent API to let Code First know that you want to have a many to many self referencing association: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Member>().HasMany(m => m.Friends).WithMany().Map(m => { m.MapLeftKey(“MemberId”); m.MapRightKey(“FriendId”); m.ToTable(“MembersFriends”); } ); }

Django – Cascade deletion in ManyToManyRelation

I think you are misunderstanding the nature of a ManyToMany relationship. You talk about “the corresponding BlogEntry” being deleted. But the whole point of a ManyToMany is that each BlogEntryRevision has multiple BlogEntries related to it. (And, of course, each BlogEntry has multiple BlogEntryRevisions, but you know that already.) From the names you have used, … Read more