many-to-many

sqlalchemy polymorphic many-to-many

拥有回忆 提交于 2019-11-28 06:22:51
问题 I'm looking to have a list of objects belong to a parent class, in the following manner: class A(object): __tablename__ = 'a' id = Column(Integer, primary_key=True) collection = relationship(.....) # contains an ordered list of [B, C, B, B, C, C, C, B, C, C, ...]; class B(object): __tablename__ = 'b' id = Column(Integer, primary_key=True) class C(object): __tablename__ = 'c' id = Column(Integer, primary_key=True) The SQLAlchemy examples folder has a simple many-to-one where, in my example,

Fluent Nhibernate Many-to-Many mapping with extra column

僤鯓⒐⒋嵵緔 提交于 2019-11-28 05:58:59
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.Products) .Cascade.All() .Table("Inventory"); } The problem I face is that how can I map the StockInHand

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

帅比萌擦擦* 提交于 2019-11-28 05:56:30
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("ParentID").Cascade.SaveUpdate(); HasManyToMany(x => x.ChildrenCategories).AsBag().Table(

What is the correct way to define many-to-many relationships in NHibernate to allow deletes but avoiding duplicate records

匆匆过客 提交于 2019-11-28 05:34:36
I've been fighting with an NHibernate set-up for a few days now and just can't figure out the correct way to set out my mapping so it works like I'd expect it to. There's a bit of code to go through before I get to the problems, so apologies in advance for the extra reading. The setup is pretty simple at the moment, with just these tables: Category CategoryId Name Item ItemId Name ItemCategory ItemId CategoryId An item can be in many categories and each category can have many items (simple many-to-many relationship). I have my mapping set out as: <hibernate-mapping xmlns="urn:nhibernate

Entity framework and many to many queries unusable?

寵の児 提交于 2019-11-28 05:29:54
I'm trying EF out and I do a lot of filtering based on many to many relationships. For instance I have persons, locations and a personlocation table to link the two. I also have a role and personrole table. EDIT: Tables: Person (personid, name) Personlocation (personid, locationid) Location (locationid, description) Personrole (personid, roleid) Role (roleid, description) EF will give me persons, roles and location entities. EDIT: Since EF will NOT generate the personlocation and personrole entity types, they cannot be used in the query. How do I create a query to give me all the persons of a

Hibernate many-to-many cascading delete

∥☆過路亽.° 提交于 2019-11-28 05:01:14
I have 3 tables in my database: Students , Courses and Students_Courses Students can have multiple courses and courses can have multiple students. There is a many-to-many relationship between Students and Courses . I have 3 cases for my project and courses added to my Courses table. (a) When I add a user, it gets saved fine, (b) When I add courses for the student, it creates new rows in User_Courses - again, expected behaviour. (c) When I am trying to delete the student, it is deleting the appropriate records in Students and Students_Courses , but it is also deleting Courses records which is

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

◇◆丶佛笑我妖孽 提交于 2019-11-28 04:44:58
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. You can Attach() a subscription then Remove() it - note, we're not using Add() here, just Attach, so effectively we're telling EF that we know the

Doctrine 2: How to handle join tables with extra columns

孤街浪徒 提交于 2019-11-28 04:44:10
How do I setup a join table with extra columns, or a many-to-many association with additional properties, in Doctrine 2? Jasper N. Brouwer First off, let me explain that this does not exist: A join table (also known as a junction table or cross-reference table ) is a table that links 2 (or more) other tables together within the same database by primary key. This means that a join table will only contain foreign keys, there is no place for these extra columns. So when you need extra columns in such a table, it is no longer just a "link" between other tables, but becomes a real table on its own!

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

百般思念 提交于 2019-11-28 04:30:53
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 create action, my checkout parameters or my new checkout form. Here's the create action: def create

SQL how to search a many to many relationship

こ雲淡風輕ζ 提交于 2019-11-28 04:29:34
问题 I have a database with two main tables notes and labels . They have a many-to-many relationship (similar to how stackoverflow.com has questions with labels). What I am wondering is how can I search for a note using multiple labels using SQL? For example if I have a note "test" with three labels "one", "two", and "three" and I have a second note "test2" with labels "one" and "two" what is the SQL query that will find all the notes that are associated with labels "one" and "two"? 回答1: To obtain