many-to-many

Entering a variable amount of data into a database with the best normalization possible

Hi guys, ok, so I have a database comprising of two tables, products and suppliers. All suppliers fill in a form and their data is then stored in the suppliers table, and the products table contains a list of all of the products, so when the supplier fills in the form, he can choose as many products as he wishes as I use jQuery JSON a...

mongoid uniqueness validation many-to-many relation

I have following association class Employee include Mongoid::Document employee_id :name references_many :companies, stored_as => :array, :inverse_of => :employees end class Company include Mongoid::Document field :name references_many :employees, stored_as => :array, :inverse_of => :companies end Now How can I check the uni...

hibernate many-to-many association and spring hibernatetemplate doesn't work

I am using Spring HibernateTemplate, OpenSessionInViewFilter(actually I extended this class and created my own to switch to FLUSH.AUTO Mode) and Mysql for implementing hibernate many-to-many association. However when I save an object, corresponding many-to-many table's values are not inserted. Does anybody can help me? Thank you. here i...

NHibernate many-to-many and SELECT N+1 problem

I have 4 database tables (Channel, User, Message, User2Channel) and according entity classes: class **Channel** { int ChannelId {get;set;} int ISet<User> UsersToChannel {get;set;} ... } class **Message** { int MessageId {get;set;} Channel Channel {get;set;} User User {get;set;} ... } class **User**{ int UserId {get;set;} ISet<...

Django admin - How can I add the green plus sign for Many-to-many Field in custom admin form

The green plus sign button for adding new instances in the admin form disappears for my MultiSelect field (photos) when I define it in my form. Ie, removing the line with the definition (photos = ...) makes the plus sign appear. However, in order to use a custom Field/Widget I need to figure this out. class GalleryForm(ModelForm): ...

What is the proper table and join structure for a many to many relationship between the same attributes of the same table?

Lets say I have a Users table with a UserID column and I need to model a scenario where a user can have multiple relationships with another user, e.g. phone calls. Any user can initiate 0...n phone calls with another user. Would it be a classic junction table like: UserCalls ----------------------- | CallerID | CalleeID | ------------...

Automapper - Bestpractice of mapping a many-to-many association into a flat object

I have two entities: Employee and Team. What I want is an EmployeeForm that has the Name of the Team. How can I achieve this using AutoMapper? My current "solution" is the following: Mapper.CreateMap<Employee, EmployeeForm>() .ForMember(dest => dest.TeamName, opt => opt.MapFrom(x => x.GetTeams().FirstO...

ejb3: mapping many-to-many relationship jointable with a simple primary key

often in books, i see that when a many-to-many relationship is translated to a DB schema, the JoinTable gets a compound key consisting of the primary keys of the tables involved in many-to-many relationship. I try to avoid compound keys completely. So i usually create a surrogate key even for the JoinTable and allow the database to fill ...

Hibernate Many-to-Many Criteria Projection

EDIT> i am at a dead end... so i can continue looking for the main reason .. Please tell me how to make a simple criteria for many to many relationships which has more than one eq restrictions, for an example, how to get the person speaking eng & german in the example shown here... My situation is like this i have two classes person and...

Removing an item from a many-to-many association in NHibernate

Dearest All, I have a one-directional many-to-many association: the ListDefinition class has the Columns property of type IList, while a column can be part of several ListDefinition-s. The problem is, whenever I try to remove a column from one Columns collection (without deleting it or removing from other ListDefinitions), I'm getting t...

query many-to-many nhibernate when only one side is mapped

I have the following entities public class Client { public virtual int Id{get;set;} public virtual IList<Telephone> Telephones { get; private set; } } public class User { public virtual int Id{get;set;} public virtual IList<Telephone> Telephones { get; private set; } } public class Telephone { public virtual int Id...

Criteria Many-to-Many Hibernate

@Entity public class Person implements Serializable { private int id; ........... private Set<Languages> languages = new HashSet<Languages>(); ............... @ManyToMany @JoinTable(name = "link_person_languages") public Set<Languages> getLanguages() { return languages; } } @Entity public...

Why is Session.Flush() required to persist relationships?

I have two entities, a Shelf and a Product: public class Shelf { public virtual IList<Product> Products { get; set; } public Shelf() { Products = new List<Product>(); } } public class Product { public virtual string Name { get; set; } } Basically put, a Shelf can contain many Products, and a Product can b...

mysql many-to-many tag implementation + full tag listing

based on http://stackoverflow.com/questions/1529073/how-to-implement-tagging-system-similar-to-so-in-php-mysql ive made small changes, and have the following image tag implementation: SELECT I.imageId, GROUP_CONCAT(DISTINCT T.tagName SEPARATOR ' '), COUNT(*) FROM Images I INNER JOIN ImageTagMap M ON I.imageId = M.imageId INNER JOIN Ima...

how to allow orphan recordsets in many-to-many bridge tables

hello, I have a problem that I can't seem to solve. I have table: Software and table: PC they both have many to many relationship between each other, that is, one PC can have many Software and One Software can have many PC's the link table is: soft-pc The table soft-pc also has licensing information like, product keys. now the problem...

Query for newest record in a table, store query as view

I'm trying to turn this query into a view: SELECT t.* FROM user t JOIN (SELECT t.UserId, MAX( t.creationDate ) 'max_date' FROM user t GROUP BY t.UserId) x ON x.UserId = t.UserId AND x.max_date = t.creationDate But views do not accept subqueries. What this does is look for the la...

Many to many query with a count of condition > 0

Hi everyone, I have 3 tables: Emails Foo EmailFoos (The many to many join table) Foo can be complete or not. I need to find the set of emails where the count of completed foos > 0 (and the inverse, but I can probably do that ;) I tried something like: SELECT e.id, e.address, count(l.foo_id) as foo_count FROM emails e LEFT ...

NHibernate many-to-many and deleting an item

Dearest All, I've got a many-to-many association between Lists and ListItems: a List knows about its Items, but a ListItem doesn't know about the containing lists. The cascade is saveupdate. So, whenever I'm trying to delete a ListItem entity, I'm getting an SQLException saying I'm breaking the referential integrity. NHibernate tries t...

Complicated Sub-query - is this possible?

I've got 2 tables: one stores tags, the other stores articles. There's a mode "Get articles by tag", which basically takes all articles, tagged "x". In my articles table I use a filed, called Tags, that stores data in such pattern 'tag1, tag2, tag3, ...'. So I want to get everything work by just a single query like that: SELECT *, ...

Filtering results based on many to many relationships

I'd like to filter the results of a query which returns the results from two tables which have any to many relationship to each other. Consider the following scenario: (SQL Server or MS Access) Table: Students --StudentID --StudentName Table: Grades --StudentID (Foreign Key) --CourseID (Foreign Key. Ignore for the sak...