many-to-many

[PHP] query-generated tables with many-to-many data fields, best practice?

You have two hypothetical tables: TABLE 1 [id] [item] [amount] [cost] 1 hat 20 10 2 shoe 7 45 3 belt 2 25 TABLE 2 (many to many) [item] [color] hat blue hat red hat yellow shoe black shoe white etc. etc. and when you run a query, you want to output a list ...

Field contains foreign IDs for different tables

I am developing a php/mysql driven facebook game. I am stuck on an element the table design. When a user completes a task I want to trigger any number of events. I was thinking of something like so: tbl_events *event_id - serogate primary ID *task_id - foreign ID of the task just completed *event_type - what type of event e.g is it a f...

AutoMapper : Map a many-to-many association into a DTO (Is flattening of collection items supported?)

Hi! I have a many to many association between a Team and an Employee. public class Employee : Entity { public virtual string LastName { get; set; } public virtual string FirstName { get; set; } public virtual string EMail { get; set; } public virtual IList<LoanedItem> LoanedItems { get; private set; } public virtual...

Select item from many-to-many table that has all these details... proper solution?

(PHP/MySQL) Let me preface by saying that this works, and that I'm wondering if there's a cleaner way. This seems a bit... brutish? And I'm not known for my efficient coding. :-/ TABLE (many-to-many) scenid mapid AA 01 AA 02 AA 04 BB 01 BB 04 CC 02 CC 03 CC 05 DD 01 DD ...

Subsonic scaffold many-to-many controls are disappearing.

I'm using the SubSonic scaffold control with auto-generating many to many controls. <subsonic:Scaffold ID="scfMain" runat="server" AutoGenerateManyToMany="true"></subsonic:Scaffold> On Page_Load I'm setting the table name scfMain.TableName = "Foo"; The many to many controls are generated by a many to many table, two foreign key...

Hibernate many-to-many collection filtering

I have the following POJO with a Set inside: class Word { private Long id; private String word; private int type = WordListFactory.TYPE_DEFAULT; private Set<Word> refs = new HashSet<Word>(); ... } Here's the mapping XML: <class name="kw.word.Word" table="word"> <id name="id" column="id" unsaved-value="null...

MongoDB Many-to-Many Association

How would you do a many-to-many association with MongoDB? For example; let's say you have a Users table and a Roles table. Users have many roles, and roles have many users. In SQL land you would create a UserRoles table. Users: Id Name Roles: Id Name UserRoles: UserId RoleId How is same sort of relationship ...

My Django manytomany fields are all marked unique, is there an option to remove this?

Given a model like this: class A(models.Model): def __unicode__(self): return "%d"%self.id class B(models.Model): a_set = models.ManyToManyField(A) def __unicode__(self): return "%d"%self.id Then the following series of operations demonstrates my problem: In [1]: a1=A() In [2]: a1.save() In [3]: a1 Out[3...

Entity Framework Self Referencing Hierarchical Many To Many

OK this problem has it all. Conceptually I have a Resource entity which can have many Child Resources and many Parent Resources. The Resource table has two fields, ID and Name with ID being the primary key. To complete the many to many relationship I created a ResourceHierarchy table which has two fields, (Parent_ID, Child_ID) and two ...

Query (M:N) ordered by relationship attribute

Hi folks, I have a simple many-to-many E-R described as below: Model order.rb: class Order < ActiveRecord::Base has_many :cronologies has_many :statuses, :through => :cronologies end Model cronology.rb: class Cronology < ActiveRecord::Base belongs_to :order belongs_to :status validates_uniqueness_of :order_id, :scope => :...

Django many-to-many relationship to self with extra data, how do I select from a certain direction?

I have some hierarchical data where each Set can have many members and can belong to more than one Set(group) Here are the models: class Set(models.Model): ... groups = models.ManyToManyField('self', through='Membership', symmetrical=False) members = models.ManyToManyField('self', through='Membership', symmetrical=False) c...

To have efficient many-to-many relation in Java

How can you make the efficient many-to-many -relation from fileID to Words and from word to fileIDs without database -tools like Postgres in Java? I have the following classes. The relation from fileID to words is cheap, but not the reverse, since I need three for -loops for it. My solution is not apparently efficient. Other options ...

SQL- How do you retrieve records matching all values in a linked table.

I have a many to many relationship within my database. For example I have a USER table, a ROLE Table, and USERINROLE table. I have a search on my website that needs to find users in specified roles. For example I would like to retrieve User records who are in roles "reader" AND "writer" My Query before the where looks like this: SELEC...

entity framework inserting a many-to-many relationship between two existing objects while updating

I'm trying to do this: using(var context = new SampleEntities()) { User user = select a user from database; //Update user's properties user.Username = ... user.Website = ... //Add a role Role role = select a role from database //trying to insert into table UserRoles which has columns (UserID, Role...

django ManyToMany through help

Hay I've got a question about relationships. I want to Users to have Friendships. So a User can be a friend with another User. I'm assuming i'll need to use the ManyToManyField, through a Friendship table. But i cannot get it to work. Any ideas? Here are my models. class User(models.Model): username = models.CharField(max_length=9...

Fluent Nhibernate Many-to-Many mapping with extra column

I want to map sth like this using fluent Nhibernate but I am not sure how to map the inventory table This is the tables I have : Product (Id,Name, ...) Warehouse(Id, Name, ...) Inventory(Product_id, Warehouse_id, StockInHand) I have map the Product and Warehouse like below Public ProductMap() { Id(x => x.Id); ...

Efficient query many-to-many relation in a nested set

I have a many-to-many relation between labels and files (using rails). The labels model is also a nested set (awesome nested set plugin) that allows the lables to be organized in a hierarchy like: Multimedia Video mpeg-4 h264 theora Audio mp3 aac vorbis To access all the files under the Video label I would have to create some ...

Database theory - relationship between two tables

I have a database with two tables - let's call them Foo and Bar. Each foo may be related to any number of bars, and each bar may be related to any number of foos. I want to be able to retrieve, with one query, the foos that are associated with a certain bar, and the bars that are associated with a certain foo. My question is, what is th...

NSManagedObject relationship undo

I have a NSManagedObject ObjA that has a many-to-many relationship with another NSManagedObject ObjB. I initialize it with [NSEntityDescription insertNewObjectForEntityForName:@"ObjA" inManagedObjectContext:app.context]; When I perform undo without performing save - the object is not added to the persistent store. But - when I add an i...

Create a many to many relationship in Entity Framework skipping extra data in the link table.

I would like to model the following many to many relationship. Table A ID Field1 Field2 Table B ID Field1 Field2 LinkTable A_ID B_ID Field_I_want_to_ignore As I understand it, if LinkTable.Field_I_want_to_ignore was not present, the Entity Model Designer would automatically create a Many to Many relationship between entity A and ent...