many-to-many

Many-to-Many with three tables relating with each other (SqlAlchemy)

爷,独闯天下 提交于 2019-12-06 11:32:43
I've three tables User, Device and Role. I have created a many-to-many relation b/w User and Device like this; #Many-to-Many relation between User and Devices userDevices = db.Table("user_devices", db.Column("id", db.Integer, primary_key=True), db.Column("user_id", db.Integer, db.ForeignKey("user.id")), db.Column("device_id", db.Integer, db.ForeignKey("device.id")))) class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(60), index=True, unique=True) devices = db.relationship("Device", secondary=userDevices, backref=db.backref(

Django: removing item from many-to-many relation more efficiently

不羁岁月 提交于 2019-12-06 11:09:13
问题 My book class uses a many-to-many field to save its readers. If I want to remove a reader from some books, I can use a loop to go through all book objects to remove the reader. But it's too slow. Is it possible to do it in a bulk operation? class Book(models.Model): readers = models.ManyToManyField(User, related_name='books') #Remove reader 'foo' from book 1, 2, 3, 4, 5. However, it is slow. for book in Book.objects.filter(id__in=[1, 2, 3, 4, 5]) book.readers.remove(R) 回答1: Yes. You can

Symfony 1.4 doctrine - many-to-many relationship with extra field in intermediate table

爱⌒轻易说出口 提交于 2019-12-06 11:02:18
There are 3 tables: shelf, section and shelf_has_section intermediate table to support n-m relation. The schema build from symfony doctrine:build-schema looks as following. Simply, shelf(id, position) section(id, name) shelf_has_section(shelf_id, section_id, number_of_books) The schema. Shelf: connection: doctrine tableName: shelf columns: id: type: integer(4) fixed: false unsigned: true primary: true autoincrement: true position: type: string(255) primary: false notnull: true autoincrement: false relations: ShelfHasSection: local: id foreign: shelf_id type: many Section: connection: doctrine

How to add or remove a many-to-many relationship in Entity Framework?

别等时光非礼了梦想. 提交于 2019-12-06 09:02:41
There's a many-to-many UserFeed table that stands between User and Feed and denotes a twitter-like follow relationship. It only has two fields, which form a composite key: UserID and FeedID . I need to write a method that will subscribe or unsubscribe a user from a feed based on a boolean flag. public void SetSubscriptionFlag (int userId, int storeId, bool subscribe) { } I'm new to Entity Framework so I'm trying to find and follow an "EF-ish" way to accomplish this. My initial thoughts are: Instead of working with the middle UserFeed class, I should create a many-to-many Subscriptions property

Entity Framework Code First Left Join

断了今生、忘了曾经 提交于 2019-12-06 08:52:43
问题 I've created a simple DB in EF code first but appear to have hit a problem. What I would like to do is, query the DBContext to retrieve a custom object CheckedTag that would have all of the available tags and a boolean field of checked. Code First abstracts the Many-To-Many table and I can't seem to find the correct query. I've tried var qry = from t in Db.Tags from a in Db.Articles where(a.Id == articleId) select new CheckedTag { Id = t.Id, Name = t.Name, PermanentUrl = t.PermanentUrl,

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

有些话、适合烂在心里 提交于 2019-12-06 08:34:18
问题 I am struggling with mappings for the following sql tables |Post | |PostRelation | |------------------| |-----------------| |PostId |1--------*|ParentPostId | |---other stuff--- |1--------*|ChildPostId | | | |RelationType | Ideally Id like a property on post called relatedPosts as Dictionary <RelationType,IList<Post>> But at the minute Id just settle for a property on post with an IList<PostRelation>. I successfully used a many to many to get related posts, but this method loses the addtional

populate a many-to-many table with access

孤街醉人 提交于 2019-12-06 07:16:45
问题 I have two tables ( persons and projects ) which are in a many-to-many table, thus linked together by a third table persons_projects In ms access I now created a form showing data from the projects table. What I want is to have a subform showing all persons - datasets which participate in this project. In this subform it should also be possible to add (or delete) persons from this project—a drop-down seems the best choice here. How can I do this? I’m able to show all participants, but I’m not

How to save models with many-to-many relationship in Ember.js?

梦想的初衷 提交于 2019-12-06 07:12:07
I'm stuck with this problem for so long that I think that I'm missing something obvious. Here's simplified model of my case: There is Patient that has all meds that he/she takes. And there is Medicine that has all patients who takes it. // Patient model Yo.Patient = DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), meds: DS.hasMany('medicine') }); // Medicine model Yo.Medicine = DS.Model.extend({ title: DS.attr('string'), patients: DS.hasMany('patient') }); I've read official manual and many resources. The last one and closest to my case was this Toptal tutorial .

Many to Many SQL Query for selecting all Images Tagged with certain words

泪湿孤枕 提交于 2019-12-06 06:49:53
问题 I have 2 Tables in Postgres: CREATE TABLE "images" ( "id" serial NOT NULL PRIMARY KEY, "title" varchar(300) NOT NULL, "relative_url" varchar(500) NOT NULL) and CREATE TABLE "tags" ( "id" serial NOT NULL PRIMARY KEY, "name" varchar(50) NOT NULL) To establish many to many relationship between images and tags I have another table as: CREATE TABLE "tags_image_relations" ( "id" serial NOT NULL PRIMARY KEY, "tag_id" integer NOT NULL REFERENCES "tags" ("id") DEFERRABLE INITIALLY DEFERRED, "image_id"

ManyToMany on itself with AssociationTable with EmbeddedId - Spring-Data-Jpa

ε祈祈猫儿з 提交于 2019-12-06 06:40:30
I have some trouble with Hibernate during a ManyToMany association :/ I want to have a user with his contacts. The association Table is used to have a creation_date of the association and her status (ex. Active, inactive, etc...) Hibernate version : 5.2.17 Spring boot : 2.0.5 My class USER : @Entity(name = "user") public class User implements Serializable { @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable(name = "assoc_user_user", joinColumns = {@JoinColumn(name = "id.myself.id")}, inverseJoinColumns = {@JoinColumn(name = "id.contact.id")}) private List<AssocUserUser>