many-to-many

SQLAlchemy ManyToMany secondary table with additional fields

做~自己de王妃 提交于 2019-11-27 06:16:24
I have 3 tables: User, Community, community_members (for relationship many2many of users and community). I create this tables using Flask-SQLAlchemy: community_members = db.Table('community_members', db.Column('user_id', db.Integer, db.ForeignKey('user.id')), db.Column('community_id', db.Integer, db.ForeignKey('community.id')), ) class Community(db.Model): __tablename__ = 'community' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100), nullable=False, unique=True) members = db.relationship(User, secondary=community_members, backref=db.backref('community_members', lazy=

Fluent Nhibernate Many-to-Many mapping with extra column

本秂侑毒 提交于 2019-11-27 05:37:15
问题 I want to map sth like this using fluent Nhibernate but I am not sure how to map the inventory table This is the tables I have : Product (Id,Name, ...) Warehouse(Id, Name, ...) Inventory(Product_id, Warehouse_id, StockInHand) I have map the Product and Warehouse like below Public ProductMap() { Id(x => x.Id); Map(x => x.Name); HasManyToMany(x => x.StoresStockedIn) .Cascade.All() .Inverse() .Table("Inventory"); } public WarehouseMap() { Id(x => x.Id); Map(x => x.Name); HasManyToMany(x => x

fluent nhibernate - many-to-many relationship mapping on same entity

巧了我就是萌 提交于 2019-11-27 05:36:56
问题 I am having a problem trying to map out a many-to-many relationship , where both sides of the relationship reference the same entity. I am using Fluent NHibernate and NH3.1. Basically, the scenario is this - I have a category, which can have multiple parents. Thus, a category has multiple other categories as parents, as well as multiple other categories as its children. HasManyToMany(x => x.ParentCategories).AsBag().Table("parentcategorychildren").ParentKeyColumn("ChildID").ChildKeyColumn(

How to delete many-to-many relationship in Entity Framework without loading all of the data

末鹿安然 提交于 2019-11-27 05:26:12
问题 Does anyone know how to delete many-to-many relationship in ADO.NET Entity Framework without having to load all of the data? In my case I have an entity Topic that has a property Subscriptions and I need to remove a single subscription. The code myTopic.Subscriptions.Remove(...) works but I need to load all subscriptions first (e.g. myTopic.Subscriptions.Load() ) and I don't want to do that because there are lots (and I mean lots) of subscriptions. 回答1: You can Attach() a subscription then

How to use Rails 4 strong parameters with has_many :through association?

若如初见. 提交于 2019-11-27 05:24:11
问题 I'm having trouble getting a has_many :through association working with Rails 4's strong parameters. I have a model called Checkout and I need to select a person from the Employee model in the new checkout form. Checkouts and Employees are associated through an Employment model. I'm getting this error when I try to create a new checkout: NoMethodError in CheckoutsController#create undefined method `employee' for #<Checkout:0x007ff4f8d07f88> It seems that there's something wrong with either my

How do I access the properties of a many-to-many “through” table from a django template?

我的梦境 提交于 2019-11-27 05:04:32
问题 From the Django documentation... When you're only dealing with simple many-to-many relationships such as mixing and matching pizzas and toppings, a standard ManyToManyField is all you need. However, sometimes you may need to associate data with the relationship between two models. For example, consider the case of an application tracking the musical groups which musicians belong to. There is a many-to-many relationship between a person and the groups of which they are a member, so you could

Filtering on many-to-many relations that fulfill a set of criteria

和自甴很熟 提交于 2019-11-27 04:52:33
问题 With the following models: class OrderOperation(models.Model): ordered_articles = models.ManyToManyField(Article, through='orders.OrderedArticle') class OrderedArticle(models.Model): order_operation = models.ForeignKey(OrderOperation) article = models.ForeignKey(Article) articles = ... # some queryset containing multiple articles If I want to find order operations containing at least one article, this works as expected: OrderOperation.objects.filter(ordered_articles__in=articles) However, if

Entity Framework Code First: how to map multiple self-referencing many-to-many relationships

蹲街弑〆低调 提交于 2019-11-27 04:45:51
问题 I have created an entity type that has multiple collection properties that reference items of the same type. In other words, it reflects a single database table in which the rows are arbitrarily grouped, such that a row may appear in multiple groups. In the following simplified example, the Person class has Brothers and Sisters collection properties that also reference Person entities: public class Person { public Person() { Brothers = new Collection<Person>(); Sisters = new Collection<Person

How to organise a many to many relationship in MongoDB

不想你离开。 提交于 2019-11-27 03:27:24
I have two tables/collections; Users and Groups. A user can be a member of any number of groups and a user can also be an owner of any number of groups. In a relational database I'd probably have a third table called UserGroups with a UserID column, a GroupID column and an IsOwner column. I'm using MongoDB and I'm sure there is a different approach for this kind of relationship in a document database. Should I embed the list of groups and groups-as-owner inside the Users table as two arrays of ObjectIDs? Should I also store the list of members and owners in the Groups table as two arrays,

Removing many to many reference in Mongoose

一个人想着一个人 提交于 2019-11-27 02:48:02
问题 One of my mongoose schemas is a many to many relationship: var UserSchema = new Schema({ name : String, groups : [ {type : mongoose.Schema.ObjectId, ref : 'Group'} ] }); var GroupSchema = new Schema({ name : String, users : [ {type : mongoose.Schema.ObjectId, ref : 'User'} ] }); If I remove a group, is there anyway to remove that group objectId from all the user's 'groups' array? GroupSchema.pre('remove', function(next){ //Remove group._id from all the users }) 回答1: You're on the right track