many-to-many

Many-to-Many-to-Many relationship with need for another specific model

不打扰是莪最后的温柔 提交于 2019-12-20 06:41:20
问题 I have a many-to-many relationship between Supermarket , Product and Brand through the Supply - and Origin -models. I also want to store which specific Product-Brand-Combination I have in my supermarket. I thought of another model (I called it Specific_Combination where I would store :supermarket_id , :product_id and :brand_id . class Supermarket < ActiveRecord::Base has_many :supplies has_many :products, :through => :supplies end class Supply < ActiveRecord::Base belongs_to :product belongs

How do you set the initial value for a ManyToMany field in django?

独自空忆成欢 提交于 2019-12-20 04:56:18
问题 I am using a ModelForm to create a form, and I have gotten the initial values set for every field in the form except for the one that is a ManyToMany field. I understand that I need to give it a list, but I can't get it to work. My code in my view right now is: userProfile = request.user.get_profile() employer = userProfile.employer bar_memberships = userProfile.barmembership.all() profileForm = ProfileForm( initial = {'employer': employer, 'barmembership' : bar_memberships}) But that doesn't

Asserting for presence of added objects in Django ManyToMany relation

倖福魔咒の 提交于 2019-12-20 04:32:45
问题 I have the following model; class Station(models.Model): name = models.CharField(max_length=50) address = models.TextField(default='') owner = models.ForeignKey(User,default='') members = models.ManyToManyField(User, related_name='members') Now after the following code; user1 = User.objects.create_user(username="username1", password="password1") user1.save() user2 = User.objects.create_user(username="username2", password="password2") user2.save() user3 = User.objects.create_user(username=

Hibernate batch delete on many-to-many table

耗尽温柔 提交于 2019-12-20 04:24:05
问题 yet another many-to-many Hibernate questions. I have the simplest possible many-to-many mapping as follows: @Entity public class Strategy implements Serializable { @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "STRATEGY_TO_GROUP", joinColumns = {@JoinColumn(name="STRATEGY_ID")}, inverseJoinColumns = {@JoinColumn(name = "STRATEGY_GROUP_ID")}) private Set<StrategyGroup> groups; ... } And the opposite side of the relation as follows: @Entity public class StrategyGroup implements

JPA and many-to-many relations in google app engine

与世无争的帅哥 提交于 2019-12-20 03:03:33
问题 I have entities A and B, and A can have set of B. The same instance of B can belong to several A. So there is classical many-to-many relation here. In GAE there is no direct support of many-to-many relations, instead they're offering an ability to use sets of keys for related relations. So in A I will maintain set of keys of records in B. Now the problem is - how can I query for objects of type B belonging to given object of type A and matching certain criteria? In plain SQL I would do that

How to configure nHibernate for many-many mapping?

社会主义新天地 提交于 2019-12-20 02:58:08
问题 Using nHibernate 3.2, C# 4.0, SQL Server 2008 R2 Express I have two business entities - Broker and Market . They are stored in the brokers and markets tables respectively. I also have brokerMarkets table with one extra column called MinIncrement . There's a many-many relationship between Broker and Market, but only when I want to store a MinIncrement value (i.e. it's optional). My classes look like this: public class Market : BusinessBase { public Market() {} public virtual int Id { get; set;

Flask-Sqlalchemy, Primary key for secondary table in many-to-many relationship

﹥>﹥吖頭↗ 提交于 2019-12-20 02:31:06
问题 I am trying to build simple many-to-many relationship using Flask-Sqlalchemy for Postgresql Database: from app import db from sqlalchemy.dialects.postgresql import UUID authors_books = db.Table( 'authors_books', db.Column('id', UUID(as_uuid=True), primary_key=True), db.Column('author_id', UUID(as_uuid=True), db.ForeignKey('authors.id')), db.Column('book_id', UUID(as_uuid=True), db.ForeignKey('books.id')), ) class Author(db.Model): __tablename__ = 'authors' # Fields id = db.Column(UUID(as_uuid

Minimizing the performance issues of loading a many to many relationship

梦想与她 提交于 2019-12-19 19:41:25
问题 I've been tokenizing an extremely large corpus. Each Unigram can occur in multiple Comments multiple times. I'm storing the Comment.ids in a list that is attached to the Unigram in the database every 250K newly counted unigrams or so. What I'm wondering is if there is a way to extend the comment id list--or a similar data structure--without querying and loading the existing list of comments tied to the Unigram (it can number in the the thousands). Or is there no way around the slow IO? Here

Minimizing the performance issues of loading a many to many relationship

只谈情不闲聊 提交于 2019-12-19 19:41:14
问题 I've been tokenizing an extremely large corpus. Each Unigram can occur in multiple Comments multiple times. I'm storing the Comment.ids in a list that is attached to the Unigram in the database every 250K newly counted unigrams or so. What I'm wondering is if there is a way to extend the comment id list--or a similar data structure--without querying and loading the existing list of comments tied to the Unigram (it can number in the the thousands). Or is there no way around the slow IO? Here

How to delete entity in many-to-many relationship using POCOs

筅森魡賤 提交于 2019-12-19 11:57:32
问题 I'm using POCOs in combination with EF4 and some entities are in many-to-many relationships, in my case objects of class User and objects of class PrivilegeGroup. This is how class User looks like: public class User { public int UserID { set; get; } public string UserName { get; set; } public string UserPassword { get; set; } public bool IsActive { get; set; } public List<PrivilegeGroup> PrivilegeGroups { get; set; } } And this is how class PrivilegeGroup looks like: public class