Questions tagged [many-to-many]

A type of relationship between entities of types A and B which associates a list of entities of type B to an entity of type A and vice versa. Types A and B may be the same type.

A type of relationship between entities of types A and B which associates a list of entities of type B to an entity of type A and vice versa. Types A and B may be the same type.

8687 questions
35
votes
1 answer

How to define Many-to-Many relationship through Fluent API Entity Framework?

Below is my model: public class TMUrl { //many other properties //only property with type Keyword public List Keywords{get;set;} } public class Keyword { //many other properties //only property with type TMUrl …
Manish Mishra
  • 12,163
  • 5
  • 35
  • 59
35
votes
1 answer

Saving Many to Many relationship data on MVC Create view

I have some issues with a Many-to-many relationship saving the results of a create view. I want to do a create page for a new user profile that has a checklist that lets them choose courses (many to many relationship). My view takes the records from…
PnP
  • 625
  • 1
  • 10
  • 18
34
votes
2 answers

DynamoDB M-M Adjacency List Design Pattern

Referring to amazon. I was wondering if anyone could help me. The first image is of the table, and the second is the GSI. Here is the table: On the table, I don't understand how one is to create the sort-key? Is this one attribute that stores both…
Bluetoba
  • 885
  • 1
  • 9
  • 16
34
votes
1 answer

SqlAlchemy and Flask, how to query many-to-many relationship

I need help creating SqlAlchemy query. I'm doing a Flask project where I'm using SqlAlchemy. I have created 3 tables: Restaurant, Dish and restaurant_dish in my models.py file. restaurant_dish = db.Table('restaurant_dish', db.Column('dish_id',…
cancerballs
  • 399
  • 1
  • 3
  • 11
33
votes
2 answers

Compound/Composite primary/unique key with Django

How can you create models (and thus tables) with a compound (composite) primary/unique key using Django?
Viet
  • 17,944
  • 33
  • 103
  • 135
32
votes
2 answers

Removing many to many entity Framework

There is a many to many relationship between Artist and ArtistType. I can easily add artist ArtistType like below foreach (var artistType in this._db.ArtistTypes .Where(artistType => vm.SelectedIds.Contains(artistType.ArtistTypeID))) { …
akd
  • 6,538
  • 16
  • 70
  • 112
32
votes
12 answers

How to model a Many to many-relationship in code?

Suppose I have 2 tables in a database. eg: Dog & Boss This is a many to many relationship, cause a boss can have more than 1 dog, and a dog can have more than 1 owner. I am the owner of Bobby, but so is my wife. But many to many is not allowed, so…
Natrium
  • 30,772
  • 17
  • 59
  • 73
32
votes
4 answers

django 1.4 Many-to-Many bulk add

I was wondering if there is the equivalent of a "add all" or "bulk create" for many to many relationships which reduce the number of queries (I will be doing this for a long list)? The docs on this subject seem to suggest that this is not…
snakesNbronies
  • 3,619
  • 9
  • 44
  • 73
31
votes
2 answers

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

How can I detect changes of ICollection<> properties (many-to-many relationships)? public class Company { ... public virtual ICollection Employees { get; set; } } using (DataContext context = new…
30
votes
1 answer

MySQL - How to insert into table that has many-to-many relationship

I have a table of persons. Each person has a property and many persons may have a certain property. So this is a many-to-many relationship. This is the schema: CREATE TABLE persons ( person_id int(11) NOT NULL AUTO_INCREMENT, firstname…
Christos Baziotis
  • 5,845
  • 16
  • 59
  • 80
30
votes
1 answer

How do 'primaryjoin' and 'secondaryjoin' work for many-to-many relationship in SQLAlchemy?

Having some difficulty understanding some Flask-SQLAlchemy stuff from the Flask Mega Tutorial. Here's the code: followers = db.Table('followers', db.Column('follower_id', db.Integer, db.ForeignKey('user.id')), db.Column('followed_id',…
user1787531
  • 789
  • 4
  • 10
  • 22
30
votes
2 answers

Bulk update for many to many fields

I have two models as Follows: class Book(models.Model): title = models.CharField(max_length=100) year = models.IntegerField(max_lenght=4) author = models.ManyToManyField(null=true, blank=true) class Author(models.CustomUser): #…
Amyth
  • 32,527
  • 26
  • 93
  • 135
29
votes
4 answers

GUI patterns to edit data with many-to-many relationship

I often run into a situation where I need to come up with a GUI to edit data that has a n:m relationship. I'm looking for user friendly GUI ideas. [table1] | /|\ [table2] \|/ | [table3] Usually the GUI resembles something like this: Grid…
Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122
29
votes
3 answers

Hibernate many-to-many cascading delete

I have 3 tables in my database: Students, Courses and Students_Courses Students can have multiple courses and courses can have multiple students. There is a many-to-many relationship between Students and Courses. I have 3 cases for my project and…
Sushant Gupta
  • 1,487
  • 2
  • 16
  • 23
28
votes
4 answers

Insert into Many2many Odoo (former OpenERP)

I'm trying to insert values into a Many2many or One2many relation table field in Odoo (former OpenERP). Do you have any idea how to do this?
m3asmi
  • 1,252
  • 1
  • 16
  • 36