many-to-many

Many-to-Many with ECTO and put_assoc/4

与世无争的帅哥 提交于 2019-12-21 21:42:18
问题 I try associate 2 existing Many-to-Many records with ECTO and put_assoc/4 but won't remove elements when try update. Basically i have projects and users . for manage the access of users to projects i have the table "user_project". def Project do schema "project" do ... # users (if user_type is :admin) many_to_many( :users, User, join_through: "user_project" ) ... end end def User do schema "user" do ... # users (if user_type is :admin) many_to_many( :projects, User, join_through: "user

Hibernate / JPA many to many relationship through a join table and a composite key, Unique Constraint issue

て烟熏妆下的殇ゞ 提交于 2019-12-21 17:24:45
问题 So I asked this question yesterday, but the goal posts have changed and the question is different: Hibernate / JPA Collection of Elements with Many to Many relationship? I want to know if it's possible to create entities that will model my required relationship so that Hibernate will create my schema when I fire up my application. The relationship I want looks like this: 1 http://a8.sphotos.ak.fbcdn.net/hphotos-ak-ash4/417593_10150594114269218_505554217_8657377_1475865815_n.jpg The thing is

How to correctly use auto_created attribute in django?

冷暖自知 提交于 2019-12-21 08:01:11
问题 I need to create my own intermediate model. class class1(models.Model) class class2(models.Model): field1 = models.ManyToManyField(class1, through="class3") class class3(models.Model): field1 = models.ForeignKey(class1) field2 = models.ForeignKey(class2) field3 = models.IntegerField() class Meta: auto_created = True I use "auto_created=True" because in the following code, I had the error : AttributeError: Cannot use add() on a ManyToManyField which specifies an intermediary model. for m2m

JPA Hibernate - Issue with manytomany mapping with extra column in the mapping table

别说谁变了你拦得住时间么 提交于 2019-12-21 06:36:06
问题 I am facing problem while saving a record when i have an extra column in the mapping table in case of manytomany relationship. Please see below for details. There is manytomany relationship between User and BankAccounts. The mapping table for user_bankaccounts has an extra column called user_type, apart from the primary keys of User and BankAccount table. However, when i try to save a bank account record, mapping table data is not inserted in the user_bankaccount table. Only bankaccount table

JPA with Hibernate - Many to Many relationship, fetching all data

为君一笑 提交于 2019-12-21 06:28:08
问题 I have many to many relation ship between User and Roles. For example public class User { @Id private Integer id; @ManyToMany @JoinTable(name = "APP_USER_ROLE", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") }) private List<Role> roles = new ArrayList<Role>(); } @Entity public class Role { @Id private Integer id; @ManyToMany(mappedBy = "roles") private List<User> users = new ArrayList<User>(); } My requirement is to fetch all users in the

Django: accessing ManyToManyField objects after the save

你说的曾经没有我的故事 提交于 2019-12-21 06:05:16
问题 This is baffling me... When I save my model, the book objects are unchanged. But if I open the invoice and save it again, the changes are made. What am I doing wrong? class Invoice(models.Model): ... books = models.ManyToManyField(Book,blank=True,null=True) ... def save(self, *args, **kwargs): super(Invoice, self).save(*args, **kwargs) for book in self.books.all(): book.quantity -= 1 if book.quantity == 0: book.sold = True; book.save() Edit: I've tried using the post_save signal, but it works

Generic many-to-many relationships in django admin

血红的双手。 提交于 2019-12-21 05:06:20
问题 I have few similar models in Django: class Material(models.Model): title = models.CharField(max_length=255) class Meta: abstract = True class News(Material): state = models.PositiveSmallIntegerField(choices=NEWS_STATE_CHOICES) class Article(Material): genre = models.ForeignKey(Genre, verbose_name='genre') And model Topic , which is related to News and Article as ManyToMany. I'd like to use Generic many-to-many relationships like in this case. But question is how to use default ManyToMany

What is the best way to represent a many-to-many relationship between records in a single SQL table?

风流意气都作罢 提交于 2019-12-21 04:54:07
问题 I have a SQL table like so: Update: I'm changing the example table as the existing hierarchical nature of the original data (State, Cities, Schools) is overshadowing the fact that a simple relationship is needed between the items. entities id name 1 Apple 2 Orange 3 Banana 4 Carrot 5 Mushroom I want to define two-way relationships between these entities so a user viewing one entity can see a list of all related entities. The relationships are defined by an end user. What is the best way to

JPA Annotations for many-to-many relation between objects of the same entity

╄→尐↘猪︶ㄣ 提交于 2019-12-21 02:41:43
问题 I want to implement a Role Hierarchy but am rather new to JPA Annotations. I have a Role Entity with a name and an id(implicit via AbstractPersistable ): @Entity @Table(name="role") public class Role extends AbstractPersistable<Long> { private static final long serialVersionUID = 8127092070228048914L; private String name; Now I want to be able to define the following relationships: a Role can have many child roles a Role can be child to many roles How would I do that with Hibernate

JPA Annotations for many-to-many relation between objects of the same entity

我的梦境 提交于 2019-12-21 02:41:06
问题 I want to implement a Role Hierarchy but am rather new to JPA Annotations. I have a Role Entity with a name and an id(implicit via AbstractPersistable ): @Entity @Table(name="role") public class Role extends AbstractPersistable<Long> { private static final long serialVersionUID = 8127092070228048914L; private String name; Now I want to be able to define the following relationships: a Role can have many child roles a Role can be child to many roles How would I do that with Hibernate