many-to-many

How to edit m2m in Django via ModelForm

可紊 提交于 2019-12-25 12:01:17
问题 I have 2 models: class Case(models.Model): Priority = ( ('Blocker', 'Blocker'), ('High', 'High'), ('Medium', 'Medium'), ('Low', 'Low'), ) id = models.AutoField(primary_key=True) name = models.CharField(max_length=200) image = models.URLField(blank=True) requirements = models.URLField(blank=True) priority = models.CharField(max_length=10, choices=Priority) description = models.CharField(max_length=200) step = models.TextField() modified = models.DateTimeField(editable=False) user = models

ManyToMany with cascade all only cascading one way

你离开我真会死。 提交于 2019-12-25 09:12:09
问题 I have 2 entities: 1) User 2) Department. each contains a SET of the other since the relationship between them is manyToMany, I marked (CascadeType.ALL) on the user entity and the department entity and when i do : userX.getDepartments.remove(departmentX); save(userX); it works like intended - it actually implies that departmentX.getUsers.contains(userX) == false. is called implicitly. BUT , when i do departmentY.getUsers.remove(userX); save(departmentY); it doesn't cascade! meaning - i can do

Large Scale Additions and Deletions Many-to-Many Relationship in Entity Framework

心已入冬 提交于 2019-12-25 08:29:35
问题 I am currently working on a project that has recently acquired many database records. I now am trying to optimize for this. Here are my models: public class QueueEntity { public int Id { get; set; } public string Name { get; set; } public virtual List<PhraseEntity> Phrases { get; set; } } public class PhraseEntity { public int Id { get; set; } public string Name { get; set; } public virtual SourceEntity Source { get; set; } public virtual List<QueueEntity> Queues { get; set; } } public class

How can i save manytomany field in django?

喜欢而已 提交于 2019-12-25 06:56:05
问题 models.py: class Tag(models.Model): name = models.CharField(max_length=100) description = models.CharField(max_length=500, null=True, blank=True) created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now_add=True) class Post(models.Model): user = models.ForeignKey(User) tag = models.ManyToManyField(Tag) title = models.CharField(max_length=100) content = models.TextField() created = models.DateTimeField(default=datetime.datetime.now) modified = models

JPA Cascade remove orphans

余生长醉 提交于 2019-12-25 05:55:27
问题 I have a question. I use JPA with eclipselink and I have relationship: Table A ---< Table AB >---- Table B class A { @OneToMany(mappedBy = "a") private List<AB> abList } class AB { @ManyToOne(fetch = FetchType.LAZY) private A a; @ManyToOne(fetch = FetchType.LAZY) private B b; } class B { @OneToMany(mappedBy = "b") private List<AB> abList; } It is ManyToMany relationship between A and B with join table AB. Now I want to remove a record from table A and to cascade remove records from table AB

Entity Framework 4 CTP 5 POCO - Many-to-many or Lookup table?

喜你入骨 提交于 2019-12-25 04:44:16
问题 I'm building a personal blog app with Entity Framework 4 CTP 5 POCO only, where a Post can have many Tags and a Tag can be in many Posts . My question is whether to build a many-to-many model, or to have a lookup table. At first I was trying to use many-to-many, but I don't know how to do insertion, each time a new post is posted (with many tags selected), I'm not sure what to do so that the tags should be associated with the post (and wouldn't insert a new tag if the tag name already exists.

Sorting a many to many relation with Laravel Eloquent

余生颓废 提交于 2019-12-25 04:43:33
问题 I do have swatches table, a colors table and a swatch_color pivot table. Relations are set as: public function colors() { return $this->belongsToMany('Color'); } public function swatches() { return $this->belongsToMany('Swatch'); } I have no problem to retrieve the swatches with the color relations $swatches = Swatch::with('colors')->get(); return dd($swatches); Colors is always an array of 5 color objects with hue, R, G, and B attributes. Now I would like to sort the swatches by the R value

Django - Create the equivalent of a “cross-join” query with the Django ORM

谁说胖子不能爱 提交于 2019-12-25 04:16:13
问题 I have two Django models with are related to each other through a many-to-many relationship. I need to list the cross product of both tables. Let say for simplicity's sake that the two models are Pizza and Topping. I would like the query to return something like this: pizza_name topping --------------------- all dressed cheese all dressed mushrooms all dressed onions all dressed peperoni all dressed pepper reddit cheese reddit peperoni reddit bacon reddit baconbits The amount of data will be

User groups management

时光总嘲笑我的痴心妄想 提交于 2019-12-25 04:05:00
问题 I am trying to implement user management functionality for a web site. I am using ASP.NET MVC 3, Entity Framework 4.1, MvcScaffolding. Let's consider the entities: The user entity: public class User { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public virtual ICollection<UserGroup> Groups { get; set; } } The user group entity: public class UserGroup { public int Id { get; set; } public string Name { get; set; } public virtual

Creating Many-2-Many reference with EF

最后都变了- 提交于 2019-12-25 04:02:42
问题 In my current project (which is really small) i have 3 tables/ POCO entities which i would like to manipulate using EF. The Tables are: Status (contains status details) StatusStatusType (which is needed because of the many-2-many relationship) StatusType (A table which is used to group statuses by type) I now want to create a new Status in the database and user code like you see below //Create new status (POCO) entity var newStatus = new Status { StatusId = status.Id, UserId = user.Id, Text =