many-to-many

PHP & Mysql updating many to many relationship with checkbox form

I have a many to many table structure and updating checkbox forms. The goal is to relate the users table to the projects table with the users_project table. This way there can be many users per project and many projects per user. The form would on each user edit page would look something like this <form action="#" method="post"> <...

Many-to-many relationship: use associative table or delimited values in a column?

Update 2009.04.24 The main point of my question is not developer confusion and what to do about it. The point is to understand when delimited values are the right solution. I've seen delimited data used in commercial product databases (Ektron lol). SQL Server even has an XML datatype, so that could be used for the same purpose as del...

Rails has_and_belongs_to_many join across 3 tables

I have a three models: listing, category, and site. There is a many to many relationship between listing and site and there is a many to many relationship between listing and category. A listing thus belongs to one or more sites and one or more categories (a listing can appear on multiple sites and multiple categories). Given a site i...

How to clean up a doubly-linked many-to-many relationship?

First of all, I'm not sure if the title accurately describes what I'm referring to, so feel free to leave a comment on what to call this, or just rename if yourself if you have the rep. Let's say for example I have 2 classes, Book and Library. A Library contains a property that is a list of all the Books it owns. A Book has a property...

Entity Framework - Linq To Entities - Many-To-Many Query Problems

Hi, I am having problems querying many-to-many relationships in Linq To Entities. I am basically trying to replicate this query using Linq: Select * FROM Customer LEFT JOIN CustomerInterest ON Customer.CustomerID = CustomerInterest.CustomerID LEFT JOIN Interest ON CustomerInterest.InterestID = Interest.InterestID WHERE Interest.Intere...

Which algoritm to use with many-to-many relation in NHibernate

I have a many-to-many relationship between photos and tags: A photo can have multiple tags and several photos can share the same tags. I have a loop that scans the photos in a directory and then adds them to NHibernate. Some tags are added to the photos during that process, e.g. a 2009-tag when the photo is taken in 2009. The Tag cla...

How to use generic foreign key in custom m2m relationship model

In first version we can use custom table for ManyToManyField with parameter through=MyModel. MyModel should include foreign keys. But I want to use generic foreign key: content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') content...

how to query many-to-many ?

Hello, I found following table structures while I was watching ruby on rails tutorial. table actors id int 11 primary key auto_increment name varchar 30 table movies id int 11 primary key auto_increment name varchar 30 table actors_movies actor_id int 11 movie_id int 11 how to I make a query to select movies that an a...

'Answer' instance needs to have a primary key value before a many-to-many relationship can be used.

I have a model called Answer which has a ForeignKey relationship to another model called Question. This means there can be several answers to question, naturally. class Question(models.Model): kind = models.CharField(max_length=1, choices=_SURVEY_QUESTION_KINDS) text = models.CharField(max_length=256) class Answer(models.Model...

Can a junction table (join table) also be used for a one-to-many relationship?

According to the definition, a Junction Table (bridge table/link table) is used for many-to-many relationships, when used like this: CREATE TABLE Users ( UserLogin varchar(50) PRIMARY KEY, UserPassword varchar(50) NOT NULL, UserName varchar(50) NOT NULL ) CREATE TABLE Permissions ( PermissionKey varchar(50) PRIMARY KEY, PermissionDesc...

How do you resolve a many-to-many collection entity in a RDBMS?

I'm trying to model artists and songs and I have a problem where I have a Song_Performance can be performed by many artists (say a duet) so I have an Artist_Group to represent who the songs is performed by. Well, I now have a many-to-many relationship between Artist and Artist_Group, where an Artist_Group is uniquely identified by the...

Query objects from a Many to Many look-up table

I have Master1 and Sub1 and a another called Master1Sub1_Map which contains foreign keys to the Master1 and Sub1 objects. There are multiple ID's from Sub1 that are associated with a single id in Master1. If I want to see all the Sub1 records that are assigned to a specific Master1.ID how do I go about doing that with the SubSonic obje...

Ordering By Mapping Table Value in Hibernate

I have a @ManyToMany mapping where the table self-references through a mapping table, and we want to order on an order id in the actual mapping table, but are finding it difficult to configure this. We could perform it in hibernate xml, so it is natural to assume the support is there in JPA annotations. Does anybody know how we can orde...

How to prevent self (recursive) selection for FK / MTM fields in the Django Admin

Given a model with ForeignKeyField (FKF) or ManyToManyField (MTMF) fields with a foreignkey to 'self' how can I prevent self (recursive) selection within the Django Admin (admin). In short, it should be possible to prevent self (recursive) selection of a model instance in the admin. This applies when editing existing instances of a mod...

Find roots of many-to-many category tree in Django

I have a Django model like: class Category(models.Model): status=models.CharField(max_length=16) machineName=models.CharField(max_length=50) readableName=models.CharField(max_length=100) description=models.CharField(max_length=1024) parents=models.ManyToManyField('self') Where each category may exist in many parent...

SQL Many-to-Many Query Problem

I have three tables: videos, videos_categories, and categories. The tables look like this: videos: video_id, title, etc... videos_categories: video_id, category_id categories: category_id, name, etc... In my app, I allow a user to multiselect categories. When they do so, I need to return all videos that are in every selected categor...

many-to-many not persisting in gorm/grails app

I have roughly the following in my grails 1.1 app class AppCategory { static belongsTo = App static hasMany = [ apps: App ] String name } class App { static hasMany = [ categories: AppCategory] String name } App app = new App() AppCategory appCat = AppCategory.findByName('blah') app.addToCategories(appCat) app.sa...

Can't get many-to-many to work with Hibernate 3.3.1GA

I have a simple many-to-many mapping: @Entity @Table(name="ITEM") public static class Item { @Id @GeneratedValue long id; @Column String name; @ManyToMany(cascade={ CascadeType.ALL }) Set<Category> categories = new HashSet<Category> (); } @Entity @Table(name="CATEGORY") public static class Category { @Id...

ManyToMany in Hibernate without composite keys

I am dealing with legacy database. And I am writing unit test using pojos & hibernate & HSQLDB. And I am getting the following error: 17:09:03,946 ERROR SchemaExport:349 - Attempt to define a second primary key in statement Let's say I have Post and Tag entities (and of course their tables posts and tags). And there is another table to...

How do I access the child classes of an object in django without knowing the name of the child class?

In Django, when you have a parent class and multiple child classes that inherit from it you would normally access a child through parentclass.childclass1_set or parentclass.childclass2_set, but what if I don't know the name of the specific child class I want? Is there a way to get the related objects in the parent->child direction witho...