many-to-many

jpa criteria for many to many relationship

天涯浪子 提交于 2019-11-30 04:52:26
I have 2 POJO classes in Java, Answer and Collaborator, in a many-to-many relationship. class Answer { @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = "ANSWERS_COLLABORATORS", joinColumns = { @JoinColumn(name = "aid") }, inverseJoinColumns = { @JoinColumn(name = "cid") }) private Set<Collaborator> collaborators = new HashSet<Collaborator>(0); } Class Answer has a set of Collaborator , but a Collaborator doesn't keep a set of Answer . What I need to do from Hibernate CriteriaQuery is to find the collaborators for an answer given by id. I have already done this with Hibernate Criteria (

Selecting an item matching multiple tags

我只是一个虾纸丫 提交于 2019-11-30 04:46:46
问题 This seems very basic but I can't figure it out. I've got a table "item_tags", and I want to select all of the items that match tags 1 and 2 (as in, each item has to have both tags). How would I do this in mysql? Create table is: CREATE TABLE `item_tags` ( `uid_local` int(11) NOT NULL DEFAULT '0', `uid_foreign` int(11) NOT NULL DEFAULT '0', `sorting` int(11) NOT NULL DEFAULT '0', KEY `uid_local` (`uid_local`), KEY `uid_foreign` (`uid_foreign`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Thanks! 回答1

Junction tables vs foreign key arrays?

折月煮酒 提交于 2019-11-30 04:40:16
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, surveys_questions and questions_answers . Instead, I'm thinking about using PostgreSQL's integer arrays

Ebean ManyToMany query

╄→гoц情女王★ 提交于 2019-11-30 03:46:19
问题 I have two classes, user and car. Both have ManyToMany mapping to each other. User: @Entity public class User extends Model { private int year; @ManyToMany(cascade=CascadeType.ALL) private List<Car> cars; } Car: @Entity public class Car extends Model { @ManyToMany(mappedBy = "cars", cascade=CascadeType.ALL ) private List<User> users; } Using ebean, I would like to query only those cars from year 1999 that have give user in their list. I do not want to iterate over the user's car list in Java

SQLAlchemy how to filter by children in many to many

倾然丶 夕夏残阳落幕 提交于 2019-11-30 03:43:15
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_tags) class Post(Base): __tablename__ = 'posts' id = alc.Column(alc.Integer, primary_key=True) text = alc

Many To Many Table Join With Pivot

非 Y 不嫁゛ 提交于 2019-11-30 03:21:40
问题 I currently have two tables similar to users and programs that are linked through a many-to-many relationships by way of a link table. mysql> select * from users; +----+----------+ | id | name | +----+----------+ | 1 | Jonathan | | 2 | Little | | 3 | Annie | | 4 | Bob | +----+----------+ 4 rows in set (0.00 sec) mysql> select * from programs; +----+----------------------+ | id | name | +----+----------------------+ | 1 | Microsoft Word | | 2 | Microsoft Excel | | 3 | Microsoft PowerPoint | +-

How to prevent self (recursive) selection for FK / MTM fields in the Django Admin

浪子不回头ぞ 提交于 2019-11-30 02:51:05
问题 Given a model with ForeignKeyField (FKF) or ManyToManyField (MTMF) fields with a foreignkey to 'self' how can I prevent self (recursive) selection within the Django Admin (admin). In short, it should be possible to prevent self (recursive) selection of a model instance in the admin. This applies when editing existing instances of a model, not creating new instances. For example, take the following model for an article in a news app; class Article(models.Model): title = models.CharField(max

Calling a function inside an iframe from outside the iframe [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-11-30 02:47:32
问题 This question already has answers here : Invoking JavaScript code in an iframe from the parent page (17 answers) Closed 5 years ago . I have a page with an iframe. Inside that iframe I have a javascript function like this: function putme() {} How can I call this function on the main page? 回答1: window.frames['frameName'].putme(); Do note that this usually only works if the iframe is referring to a page on the same domain. Browsers restrict access to pages within frames that belong to a

Many-to-many relationships in CouchDB or MongoDB

本秂侑毒 提交于 2019-11-30 02:32:26
问题 I have an MSSQL database which I am considering porting to CouchDB or MongoDB. I have a many-to-many relationship within the SQL db which has hundreds of thousands rows in the xref table, corresponding to tens of thousands of rows in the tables on each side of the relationship. Will CouchDB and/or MongoDB be able to handle this data, and what would be the best way of formatting the relevant documents for performant querying? Thanks very much. 回答1: For CouchDB, I would highly recommend reading

has_many :through multiple has_one relationships?

懵懂的女人 提交于 2019-11-30 02:25:45
I'm writing a mentorship program for our church in rails (im still farily new to rails).. And i need to model this.. contact has_one :father, :class_name => "Contact" has_one :mother, :class_name => "Contact" has_many :children, :class_name => "Contact" has_many :siblings, :through <Mother and Father>, :source => :children So basically an objects "siblings" needs to map all the children from both the father and mother not including the object itself.. Is this possible? Thanks Daniel It's funny how questions that appear simple can have complex answers. In this case, implementing the reflexive