many-to-many

Django: How to follow ManyToMany('self') backwards

情到浓时终转凉″ 提交于 2019-12-11 04:06:56
问题 class c(models.Model): f = models.ManyToManyField( 'self', blank=True, null=True, related_name='child_set' ) I can do : c.objects.get(pk="1").f But how do I get by '_set'? c.objects.get(pk="1").child_set doesn't work i need this: {name:A,parent:[]} {name:B,parent:[A]} {name:C,parent:[A,B]} C.parent.all() == [A,B] A.parent_set.all() == [B,C] 回答1: For ManyToManyField s that reference self , a reverse relationship is not created. This is because it has no use - it would contain all relations

@ManyToMany inconsistent data on both side problem

白昼怎懂夜的黑 提交于 2019-12-11 03:57:08
问题 I have a blog-like scenario , with two Java classes : Post and Tag , which is a @ManyToMany relationship , with a Post_Tag association table , here is my simplified definitions: public class Post { @ManyToMany(fetch=FetchType.LAZY) @Fetch(FetchMode.SELECT) @JoinTable(name = "Post_Tag" , joinColumns = @JoinColumn(name="Post_id") , inverseJoinColumns = @JoinColumn(name="Tag_id") ) private Set<PostTag> tags = new HashSet<PostTag>(); } public class Tag { @ManyToMany(mappedBy="tags" , fetch

Naming Generated Functions in Propel

╄→гoц情女王★ 提交于 2019-12-11 03:52:56
问题 The ideo of cross-reference tables is introduced in Propel 1.5. This means that an entity can get a list of related items as if it were a one-to-many relation. So in a person-to-groups relationship, a person can call getGroups() , and a group can call getPersons() . This makes things much easier to handle. However, if an entity has a many-to-many relationship to itself, the names of the function calls become more complex. As an example, the following permits groups to contain groups within

How to save associated joinData in cakephp 3.x

安稳与你 提交于 2019-12-11 03:52:34
问题 I have Problems and Fields in a many-to-many relationship. The join table fields_problems has a field named fieldvalue I am trying to have a form that will insert a problem record and also multiple records into fields_problems. /src/Model/Table/ProblemsTable.php class ProblemsTable extends Table { public function initialize(array $config) { parent::initialize($config); $this->table('problems'); $this->displayField('id'); $this->primaryKey('id'); $this->addBehavior('Timestamp'); $this-

Add many to many relation without fetching child entity from database

你说的曾经没有我的故事 提交于 2019-12-11 03:42:15
问题 I have Book and Author entities with many to many relation and I am trying to save the relation (a record in junction table) with Database first approach. I would like to start with my working version of code [HttpPost] public ActionResult Edit(BookViewModel bookv) { Mapper.CreateMap<AuthorViewModel, Author>(); List<Author> authors = Mapper.Map<List<AuthorViewModel>, List<Author>> (bookv.Authors.ToList()); //remove authors from book object to avoid multiple entities with same key error bookv

Multiple Many-to-Many Relationships (Circular Relationship)

时间秒杀一切 提交于 2019-12-11 02:46:33
问题 OK, I'm new to programming things, mainly learned myself by reading sites.... but I'm looking for an answer I haven't found fully explained anywhere. I have three tables in a database: - Parts - Tools - Machines I have read many instances of two junction tables connecting these three tables, but can this be circular, and I have three junction tables connecting the three info tables? These are all Many-to-Many relationships.... for example: Part A and B are both made from Tool 1 Part A is also

MySql query over many-to-many relationship [duplicate]

别等时光非礼了梦想. 提交于 2019-12-11 02:35:31
问题 This question already has answers here : SQL query that gives distinct results that match multiple columns (4 answers) Closed 4 months ago . A very simple example of a n:m relationship that puzzles me. Let's assume we have two tables "Plant" and "Attribute" and another table between them holding their relationship with their IDs: Plant--------hasAttribute--------Attribute P1 | A1 P1 | A2 P1 | A3 P2 | A1 P2 | A2 P3 | A2 P3 | A3 So, Plant 1 has Attributes 1,2 and 3. Plant 2 has Attributes 1 and

Tag based SQL query

蹲街弑〆低调 提交于 2019-12-11 02:26:50
问题 Its been a while since I have done any SQL and I am not sure if this problem has an easy solution or not. Also I am a bit of a Noob. I am trying to put together an image gallery that allows users to use tags in order to search for images and then click on additional tags to refine the search and lower the number of results but I am having a big issue with the queries involved. This is a simplified version of my current database structure: ( 2 tables with an additional Many-to-Many link table

Entity Framework 6.2 copy many to many from one DbContext to another DbContext

帅比萌擦擦* 提交于 2019-12-11 02:20:50
问题 When working with a network database such as MySQL, the DbContext should be short lived, but according to https://www.entityframeworktutorial.net/EntityFramework4.3/persistence-in-entity-framework.aspx the DbContext can be long lived when working with a local database, such as SQLite. My app is using a long lived DbContext to work with SQLite on HDD and I want to copy many-to-many entities to another DbContext for the same type of SQLite database on USB. I am using the Code-First approach.

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

最后都变了- 提交于 2019-12-11 01:47:27
问题 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]: <A: 1> In [4]: b1=B() In [5]: b1.save() In [6]: b1 Out[6]: <B: 1> In [7]: b2=B() In [8]: b2.save() In [9]: b2 Out[9]: <B: 2> In [10]: a1.b_set.add(b1) In [11]: a1.b_set.all() Out[11]: [<B: