many-to-many

UnsupportedOperationException merge-saving many-to-many relation with hibernate and JPA

邮差的信 提交于 2019-12-18 13:53:14
问题 I've set up a simple many-to-many relationship account : role with Hibernate but when I try to save an account in a unit test after it has had its role added I get an UnsupportedOperationException: java.lang.UnsupportedOperationException at java.util.AbstractList.remove(AbstractList.java:144) at java.util.AbstractList$Itr.remove(AbstractList.java:360) at java.util.AbstractList.removeRange(AbstractList.java:559) at java.util.AbstractList.clear(AbstractList.java:217) at org.hibernate.type

many-to-many: has_many :through association form with data assigned to linking model create form view

旧街凉风 提交于 2019-12-18 12:44:34
问题 I'm playing with an example from Rails Guides: http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association This example has the following setup for the models: class Physician < ActiveRecord::Base has_many :appointments has_many :patients, :through => :appointments end class Appointment < ActiveRecord::Base belongs_to :physician belongs_to :patient end class Patient < ActiveRecord::Base has_many :appointments has_many :physicians, :through => :appointments end I'm

Junction tables vs foreign key arrays?

末鹿安然 提交于 2019-12-18 11:44:46
问题 I'm modeling many-to-many relationship where the relationship is accessed most of the time from one side only. It's more like a hierarchy, that is accessed top-down and not the other way around. Survey has and belongs to many Questions has and belongs to many Answers . Both relationships must be many-to-many because a same question can be re-used across different surveys and same answer in many questions. This is a requirement. The standard M2M implementation would use two junction tables,

SQLAlchemy how to filter by children in many to many

痞子三分冷 提交于 2019-12-18 11:35:29
问题 I was asking for a problem I had in SQLAlchemy and found the solution while writing. I post it anyway just in case it helps somebody :) Let's say I have a many to many relationship that seems to work (at least I can fetch children) Three tables: posts, tags and post_tags. import sqlalchemy as alc class Tag(Base): __tablename__ = 'tags' id = alc.Column(alc.Integer, primary_key=True) name = alc.Column(alc.String) accepted = alc.Column(alc.Integer) posts = relationship('Post', secondary=post

JPA Hibernate many-to-many cascading

北城以北 提交于 2019-12-18 10:01:45
问题 I am using JPA 2.0 and hibernate. I have a User class and a Group class as follows: public class User implements Serializable { @Id @Column(name="USER_ID") private String userId; @ManyToMany @JoinTable(name = "USER_GROUP", joinColumns = { @JoinColumn(name = "GROUP_ID") }, inverseJoinColumns = { @JoinColumn(name = "USER_ID") } ) private Set<Group> groupList; //get set methods } public class Group { @Id @Column(name="GROUP_ID") private String groupId; @ManyToMany(mappedBy="groupList") private

mysql query show multiple tables from one ID column

十年热恋 提交于 2019-12-18 09:56:43
问题 I'm trying to find this query where I want to show which hosts uses which template from my Zabbix table. The only problem is that hosts and templates are registered in the same table. They are mixed in the table with for example ID 11813 being a host and 11815 being a template. Now I've found a table where the relation between these 2 is defined: hosts_templates. This table has 3 columns: a host_template id, hostid, templateid The table hosts has many columns but also containing: hostid, name

mysql query show multiple tables from one ID column

╄→尐↘猪︶ㄣ 提交于 2019-12-18 09:56:25
问题 I'm trying to find this query where I want to show which hosts uses which template from my Zabbix table. The only problem is that hosts and templates are registered in the same table. They are mixed in the table with for example ID 11813 being a host and 11815 being a template. Now I've found a table where the relation between these 2 is defined: hosts_templates. This table has 3 columns: a host_template id, hostid, templateid The table hosts has many columns but also containing: hostid, name

Many to Many Self referencing relationship

泪湿孤枕 提交于 2019-12-18 09:45:53
问题 I'm attempting to create a library database using SQL in which one book_id recommends another book_id number. The table I have created is as follows: CREATE TABLE BOOK ( Book_id INT NOT NULL, Book_name VARCHAR(40) NOT NULL, Description VARCHAR (100) NOT NULL, Image BLOB NOT NULL, Category_id INT NOT NULL, PRIMARY KEY (Book_id), FOREIGN KEY (Category_id) REFERENCES Category (Category_id) Do I need to create a separate table in order to enforce this many to many self relationship? 回答1: You

Django - Access fields on a model's “through” table from an instance

亡梦爱人 提交于 2019-12-18 09:21:28
问题 I have a many-to-many relationship with a through table like so: class Chapter(models.Model): name = models.CharField(max_length=255,) slides = models.ManyToManyField('Slide', blank=True, related_name='chapters', through='SlideOrder') # ... class Slide(models.Model): title = models.CharField(max_length=255,) # ... class SlideOrder(models.Model): chapter = models.ForeignKey(Chapter) slide = models.ForeignKey(Slide) number = models.PositiveIntegerField() I am able to get the slides for a

Way to allow for duplicate many-to-many entries in Python/Django

ぐ巨炮叔叔 提交于 2019-12-18 09:04:16
问题 I have the following Django model: class Icon(models.Model): name = models.CharField(max_length=200,null=False,blank=False) class Post(models.Model): icons = models.ManyToManyField(Icon) When I write the following code: post = Post() icons = [] icon_id = form.cleaned_data['icon_1'] if (icon_id): i = Icon.objects.get(id=icon_id) icons.append(i) icon_id = form.cleaned_data['icon_2'] if (icon_id): i = Icon.objects.get(id=icon_id) icons.append(i) post.icons = icons post.save() It works fine for