many-to-many

Hibernate Many-to-Many, duplicates same record

我与影子孤独终老i 提交于 2019-12-04 05:15:12
问题 I tried Hibernate Mapping Many-to-Many using Annotations with the example given in vaannila. http://www.vaannila.com/hibernate/hibernate-example/hibernate-mapping-many-to-many-using-annotations-1.html Set<Course> courses = new HashSet<Course>(); courses.add(new Course("Maths")); courses.add(new Course("Computer Science")); Student student1 = new Student("Eswar", courses); Student student2 = new Student("Joe", courses); session.save(student1); session.save(student2); This thing works fine. But

Correct way to remove a many-to-many relationship via linq to sql?

丶灬走出姿态 提交于 2019-12-04 04:39:32
问题 Let's say we have two tables with a many-to-many relationship: public class Left{ /**/ } public class Right{ /**/ } public class LeftRight{ /**/ } is the following sufficient to unhook these records (ignore the possibility of more than one relationship or no relationship defined)? public void Unhook(Left left, Right right){ var relation = from x in Left.LeftRights where x.Right == right; left.LeftRrights.Remove(relation.First()); Db.SubmitChanges(); } Or do I have to do it on both parts? What

JPA simple many-to-many with eclipselink

风格不统一 提交于 2019-12-04 03:58:31
问题 I've this ER diagram: That was translated into these classes: User.java @Entity @Table(name = "user") @NamedQueries({ @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u")}) public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "id") private Integer id; @Column(name = "name") private String name; @OneToMany(cascade = CascadeType.ALL, mappedBy =

How to correctly use auto_created attribute in django?

天大地大妈咪最大 提交于 2019-12-04 03:23:26
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_field in self._meta.many_to_many: for m2m_link in getattr(self, m2m_field.get_attname()).all(): getattr(to

Django query for many-to-many subset containment

跟風遠走 提交于 2019-12-04 03:20:30
Is there a way to query for subset or superset containment with many-to-many fields? Suppose each Person has a list of birds they want to see, and each Aviary houses a list of birds. How can I make a query to find, for a given Person instance, which Aviaries have every bird on the person's list? And similarly, for a given Person instance, how do I find which Aviaries have only birds on the person's list (but not necessarily all of them). Here are my Django 1.5 models: class Bird(models.Model): name = models.CharField(max_length=255, unique=True) class Aviary(models.Model): name = models

EntityFramework Mutli-Table Many-to-Many

雨燕双飞 提交于 2019-12-04 02:35:39
问题 I'm working with EF4.1 Code First and am trying to create some Many-to-Many relationship tables where there tables would need to be linked. Please see small snippet of code beloow: class Event { int EventId { get; set; } ICollection<Contact> Contacts { get; set; } } class Contact { int ContactId { get; set; } ICollection<Relation> Relations { get; set; } } class Relation { int RelationId { get; set; } string Name { get; set; } } So the Contacts object can have many different types of

Determine if many-to-many record combination exists

巧了我就是萌 提交于 2019-12-04 02:33:34
问题 This seems like it would be a common task with an easy solution but I've come up empty handed both on StackOverflow and Google. Scenario is this: I have two tables A & B that share a many-to-many relationship. As such I have table A_B with foreign keys which maps the A-to-B record relationships. Standard stuff. All I'm trying to figure out is how to query the tables before I enter a new record (one 'A' record with one or more 'B' records) if a matching, identical relationship already exists.

Yii framework Many to Many relationships

自闭症网瘾萝莉.ら 提交于 2019-12-04 01:13:54
What is the method to save and update Many to Many relationship in Yii framework? There is a better implementation as behavior. http://www.yiiframework.com/forum/index.php?/topic/6905-please-test-my-ar-enhancement-automatically-sync-many-many-table-when-calling-save/ Unless you create a model for the table between the two main tables, your only option is to use DAO (Database Access Object) and specify SQLs with it. Have a look at how blog demo accomplishes this task. user318750 use MANY_MANY relationship type to setup many to many connection between Models (An associative table is needed to

Many-to-many self-referential relationship in sqlalchemy

本秂侑毒 提交于 2019-12-04 00:26:29
I'm trying to make a self-referential many-to-many relationship (it means that Line can have many parent lines and many child lines) in sqlalchemy like this: Base = declarative_base() class Association(Base): __tablename__ = 'association' prev_id = Column(Integer, ForeignKey('line.id'), primary_key=True) next_id = Column(Integer, ForeignKey('line.id'), primary_key=True) class Line(Base): __tablename__ = 'line' id = Column(Integer, primary_key = True) text = Column(Text) condition = Column(Text) action = Column(Text) next_lines = relationship(Association, backref="prev_lines") class Root(Base):

NHibernate many-to-many assocations making both ends as a parent by using a relationship entity in the Domain Model

左心房为你撑大大i 提交于 2019-12-03 22:47:50
Entities: Team <-> TeamEmployee <-> Employee Requirements: A Team and an Employee can exist without its counterpart. In the Team-TeamEmployee relation the Team is responsible (parent) [using later a TeamRepository]. In the Employee-TeamEmployee relation the Employee is responsible (parent) [using later an EmployeeRepository]. Duplicates are not allowed. Deleting a Team deletes all Employees in the Team, if the Employee is not in another Team. Deleting an Employee deletes only a Team, if the Team does not contain no more Employees. Mapping: public class TeamMap : ClassMap<Team> { public TeamMap