many-to-many

Correct way to remove M:M in PLINQO?

Suppose you have this table structure: Patient -> PatientTag -> Tag A typical N:M relationship between patients and tags, PatientTag being the intermediate entity with both FKs. (PatientId and TagId). I want to remove a specific tag, I have its ID. I’m doing this but I’d like to know if there’s a better way, since these are the 1st m...

SQL query to find users that don't have any subscription to a specified list (many-to-many).

Having two tables, "users" and "lists", and a many-to-many "subscriptions" table relating users to lists (thus having foreign keys user_id and list_id), what would be a single SQL query to find all the users that don't have any subscription with a specific list_id (naturally including the users that have no subscriptions at all)? ...

How can i use ManyToManyRawIdWidget outside admin?

Im new to django and I would like to know how could i use the ManytoManyRawId widget outside admin. I've tried different ways but still don't work. Help would be really much appreciated. ...

Many-to-many on the same table with additional columns

I have a class User. A user can be a friend with many other users. The relationship is mutual. If A is a friend of B then B is a friend of A. Also I want every relation to store additional data - for example the date when two users became friends. So this is a many-to-many relationship on the same table with additional columns. I know th...

Django m2m and saving objects

I have a couple of simple objects that have a many-to-many relationship. Django has joined them using obj1_obj2 table and it looks like this in mysql; id | person_id | nationality_id ----------------------------------- 1 | 1 | 1 2 | 1 | 2 Now when I save obj1 (which shows obj2 in as Multi-...

Get all table names in a Django app

How to get all table names in a Django app? I use the following code but it doesn't get the tables created by ManyToManyField from django.db.models import get_app, get_models app = get_app(app_name) for model in get_models(app): print model._meta.db_table ...

nhibernate many-to-many with relationship specific properties

Is there a way to map a many-to-many relationship with properties on each item in the list specific to the relationship? The actual case I'm trying to solve is this: A business can be related to many contacts, and a contact can be related to many businesses. What I want to do is provide a status for the relationship, like active or d...

T-SQL - How to write query to get records that match ALL records in a many to many join

(I don't think I have titled this question correctly - but I don't know how to describe it) Here is what I am trying to do: Let's say I have a Person table that has a PersonID field. And let's say that a Person can belong to many Groups. So there is a Group table with a GroupID field and a GroupMembership table that is a many-to-many...

Chained has_many through: users -> roles -> lists. Finding lists that a user is assigned to (via roles).

It must be a very common problem. I have a chained many-to-many relationship like this: User n<==>n Role n<==>n List ActiveRecord models: class User # linking to roles has_many :role_assignments has_many :roles, :through => :role_assignments end class Role # linking back to users has_many :role_assignments has_many :user...

Filtering objects with many to many relationships

I have a two tables one for documents one for mapping to categories. Documents id | document_name 1 | somename.doc 2 | anothername.doc Documents_to_categories cat_id | doc_id 10 | 1 10 | 2 11 | 3 12 | 1 Some documents can map to multiple categories. What I want is to be able to select document...

Adding a new column to a may to many relationship in NHibernate

Hi. A have this mapping: mapping.HasManyToMany(x => x.SubVersions).ParentKeyColumn("ParentId").ChildKeyColumn("SubVersionId").Table( "VersionLinks"); This will create a table VersionLinks with 2 columns(ParentId,SubVersionId). Is it possible to have in this table another column (ex. CreateDate) that will be filled autom...

Many-to-many without intermediate table - is it possible?

I have two entities that usually have one-to-many relationship, but in rare cases should have an opportunity to be many-to-many. I don't want to join the tables with the intermediate table for every query - and i guess there are preferable patterns for "rare many-to-many", - (perhaps with additional table for m-t-m, with duplicate recor...

How to properly remove a specific ManyToMany relationship?

I have a ManyToMany relationship with one of my Models. On deleting a child, I want to remove the relationship but leave the record as it might be being used by other objects. On calling the delete view, I get an AttributeError error: Exception Value: 'QuerySet' object has no attribute 'clear' This is my models.py: class Feed(...

Subsonic 3 simple repository many to many relations

I saw in an earlier post here on stackoverflow a example on many to many relations. To keep it simple, lets have a look at these classes : public class Role(){ public int Id { get; set; } public string Rolename { get; set; } public string Description { get; set; } } public class User(){ public int Id { get; set; } p...

[SQL] Artist-tag database: Getting tags

I'm creating a database that's going to contain various artists which can be tagged with several tags. It's a standard many-to-may relation and my database looks like this: artist: ID name tag: ID name tagID: tagID artistID Say I've got two tagIDs, X and Y. What I want to do is to find all the tags that have an artist in...

NHibernate many-to-many assocations making both ends as a parent by using a relationship entity in the Domain Model

Entities: Team <-> TeamEmployee <-> Employee Requirements: A Team and an Employee can exist without its counterpart. In the Team-TeamEmployee relation the Team is responsible (parent) [using later a TeamRepository]. In the Employee-TeamEmployee relation the Employee is responsible (parent) [using later an EmployeeRepository]. Duplica...

How do I map a conditional many-to-many relationship with JDO?

I have two objects, A and B. They both share the same types of fields, 1 and 2. Their relationship can be expressed in SQL as follows: A's Bs: SELECT * FROM B WHERE B.1 = A.1 AND (B.2 = A.2 OR B.2 IS NULL) B's As: SELECT * FROM A WHERE B.1 = A.1 AND (A.2 = B.2 OR B.2 IS NULL) That's the tricky part - that B.2 can be null and still b...

Django Forms save_m2m

Hi I have a model which has 2 many to many fields in it. one is a standard m2m field which does not use any through tables whereas the other is a bit more complecated and has a through table. I am using the Django forms.modelform to display and save the forms. The code I have to save the form is if form.is_valid(): f = form....

How do I to check if a entity is in a many-to-many relationship.

I have a 'user' table, a 'phone number' table and a 'user to phone number map' table. The phone number table stores only unique phone numbers. This way I can take a look at a phone number and see who is using it easily. It is also easy to check if a phone number exists when the user is edited. The question is how I should be checkin...

is dinstinct an expensive query in django?

Hi, I have three models: Product, Category and Place. Product has ManyToMany relation with Category and Place. I need to get a list of categories with at least on product matching a specific place. For example I might need to get all the categories that has at least one product from Boston. I have 100 categories, 500 places and 100,000...