many-to-many

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

孤人 提交于 2019-12-02 18:27:21
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="Message_forum", blank=True, null=True) ... class Message_forum(models.Model): message = models.ForeignKey(Message) forum = models.ForeignKey(Forum) status = models.IntegerField() position = models.IntegerField(blank=True, null=True) tags = models.ManyToManyField(Tag, blank=True, null=True) In the

symfony2 many-to-many form checkbox

二次信任 提交于 2019-12-02 18:07:10
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="string",length=100,unique=true) */ private $username; /** * @ORM\ManyToMany(targetEntity="Role",

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

谁都会走 提交于 2019-12-02 17:32:18
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 to table1, and not the other way around; You can only browse table1 items and see related table3 items

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

ぃ、小莉子 提交于 2019-12-02 14:32:11
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(11) NOT NULL, property_id int(11) NOT NULL, PRIMARY KEY (person_id,property_id), FOREIGN KEY (person_id

Insert into many-to-many relationship tables

让人想犯罪 __ 提交于 2019-12-02 14:17:48
问题 Simple scenario [ClientTable]: ClientId, ClientName, Phone, Age [CityTable]: CityID, CityName, Country [ClientCityTable]: ClientCityID, ClientID, CityID Client client = new Client("John", 123456789, 40); City city = new City("NY", USA); ClientCity clientCity = new ClientCity(client, city); Should I make InsertOnSubmit on every object(table) or only on clientCity? Or it doesn't matter? Where's the difference? EDIT I'ms asking if should I make DatabaseDC dc = new DatabaseDC(connectionString);

Insert into many-to-many relationship tables

此生再无相见时 提交于 2019-12-02 12:15:32
Simple scenario [ClientTable]: ClientId, ClientName, Phone, Age [CityTable]: CityID, CityName, Country [ClientCityTable]: ClientCityID, ClientID, CityID Client client = new Client("John", 123456789, 40); City city = new City("NY", USA); ClientCity clientCity = new ClientCity(client, city); Should I make InsertOnSubmit on every object(table) or only on clientCity? Or it doesn't matter? Where's the difference? EDIT I'ms asking if should I make DatabaseDC dc = new DatabaseDC(connectionString); dc.Client.InsertOnSubmit(client); dc.City.InsertOnSubmit(city); dc.ClientCity.InsertOnSubmit(clientCity)

Get data of all entities in a many-to-many relationship

ⅰ亾dé卋堺 提交于 2019-12-02 12:09:12
问题 picture of DB My database has 3 tables Customers, Films and CustomersFilms is the brige table between Films and Customers now, I want to diaplay a table of cutomers with the movies they rented. I wrote a function that does the job for spesific id ( in the code 8 and 9 ). My Question is how to show the data to all entitys ? public ActionResult GetData() { MyDatabaseEntities2 db = new MyDatabaseEntities2(); var q = (from c in db.Customers from Films in db.Films where Films.FilmId == 8 where c

Rails: How to sort many-to-many relation

折月煮酒 提交于 2019-12-02 11:34:28
I have a many-to-many relationship between a model User and Picture. These are linked by a join table called Picturization. If I obtain a list of users of a single picture, i.e. picture.users -> how can I ensure that the result obtained is sorted by either creation of the Picturization row (i.e. the order at which a picture was associated to a user). How would this change if I wanted to obtain this in order of modification? Thanks! Edit Maybe something like picture.users.where(:order => "created_at") but this created_at refers to the created_at in picturization Firoz Ansari Have an additional

Entity framework 4 many-to-many insertion?

我的未来我决定 提交于 2019-12-02 11:02:54
I'm not very familiar with the many-to-many insertion process using Entity Framework 4, POCO. I have a blog with 3 tables: Post, Comment, and Tag. A Post can have many Tags and a Tag can be in many Posts . Here are the Post and Tag models: public class Tag { public int Id { get; set; } [Required] [StringLength(25, ErrorMessage = "Tag name can't exceed 25 characters.")] public string Name { get; set; } public virtual ICollection<Post> Posts { get; set; } } public class Post { public int Id { get; set; } [Required] [StringLength(512, ErrorMessage = "Title can't exceed 512 characters")] public

Return all nodes in many-to-many hierarchal tree

别说谁变了你拦得住时间么 提交于 2019-12-02 10:26:21
Similar to this question: How do I query for all the nodes between two nodes in a tree? But I do not have a closure (flattened) table, a child can have many parents, and ID traversal is not necessarily in order. There is no limit to the nesting depth. Assume a circular reference is impossible... I would like to return all rows required to traverse the hierarchy. Assume the following table: ParentID ID RowNumber(Reference) 1 2 1 2 4 2 4 3 3 3 5 4 1 6 5 6 7 6 2 8 7 3 9 8 1 8 9 6 8 10 Given 1 how would I write a single query to return all the rows (get all descendants' relationsips)? Likewise,