many-to-many

Should Many to Many Tables Have a Primary Key?

青春壹個敷衍的年華 提交于 2019-12-03 04:23:21
If I have two objects that have a many-to-many relationship, I would typically model them in my database schema with a many-to-many table to relate the two. But should that many-to-many table (or "join table") have a primary key of its own (integer auto-incremented)? For example, I might have tables A and B, each with an ID, and a table called A_B that has a foreign key tuple of (A_ID, B_ID). But should A_B have a primary key auto-incremented ID column of its own, or not? What are the advantages and disadvantages of adding it? I personally like natural keys for many-to-many joins. But what

GUI patterns to edit data with many-to-many relationship

久未见 提交于 2019-12-03 04:14:19
问题 I often run into a situation where I need to come up with a GUI to edit data that has a n:m relationship. I'm looking for user friendly GUI ideas. [table1] | /|\ [table2] \|/ | [table3] Usually the GUI resembles something like this: Grid that shows all items from table1 Add table3 item... (shows modal window with table3 items) Grid that shows all items from table3 After the user picked a table3 item, I add a new row to table2 and refresh the grids. Disadvantages: You can only add table3 items

symfony2 many-to-many form checkbox

好久不见. 提交于 2019-12-03 03:49:08
问题 I have in symfony created 2 entities: User and Role in many-to-many relationship. That means every user can have more roles and roles can be set to many users. User class: /** * @ORM\Entity * @ORM\Table(name="JEP_User") * @ORM\Entity(repositoryClass="Chrchel\JepBundle\Repository\UserRepository") */ class User implements AdvancedUserInterface { /** * @ORM\Id() * @ORM\Column(name="id",type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(name="username",type=

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

那年仲夏 提交于 2019-12-03 03:31:48
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.InterestName = 'Football' I have looked around the net and not really found any suitable examples of how to do this. The closest I have got is: List<Customer> _Customers = (from _LCustomers in _CRM.Customer.Include("CustomerInterest.Interest") where _LCustomers

How to dynamically order many-to-many relationship with JPA or HQL?

て烟熏妆下的殇ゞ 提交于 2019-12-03 03:29:13
I have a mapping like this: @ManyToMany(cascade = CascadeType.PERSIST) @JoinTable( name="product_product_catalog", joinColumns={@JoinColumn(name="product_catalog", referencedColumnName="product_catalog")}, inverseJoinColumns={@JoinColumn(name="product", referencedColumnName="product")}) public List<Product> products = new ArrayList<Product>(); I can fetch the products for the catalog nicely, but I can't (dynamically) order the products. How could I order them? I probably have to write a many-to-many HQL query with the order-by clause? I though of passing the orderBy field name string to the

filtering by association attributes with SqlAlchemy association_proxy

与世无争的帅哥 提交于 2019-12-03 02:26:59
I have a many-to-many (developers & projects) relationship modeled using SA's association_proxy . The collections (developers on each project & projects for each developer) work fine, but I need to filter on an attribute of the association itself (status). Something like this (which does not work): activeDevelopers = s.query(Developer).filter_by(Developer.developerProjects.status == 'active').all() What am I missing? Here is the complete test code: import logging from sqlalchemy import create_engine, Table, Column, Integer, String, MetaData, ForeignKey from sqlalchemy.orm import relation,

MySQL - How to insert into table that has many-to-many relationship

白昼怎懂夜的黑 提交于 2019-12-03 01:13:49
问题 I have a table of persons. Each person has a property and many persons may have a certain property. So this is a many-to-many relationship. This is the schema: CREATE TABLE persons ( person_id int(11) NOT NULL AUTO_INCREMENT, firstname varchar(30) NOT NULL, lastname varchar(30) NOT NULL, PRIMARY KEY (person_id) ); CREATE TABLE properties ( property_id int(11) NOT NULL AUTO_INCREMENT, property varchar(254) NOT NULL UNIQUE, PRIMARY KEY (property_id) ); CREATE TABLE has_property ( person_id int

How to update/create many-to-many relational data in MVC Code-first using EF?

帅比萌擦擦* 提交于 2019-12-03 00:32:39
I have pored through StackOverflow, Google and asp.net trying to find a clear cut, basic example of how to do this. All the examples have been abstract or involved complications that do not apply. I haven't been able to extract much useful from them. So far, none of them have completely answered my question or addressed my issue(s). I am working on an MVC project with the following model: Article.cs: public class Article { public int ArticleId { get; set; } public string Title { get; set; } . . . public virtual ICollection<Category> Categories { get; set; } public Article() { Categories = new

How to query directly the table created by Django for a ManyToMany relation?

本秂侑毒 提交于 2019-12-02 22:03:38
I have a model MyModel2 with a ManyToManyField related to another model MyModel1 . How can I get the pairs mymodel1.id, mymodel2.id , as represented in the table Django create for this relation? Do I have to do a raw SQL query on this table or is it possible through the object managers of this models? class MyModel1(models.Model): name = models.CharField(max_length=50) class MyModel2(models.Model): name = models.CharField(max_length=50) mymodel1 = models.ManyToManyField(MyModel1) This is the many to many field instance: MyModel2.mymodel1 This is the intermediary table model: MyModel2.mymodel1

Symfony2 Doctrine2 Many-To-Many relation with two Owning Sides and Doctrine cmd line tools

烂漫一生 提交于 2019-12-02 21:59:56
In my Symdony2 project I've two related entities: Service and ServiceGroup. This should be many-to-many relationship, because each group can have many services, and each service can belongs to many groups. Moreover, I need a user interface to manage services and groups. So, when editing a Service, user should be able to choose to which groups it belongs. Analogously, when editing a ServiceGroup user should be able to choose which services belongs to this group. I've already achieved this by setting up a Many-To-Many relation in my Doctrine entites. Everything is working like a charm, including