many-to-many

Django: accessing ManyToManyField objects after the save [Solved]

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

django many to many validation when add()

Hi i have a Category model with parent/child self relation For primary category and sub categories : class Place(models.Model): name = models.CharField(_("name"), max_length=100) categories = models.ManyToManyField("Category", verbose_name=_("categories")) class Category(models.Model): name = models.CharField(_("name"), ma...

Advanced many2many query for MYSQL

I im trying to build a imagegallery where people have access to different groups and the groups decide what catalogues and images they are allowed to see. I though many2many structure would be best for this. So far, ive manage to build the database like this: image (image_name, image_file, image_id) catalog (catalog_id, catalog_nam...

EntityFramework - LINQ Join help

Hello, I have following schema: Clients - ClientId Users - UserId Offices - OfficeId ClientOffices - ClientId, OfficeId UserOffices - UserId, OfficeId Bold entities are EntityFramework Entities. Now I need to write a function which accepts UserId and returns a list of Clients - who also belong to the offices to which user belongs. ...

Fluent NHibernate Self Referencing Many To Many

I have an entity called Books that can have a list of more books called RelatedBooks. The abbreviated Book entity looks something likes this: public class Book { public virtual long Id { get; private set; } public virtual IList<Book> RelatedBooks { get; set; } } Here is what the mapping looks like for this relationship ...

Zend_db junction table join query

Hi guys, Not sure why I can't figure this one out. Basically, I have two tables with a many-to-many relationship so I have a junction table inbetween them. For an example, consider the following database schema: Restaurant (id, restaurant_name, suburb) RestaurantCuisine (restaurant_id, cuisine_id) Cuisine (id, cuisine_name) So, ma...

Data modeling of interdependent hierarchies

I'm trying to make a sales report based on the following: DColor IdColor ColorPalette ColorName 21 Vibrant Blue 22 Nature Brown 23 Vibrant Red 24 Nature Black 25 Vibrant Yellow ... ... ... DFurniture IdFurniture FurnitureType FurnitureName 43 ...

MySQL Many-To-Many Query Problem

Hello! Here's my problem. I have a many-to-many table called 'user_has_personalities'. In my application, users can have many personalities, and a personality can belong to many users. The table has two integer columns, user_id and personality_id. What I need to do is get all users that have at least all of the personalities (a set of...

ANSI SQL - Delete all entries in a MxN relation with non-null FK constraints

I have two entities A and B that are related in a MxN relation through an intermediary table, thus making a total of three tables. My relation table R has non-nullable FK constraints on the other two tables. I want to delete all entries from tables A and B and R where A obeys some constraint (I can supply the ids in A table for instance...

How to distuingish between Django's automatically created ManyToMany through-models and manually defined ones?

Hi. Say we have models from django.db import models class AutomaticModel(models.Model): others = models.ManyToManyField('OtherModel') class ManualModel(models.Model): others = models.ManyToManyField('OtherModel', through='ThroughModel') class OtherModel(models.Model): pass class ThroughModel(models.Model): pblm = mo...

Select users with a certain role in Kohana's auth module

In the auth module, we have users and roles with a many to many relationship. My question probably has a simple answer, but I couldn't find it by myself... How would I go about selecting only users having a certain role using ORM? What I'd like to do is something like this: ORM::factory('user')->with('roles')->where('role','member')->f...

Fluent nhibernate mapping problem: many to many self join with additional data

I am struggling with mappings for the following sql tables |Post | |PostRelation | |------------------| |-----------------| |PostId |1--------*|ParentPostId | |---other stuff--- |1--------*|ChildPostId | | | |RelationType | Ideally Id l...

How do you insert or update many to many tables in .net entity framework

This seems like it should be quite obvious but something about the entity framework is confusing me and I cannot get this to work. Quite simply, I have three tables where the Id values are identity columns: Users (userId, username) Categories (categoryId, categoryName) JoinTable (UserId, CategoryId) composite. In the entities designe...

Hibernate many-to-many delete.

Hello, I have many-to-many relationship in NHibernate between two classes Actor and Movie. public ActionResult removeMovieFromActor(int MovieId, int ActorId) { ViewData["SectionTitle"] = "Usunięcie filmu"; ActorsRepository ar = new ActorsRepository(); Actor act = ar.getActor(ActorId); //what to ...

Relation many-to-many with attributes : how ?

Hi, Excuse me for my poor english in advance as it is not my mother tongue. Like in this example: http://www.xylax.net/hibernate/manytomany.html But i have in the table foo-bar 2 attributes which are not part of the primary or foreign keys.: one boolean(A) & one string(B). I know how to map it without attributes but not in this case. ...

nHibernate Many-to-Many query using Criteria API

Hello, Before asking I have looked at all relevant posts on this topic I have also read this blog post: http://ayende.com/Blog/archive/2007/12/23/NHiberante-Querying-Many-To-Many-associations-using-the-Criteria-API.aspx I have Teams and I have Members, there is many-to-many relationship between them Basically: Member -> MemberTeam <-...

Compound/Composite primary/unique key with Django

How to create models and tables with Compound/Composite primary/unique key with Django? ...

Fluent NHibernate HasManyToMany IDictionary

I have three tables: Employee, EmployeesCustomer, and Customer. Employee has a primary key called Id. Customer has a primary key called Id. EmployeesCustomer has a composite key made up of two fields, EmployeeId and CustomerId. The EmployeesCustomer does NOT contain any other fields. My goal is to create an IDictionary on the Employee...

How to access the joining model on a has_many :through relationship

I have a typical many-to-many relationship using has_many => :through, as detailed below. class member has_many member_roles has_many roles, :through => :member_roles end class role has_many member_roles has_man members, :through => :member_roles end class member_role belongs_to :member belongs_to :role # has following f...

NHibernate: Adding an entity to a lazy loaded many-to-many relationship

We have a entity with a many-to-many collection mapped as a lazy loaded bag. When we load up the entity, the collection is not loaded - great. Now we want to add a new entity to that collection. As soon as we do this, the collection is loaded up. How do we add the new entity without loading up the whole collection (the collection is lar...