many-to-many

Is it possible to add many-to-many relationship without initialize collection in NHibernate?

Here is my class: public class User { public int Id { get; set; } public string Name { get; set; } public ISet<User> Friends { get; set; } } Here is my mapping: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Test" assembly="test"> <class name="User" table="Users"> ...

Using the entity framework to add existing entities to a collection on a newly created entity.

I am using the Entity framework to create a new order. The order contains a collection of contacts, a many to many relationship. I want to add a reference to an existing contact on the order on creation of the order. Both Order and Contact a Entity Objects. Order order = new Order(); //set details on order Contact contact = new ...

hibernate criteria - querying tables in n:m relationship

I'm trying to build a query with hibernate criteria for the following scenario: Two entities: Indicator and report (each with their own tables, classes etc.) an indicator can be used in zero to many reports a report uses zero to many indicators therefore, I have an intersection table to store the relationship the relationship is define...

Query examples in a many-to-many relationship

Wow, it's hard to find a simple explanation to this topic. A simple many-to-many relationship. Three tables, tableA, tableB and a junction tableA_B. I know how to set up the relationship, with keys and all, but I get a little confused when time comes to perform INSERT, UPDATE and DELETE queries.... Basically, what I am looking for is...

Saving object with ManyToMany relation

I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model): group = models.ForeignKey(Group) class Task(models.Model): group = models.ForeignKey(Group) people = models.ManyToManyField(Person) def save(self, **kwargs): ppl = Person.objects.all().filt...

How to make sure redundant data is deleted in a many-to-many relationship

Hi folks, I'm trying to make sure some data is auto-deleted when there's no more references using cascade deletes. I'll explain with a fake database based on Stack Overflow. I have a Post table. Each post has zero to many Tags. So it should look like: Post <-> PostTags <-> Tags eg. Post 1 has tags 'A', 'B', 'C' Post 2 has...

Problem with Linq2Sql Many-to-Many relationship & Inserting new objects.

Hi folks, i'm trying to do a simple linq 2 sql many-to-many, insert some data, operation. here's the stock Northwind model representing a many to many: Now what i'm trying to do is insert a new order and if the product doesn't exist, then insert that at the same time, within the same transaction. The error i'm getting is: System.Da...

Deleting item from many to many reference table ?

I have two tables "Group" and "Customer" and of course two entities "Group" and "Customer". And i have another table which is referencing both "CustomerGroupMember" table. I use CustomerGroupMember table for many-to-many mapping. Customer.hbm.xml <!--Many to many--> <bag name="CustomerGroups" table="CustomerGroupMember" cascade="a...

basic many-to-many sql select query

I think this should be easy, but it's evading me. I've got a many-to-many relationship between Accounts and Account Groups. An Account can be in zero or more Groups, so I'm using the standard join table. Accounts -------- ID BankName AcctNumber Balance AccountGroups ------------- ID GroupName JoinAccountsGroups ------------------ AID...

Trying to remove a has_and_belongs_to_many relationship in rails

So I just started my first rails project yesterday. I had two many-to-many (has_and_belongs_to_many) relationships in my application. I had one between models games and teams and another between models stats and results. This was all working just fine by creating the join table myself with a migration. I then decided that I did not w...

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

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 ...

Linq To Sql Many-Many Join Table

I am a somewhat experienced Rails developer and I thought I would try out ASP.NET's version of MVC. In doing so I also decided to try Linq->Sql... I am a bit confused about the way Linq->Sql handles joins. A trivial example of my schema is : books: id title categories: id name books_categories: book_id category_id Simply dragging...

Hibernate: Transitive persistance of set of objects in an @ManyToMany relationship

I am trying to map the following: public class Person{ ... @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @JoinTable(name = "person_categories", joinColumns = @JoinColumn(name = "personId"), inverseJoinColumns = @JoinColumn(name = "categoryId")) private Set<Category> categories ... } public class Category ...

How to work with unsaved many-to-many relations in django?

I have a couple of models in django which are connected many-to-many. I want to create instances of these models in memory, present them to the user (via custom method-calls inside the view-templates) and if the user is satisfied, save them to the database. However, if I try to do anything on the model-instances (call rendering methods,...

Django Model API reverse lookup of many to many relationship through intermediary table

I have a Resident and can not seem to get the set of SSA's the resident belongs to. I've tried res.ssa_set.all() .ssas_set.all() and .ssa_resident_set.all(). Can't seem to manage it. What's the syntax for a reverse m2m lookup through another table? EDIT: I'm getting an 'QuerySet as no attribute' error. Erm? class SSA(models.Model): ...

NHibernate ManyToMany and eager loading: strange resultset for SetFetchmode combined with SetResultTransformer and SetMaxResult

I've got a many-to-many relationship which I try to fetch eager: *.CreateCriteria(typeof(Class1)) .SetFetchMode("Class2", FetchMode.Eager) .SetResultTransformer(new DistinctRootEntityResultTransformer()) .SetFirstResult(20) .SetMaxResult(10) .List<Class1>(); I'd like to have rows 20-30 returned, but instead I've got 12-18. Why? Becaus...

Entity framework and many to many queries unusable?

I'm trying EF out and I do a lot of filtering based on many to many relationships. For instance I have persons, locations and a personlocation table to link the two. I also have a role and personrole table. EDIT: Tables: Person (personid, name) Personlocation (personid, locationid) Location (locationid, description) Personrole (per...

Many-to-many relationship with surrogate key in Entity Framework

Entity Framework magically interprets the following table structure as a many-to-many relationship. table foo (int id) table foo_bar (int foo_id, int bar_id) table bar (int id) But if the join table has any additional fields it will instead be interpreted as two one-to-many relationships. I am using a database in which the join table...

retrieving variable from intermed table

I need to retrieve institution name by going through an intermediate table. My view gets all the values except this one or at least it is not displaying in the template. Can someone please help with either revising my view or template statement? http://dpaste.com/122204/ Thank you, May ...

python code for django view

MODEL: class Pathology(models.Model): pathology = models.CharField(max_length=100) class Publication(models.Model): pubtitle = models.TextField() class Pathpubcombo(models.Model): pathology = models.ForeignKey(Pathology) publication = models.ForeignKey(Publication) List of pathology sent to HTML template as drop dow...