many-to-many

admin template for manytomany

I have a manytomany relationship between publication and pathology. Each publication can have many pathologies. When a publication appears in the admin template, I need to be able to see the many pathologies associated with that publication. Here is the model statement: class Pathology(models.Model): pathology = models.CharField(...

How to properly index a linking table for many-to-many connection in MySQL?

Lets say I have a simple many-to-many table between tables "table1" and "table2" that consists from two int fields: "table1-id" and "table2-id". How should I index this linking table? I used to just make a composite primary index (table1-id,table2-id), but I read that this index might not work if you change order of the fields in the qu...

Update Junction table in many-to-many relationship

This is a follow up question to this one: http://stackoverflow.com/questions/416565/query-examples-in-a-many-to-many-relationship regarding updating the junction table. To do this, I would have to use both key values in the junction table, in the WHERE clause. Users UserAddresses Addresses ======= ============= =====...

Should I store as friends as "strings" or "integers" in php and mysql?

Hi, I am in dilemma, do not know which one is better. (I am using php and mysql btw) Lets say I am developing a social community website. A user can add as many friends as he wants. In my database, I have a users table which store user's details include user's friends. Should I store the user's friends in: Strings => john;bryan;sam;pau...

Subsonic many-to-many

For Subsonic users, is there a source of information about how to deal with many-to-many relations in Subsonic? I keep getting "//no ManyToMany tables defined (0)" in my generated code, although I have defined the right relations in database. any help? ...

Entity Framework: Conditional foreign key

Hi all, I have the following schema in the database: BillingReferences (ReferencingType tinyint, ReferencingId tinyint, ReferencedType tinyint, ReferencedId tinyint, IsActive bit) - where all fields (except IsActive) are part of a Unique Index. BillingType (BillingTypeId tinyint, Name varchar(50)) ReferencingType and ReferencedType i...

What's the optimal solution for tag/keyword matching?

I'm looking for the optimal solution for keyword matching between different records in the database. It's a classic problem, I've found similar questions, but nothing concretely. I've done it with full text searches, joins and subqueries, temp tables, ... so i'd really like to see how you guys are solving such a common problem. So, let...

Duplicate PK in MySQL

Hi - I was told a while ago on this site that the only way to go with a many-to-many (in my case a facebook-ish "friend-ing" system) is to do something like this: uid(PK) friend_id 4 23 4 20 4 54 32 20 32 89 Wont this leave me with lots of identical primary keys (which i believe isn't possible?) And if I ...

Fluent NHibernate objectified relationship mapping

Hi there! Looking for an answer on how to configure NHibernate to support my scenario, an many-to-many map with an objectified relation. I have a colection of Person:s with relations to other Person:s. Each of the relations have an attribute specifying what type of relation they have. In an RDB this is done by using a many-to-many tabl...

How do you name your many-to-many relationship tables?

I've seen a few different naming schemes throughout multiple languages when it comes to many-to-many relationships, so I was wondering: what naming scheme do you use for naming these relationships? Please include the platform for which you are developing. Use Posts and Tags as examples for the tables that would be related. Examples: ...

A database schema for Tags (eg. each Post has some optional tags).

Hi folks, I have a site like SO, Wordpress, etc, where you make a post and u can have (optional) tags against it. What is a common database schema to handle this? I'm assuming it's a many<->many structure, with three tables. Anyone have any ideas? ...

Saving many-to-many relationship objects in entity framework

I'm trying to save an entity that forms part of a many-to-many relationship in the entity framework and am getting the error: Unable to update the EntitySet 'zRM_OP_defaultloccvgsMapping' because it has a DefiningQuery and no element exists in the element to support the current operation. My google-fu is weak on this one, but I unders...

Why doesn't my remove() actually remove reference from DB using JPA @Many-to-Many

Hi gang, I have a pretty simple JPA @ManyToMany relationship set up in my application. A Product is a part of one or more OrderSystems. Each OrderSystem can have many Products. It's a typical many-to-many relationship. The problem I'm fighting with is this: If I use orderSystems.remove() to remove a reference from a Product to an Or...

Inserting object with ManyToMany in Django

I have a blog-like application with stories and categories: class Category(models.Model): ... class Story(models.Model): categories = models.ManyToManyField(Category) ... Now I know that when you save a new instance of a model with a many-to-many field, problems come up because the object is not yet in the database. This ...

Child collection not filtering even though linq to sql join exists

I have a LINQ query: var result = from mt in MessageTypes join mtfmt in MessageTypeField_MessageTypes on new { MessageTypeID = mt.ID, MessageTypeFieldID = messageTypeFieldId } equals new { MessageTypeID = mtfmt.MessageTypeID, MessageTypeFieldID = mtfmt.MessageTypeFieldID } where (mt.StatusID == (int)status) sele...

Another Many-Many Scenario

My database model has 2 particular tables in it that require a many-to-many relationship. The tables are Systems and Users. One user can be a member of more than one system and one system has more than one user in it. system_id is the PK in the system table and user_id is the PK in the user table. I have them linked with system_id as a...

How to delete many-to-many relationship in Entity Framework without loading all of the data

Does anyone know how to delete many-to-many relationship in ADO.NET Entity Framework without having to load all of the data? In my case I have an entity Topic that has a property Subscriptions and I need to remove a single subscription. The code myTopic.Subscriptions.Remove(...) works but I need to load all subscriptions first (e.g. myTo...

Silverlight/WPF Many to Many List of Checkboxes Binding

I have an entities model with a many to many relationship. For simiplicity, lets assume its a car entity and a feature(cd player, moonroof, etc.) entity. I have a Silverlight/WPF form in which you edit the car entity. I would like to have the list of possible features (everything in the features table) be a list of checkboxes. That par...

Moving objects from one many-to-many association to another in django?

Hey all, Got a question. Say I have two models in a many-to-many relationship (Article, Publication). Article A is in Publication One, Two, and Three. I want to remove it from those publications and put it into Publication X. The django documentation covers deleting objects and adding objects, but I don't want to delete nor add objects,...

Hibernate - @ManyToMany with additional fields in mapping entity

Hi there. My simplified Entity Scenario is as follows: A PERSON is associated to a COMPANY in a specific ROLE (yawn). My first thought was to configure a ManyToMany relationship between PERSON and COMPANY. However and apparently, I can not include the type of ROLE in the ROLE table that way (as another field the two foreign keys). I ...