many-to-many

Domain model for an optional many-many relationship

Let's say I'm modeling phone numbers. I have one entity for PhoneNumber, and one for Person. There's a link table that expresses the link (if any) between the PhoneNumber and Person. The link table also has a field for DisplayOrder. When accessing my domain model, I have several Use Cases for viewing a Person. I can look at them with...

FluentNhibernate many-to-many mapping - resolving record is not inserted

Hi, I have a many-to-many mapping defined (only relevant fields included) with FluentNHibernate (v1.0.0.637): // MODEL: public class User : IPersistentObject { public User() { Permissions = new HashedSet<Permission>(); } public virtual int Id { get; protected set; } public virtual ISet<Permission> Permissions { ...

How to handle Many-To-Many In Grails without belongsTo?

I need to create a many-to-many relationship in Grails. I have a "Question" domain and a "Tag" domain. A Question can have 0 or more tags. A Tag can have 0 or more Questions. If I put a "hasMany" on each sides, it gives me an error saying I need a "belongTo" somewhere. However, adding a belongsTo means that the owner must exist... ...

Class model for a many-to-many relationship, where relationship has attributes

Hi, What would the basic C# code look like to model a many-to-many relationship, where the relationship itself has attributes? And also in this case the many-to-many was referential. So a possible database model for this might look like the following (just to give an example of what I'm talking about) Nodes ID Name Description Rel...

Hibernate: delete many-to-many association

I have two tables with the many-to-many association. — DB fragment: loads Id Name sessions Id Date sessionsloads LoadId SessionId — Hibernate mapping fragments: /* loads.hbm.xml */ <set name="sessions" table="sessionsloads" inverse="true"> <key column="LoadId" /> <many-to-many column="SessionId" class="Session" /> </set> ...

find relationships in a many-to-many structure with sql

Hi, my question is near a parent-child problem, and may need some recursive query, but i didn't find any answers by browsing forums. here is my problem: I've got 3 tables: T1 (people) T2 (places) T3 (relationship betwenn A and B) ------- ------ -------- id1 (pk) id2 (pk) id3 (pk) name city ...

ManyToManyField error when having recursive structure. How to solve it?

Hello, I have the following table in the model with a recursive structure (a page can have children pages) class DynamicPage(models.Model): name = models.CharField("Titre",max_length=200) parent = models.ForeignKey('self',null=True,blank=True) I want to create another table with ManyToMany relation with this one. class...

MS Access 07 - Q re lookup column vs many-to-many; Q re checkboxes in many-to-many forms

Hello, I'm creating a database with Access. This is just a test database, similar to my requirements, so I can get my skills up before creating one for work. I've created a database for a fictional school as this is a good playground and rich data (many students have many subjects have many teachers, etc). Question 1 What is the differ...

MySQL Many to Many with Unique keys and Update/Select if Exists otherwise Insert

In my goal to have a Many-to-Many relationship in my MySQL database I have arrived at another bridge to build. Current Tables: Users (id, name) Tags (id, name) User_Tags (user_id, tag_id) Here is the goal: I would like to have the ability to take a tag i.e: #fb and insert it into my Tags database which has a unique constraint on name a...

SQL Server many-to-many design recommendation

I have a SQL Server database with two table : Users and Achievements. My users can have multiple achievements so it a many-to-many relation. At school we learned to create an associative table for that sort of relation. That mean creating a table with a UserID and an AchivementID. But if I have 500 users and 50 achievements that could ...

Foreign keys and NULL in mySQL

Hi everyone, Can I have a column in my values table (value) referenced as a foreign key to knownValues table, and let it be NULL whenever needed, like in the example: Table: values product type value freevalue 0 1 NULL 100 1 2 NULL 25 3 3 1 NULL Tab...

JPA @ManyToMany on only one side?

I am trying to refresh the @ManyToMany relation but it gets cleared instead... My Project class looks like this: @Entity public class Project { ... @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name = "PROJECT_USER", joinColumns = @JoinColumn(name = "PROJECT_ID", referencedColumnName = "ID")...

Many-To-Many Query with Linq-To-NHibernate

Ok guys (and gals), this one has been driving me nuts all night and I'm turning to your collective wisdom for help. I'm using Fluent Nhibernate and Linq-To-NHibernate as my data access story and I have the following simplified DB structure: CREATE TABLE [dbo].[Classes]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](100) NOT...

Django represent a many-to-many relationship as a CharField

I have a many-to-many field on one of my models and a ModelForm to represent it. I have it in a template but it shows up as a multiple select field. I need it to show up as a CharField so the user can put in comma-delimited values. Is there any way to do this? ...

Core Data Many-to-Many Relationship NSPredicate

Hi all, I have a data model with a many-to-many relationship like EntityA <-->> EntityB <<--> EntityC. I used to query EntityA with different search criteria and I use NSCompoundPredicate with an array of NSPredicates. On one of the predicate I wanted to query EntityA using EntityC. I tried to use the following SUBQUERY but it did not w...

How to sort objects in a many-to-many relationship in ruby on rails?

I've been trying to deal with this problem for a couple of hours now and haven't been able to come up with a clean solution. It seems I'm not too good with rails... Anyway, I have the following: In code: class Article < ActiveRecord::Base has_many :line_aspects has_many :aspects, :through => :line_aspects #plus a 'name' field ...

Entity Framework - Many to Many Subquery

I asked a question about this previously but my database structure has changed, and while it made other things simpler, now this part is more complicated. Here is the previous question. At the time, my EF Context had a UsersProjects object because there were other properties. Now that I've simplified that table, it is just the keys, s...

How to get the related_name of a many-to-many-field?

I'm trying to get the related_name of a many-to-many-field. The m2m-field is located betweeen the models "Group" and "Lection" and is defined in the group-model as following: lections = models.ManyToManyField(Lection, blank=True) The field looks like this: <django.db.models.fields.related.ManyToManyField object at 0x012AD690> T...

Query a Hibernate many-to-many association

In Hibernate HQL, how would you query through a many-to-many association. If I have a Company with multiple ProductLines and other companies can offer these same product lines, I have a Company entity, a ProductLine entity and an association table CompanyProductLine. In SQL, I can get what I need like this: select * from company c wh...

Django Admin: Many-to-Many listbox doesn't show up with a through parameter

Hi All, I have the following models: class Message(models.Model): date = models.DateTimeField() user = models.ForeignKey(User) thread = models.ForeignKey('self', blank=True, null=True) ... class Forum(models.Model): name = models.CharField(max_length=24) messages = models.ManyToManyField(Message, through="M...