many-to-many

C#: 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 there is a helpertable: DogsPerBoss How to modle this in code? Class Boss can have a col...

How do I search for an array of values in a many to many relation?

Hey I have a problem with my LINQ to Entity model many to mant relation. I am new to both C# and LINQ, so bear with me. I have a model containing pictures and tags, where each picture can have many tags, and each tag can be on many pictures. In the db there is a normal relation table, but in the object model I see it as picture.tags (a...

SQL query with multiple "IN" on same many-to-many table

Hello, I've got m2m relationship like this: #main table CREATE TABLE products_product ( id integer NOT NULL, company_id integer, user_id integer, type_id integer NOT NULL, name character varying(100) NOT NULL, description character varying(200) NOT NULL, tags character varying(255) NOT NULL, image charac...

Django ManyToMany Template rendering and performance issues

Hi all, I've got a django model that contains a manytomany relationship, of the type, class MyModel(models.Model): name = .. refby = models.ManyToManyField(MyModel2) .. class MyModel2(..): name = .. date = .. I need to render it in my template such that I am able to render all the mymodel2 objects that refer to mymodel. Cu...

Rails (ActiveRecord) many to many table

I have two models, Users and Groups. Each group can have many users and each user can be in many groups. I currently have something simple like: User: has_many :groups Group: has_many :users So I have a groups_users table which is just creating rows with group_id and user_id. I want to add another column to this, (which I h...

hibernate manytomany xdoclet

is this the right way of using it? because it does not work. i have the same thing in the RoleDAO. the two tables for users and roles are generated, but the table that links userid to roleid is not. (more info on the syntax bellow http://xdoclet.codehaus.org/HibernateTags#HibernateTags-hibernate.manytomany hibernate xdoclet tags) /** ...

How to model a many to many relationship?

With only a bit of previous experience with databases and no formal education with them, I'm a bit stuck as to how to model this (and retrieve the data I require from it in PHP). This is what I'm trying to model: For each item on my site, it is allowed to have multiple tags such as file, upload, php, recursive etc. However the tags are ...

Correct way to remove a many-to-many relationship via linq to sql?

Let's say we have two tables with a many-to-many relationship: public class Left{ /**/ } public class Right{ /**/ } public class LeftRight{ /**/ } is the following sufficient to unhook these records (ignore the possibility of more than one relationship or no relationship defined)? public void Unhook(Left left, Right right){ var r...

Why does many-to-many data structure require two additional tables?

This question is based on the thread. If we have one-to-many data structure, we need to have a "help-table" to store for instance phonenumbers for one person. Many person cannot have the same phonenumbers. I look forward for an explanation why we then need two "help-tables" between many-to-many relations. An example of this is a questi...

Best way to implement many-to-many lookup table with user-entered data

Say I want users to pick one or more contact methods (email, phone, fax, other, etc). And if they choose other, then they can enter a single contact method of their own. What's the best way to store this in a database? I see three possibilities: Use a set datatype column, plus a single "other_contact" varchar column to store the opt...

Guidelines for join/link/many to many tables

I have my own theories on the best way to do this, but I think its a common topic and I'd be interested in the different methods people use. Here goes Whats the best way to deal with many-to-many join tables, particularly as far as naming them goes, what to do when you need to add extra information to the relationship, and what to do wh...

MySql query over many-to-many relationship

A very simple example of a n:m relationship that puzzles me. Let's assume we have two tables "Plant" and "Attribute" and another table between them holding their relationship with their IDs: Plant--------hasAttribute--------Attribute P1 | A1 P1 | A2 P1 | A3 P2 | A1 ...

CakePHP Many-To-Many Per-Relationship Additional Data

Hello, I am relatively new to CakePHP, and I am writing a CakePHP application which currently has an Author model and a Book model. Author and Book both have a many-to-many relationship. However, I would like to additionally, for every author-book relationship, have a corresponding link to that author's blog where they reflect upon thei...

MySQL query over many-to-many realtion: unions?

In addition to this question http://stackoverflow.com/questions/1202668/problem-with-sql-query which had very neat solution, I was wondering how the next step would look: DOCUMENT_ID | TAG ---------------------------- 1 | tag1 1 | tag2 1 | tag3 2 | tag2 3 | tag1 3 ...

VS2008/SQL Server: Quickly set up many-to-many-tables

Hi I've recently started using Visual Studio 2008 and SQL Server Express. I'm coming from a Emacs/Django background, so I'm not used to this way of working. Is there any quick and easy way to set up a many-to-many-table between two other tables? This would be the equivalent to the table generated by a ManyToManyField in Django. ...

how to make a composite primary key (java persistence annotation)

how to make it so that the table user_roles defines the two columns (userID, roleID) as a composite primary key. should be easy, just can't remember/find. in userdao @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "user_roles") public List<RoleDAO> getRoles() { return roles; } @Id @GeneratedValue(strategy = ...

Does anyone use SubSonic in .Net

in SubSonic 3, if i use SimpleRepository, can i ask it to generate forkey as well include "one to many", "one to one" and "many to many" is there any sample code i can have a look at???? what i see from its demo, is only for one table, not dealing with relationship ..if it cannot deal with relationship...i won`t go into it and use it...

finding the posts related by tags with one specific post in mysql

I have this tables: Posts (post_is, title and text), Tags (tag_id, tag), Post_tag_nn (id, tag_id, post_id). I want for a specific post having for example 4 tags all the posts with those tags, then all the posts with any three of those tags, then all posts with any two of those tags and so on. How can i build a SQL query for this purpose ...

Django ManyToMany relation add() error

Hi all, I've got a model that looks like this, class PL(models.Model): locid = models.AutoField(primary_key=True) mentionedby = models.ManyToManyField(PRT) class PRT(models.Model): tid = .. The resulting many to many table in mysql is formed as, +------------------+------------+------+-----+---------+----------------+ |...

Filter ManyToMany box in Django Admin

I have a object with a many-to-many relation with another object. In the Django Admin this results in a very long list in a multiple select box. I'd like to filter the ManyToMany relation so I only fetch Categories that is available in the City that the Customer have selected. Is this possible? Will I have to create a widget for it? An...