many-to-many

Rails 5 - Object Relation Impedence and how to structure multiple inherited classes/tables

只愿长相守 提交于 2019-12-01 16:14:11
问题 EDIT I have edited this from the original to make it easier to understand. I understand the Object Relationship Impedance problem. I understand Rails STI and Polymorphism (the Rails way and that it's not true OO Polymorphism). I've read a TON of blogs and questions on this, and still cannot find the answer to this problem. class Person < ApplicationRecord (ie what was ActiveRecord::Base) end class Employee < Person end class Customer < Person end ... multiple other types of Person Now lets

django adding a ManyToMany field/table to existing schema, related_name error

独自空忆成欢 提交于 2019-12-01 15:16:20
问题 I have an existing project with models (Users and Books). I would like to add a ManyToMany(M2M) field to the existing model Books, but the syncbb command does not do this. Details: Books already has a FK field that maps to User, and I want to add a new M2M field (readers) that also maps to User. As you know, Django's syncdb only cares about tables, so adding a normal field is easy, but a M2M requires a new join table (app_books_user), so shouldn't syncdb cmd add this like any other new table?

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

只愿长相守 提交于 2019-12-01 14:45: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 PrivilegeGroup { public int PrivilegeGroupID { get; set; } public string Name { get; set; } public List<User> Users

Django Combining AND and OR Queries with ManyToMany Field

社会主义新天地 提交于 2019-12-01 14:37:59
hoping someone can help me out with this. I'm trying to figure out whether I can construct a query that will allow me to retrieve items from my db based on a ForeignKey field and a ManyToManyField at the same time. The challenging part is that it will need to filter on multiple ManyToMany objects. An example will hopefully make this clearer. Here are my (simplified) models: class Item(models.Model): name = models.CharField(max_length=200) brand = models.ForeignKey(User, related_name='brand') tags = models.ManyToManyField(Tag, blank=True, null=True) def __unicode__(self): return self.name class

Core data: Managing employee contracts in a many-to-many relationship?

不打扰是莪最后的温柔 提交于 2019-12-01 14:04:00
I am mapping an idea for a relationship using Core Data. I have an Employer entity who has a many-to-many relationship with Employees . Basically, an employee can work for multiple employers, and an employer can have multiple employees. The problem I'm facing is, I'm not sure how to manage the contracts between employees and employers. As an employee can work for either 1 or many employers, they would naturally have a contract for each employer they work for (complete with salary, duration) and a list of dates when they are working for a specific employer. My question is - how to manage the

Get all entries from Table B which have a relation to multiple entries (given list) from Table A

旧街凉风 提交于 2019-12-01 13:49:16
I have two tables. Table A and Table B . Both are connected with a many-to-many relationship. Table A: ID --- 1 2 Table B: ID --- 3 4 Table AB: ID | A_ID | B_ID ---------------- 5 | 1 | 4 6 | 1 | 3 7 | 2 | 3 I want to get the list of ID s from table B which have a relation to a list of ID s of table A . Example from the above tables: I want to get all B s which have a relation to table A ID 1 and ID 2. I get then ID 3 has to both ID s of table A . How could I do this with an SQL query ? If you are looking to select based on a list of As (not ALL As), then do it like this: SELECT b_id FROM ab

How to config Many-to-many with condition, in Sqlalchemy

删除回忆录丶 提交于 2019-12-01 12:40:34
I'm use sqlalchemy 0.6.4. I have 2 classes: Question and Tag, they are many-to-many. class Question(Base): __tablename__ = "questions" id = Column(Integer, primary_key=True) deleted = Column(Boolean) ... tags = relationship('Tag', secondary=r_questions_tags) class Tag(Base): __tablename__ = "tags" id = Column(BigInteger, primary_key=True) questions = relationship('Question', secondary=r_questions_tags) So, tag.questions will get all the questions belong to a tag. But now, since the Question has a deleted column, I hope to do like this: class Tag(Base): ... # get non-deleted questions questions

Django Combining AND and OR Queries with ManyToMany Field

荒凉一梦 提交于 2019-12-01 12:33:09
问题 hoping someone can help me out with this. I'm trying to figure out whether I can construct a query that will allow me to retrieve items from my db based on a ForeignKey field and a ManyToManyField at the same time. The challenging part is that it will need to filter on multiple ManyToMany objects. An example will hopefully make this clearer. Here are my (simplified) models: class Item(models.Model): name = models.CharField(max_length=200) brand = models.ForeignKey(User, related_name='brand')

basic many-to-many sql select query

好久不见. 提交于 2019-12-01 12:21:55
问题 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 GID I'm using MS Access, FWIW. Also, this is for a low-bandwidth situation, so code optimization isn't as important as simplicity/readability. I'm using php as a

How to config Many-to-many with condition, in Sqlalchemy

匆匆过客 提交于 2019-12-01 11:54:37
问题 I'm use sqlalchemy 0.6.4. I have 2 classes: Question and Tag, they are many-to-many. class Question(Base): __tablename__ = "questions" id = Column(Integer, primary_key=True) deleted = Column(Boolean) ... tags = relationship('Tag', secondary=r_questions_tags) class Tag(Base): __tablename__ = "tags" id = Column(BigInteger, primary_key=True) questions = relationship('Question', secondary=r_questions_tags) So, tag.questions will get all the questions belong to a tag. But now, since the Question