many-to-many

Many-to-many relationship with duplicate entries

拈花ヽ惹草 提交于 2019-12-02 01:49:16
问题 I'm trying to build a many to many relationship using the entity framework and fluent API, but I'm stuck trying to allow duplicate entries. Here is what I have: public class Pizza { public int PizzaId { get; set; } public virtual ICollection<Topping> Toppings { get; set; } } public class Topping { public int ToppingId { get; set; } } Any pizza should be able to have multiple toppings. Any topping can be applied to multiple pizzas. So in OnModelCreating() I call: modelBuilder.Entity<Pizza>()

Rails 3 many to many query condition

空扰寡人 提交于 2019-12-02 01:42:56
I'm trying to do a simple Post/Tags relation in rails 3. Everything working fine except when I want to query the Posts which are related to several tags. Basically I'd like to do this kind of thing : Post.joins(:tags).where('tags.name ILIKE ?', var) But instead of having just one var, I'd like to use an array. I tried : Post.joins(:tags).where('tags.name IN (?)', names_array) But unfortunately it does a simple LIKE (not ILIKE) and works like a OR condition which sounds perfectly logical. I also found another solution by using find_by_sql in this post http://snippets.dzone.com/posts/show/32 But

Many-to-many relationship with duplicate entries

☆樱花仙子☆ 提交于 2019-12-02 00:35:07
I'm trying to build a many to many relationship using the entity framework and fluent API, but I'm stuck trying to allow duplicate entries. Here is what I have: public class Pizza { public int PizzaId { get; set; } public virtual ICollection<Topping> Toppings { get; set; } } public class Topping { public int ToppingId { get; set; } } Any pizza should be able to have multiple toppings. Any topping can be applied to multiple pizzas. So in OnModelCreating() I call: modelBuilder.Entity<Pizza>() .HasMany(p => p.Toppings) .WithMany() .Map(m => m.ToTable("ToppingsForPizza")); That give me a nice many

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

半腔热情 提交于 2019-12-01 22:17:35
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=True), primary_key=True) first_name = db.Column(db.String) last_name = db.Column(db.String) #

Correct way to remove a many-to-many relationship via linq to sql?

≡放荡痞女 提交于 2019-12-01 21:31:24
Let's say we have two tables with a many-to-many relationship: public class Left{ /**/ } public class Right{ /**/ } public class LeftRight{ /**/ } is the following sufficient to unhook these records (ignore the possibility of more than one relationship or no relationship defined)? public void Unhook(Left left, Right right){ var relation = from x in Left.LeftRights where x.Right == right; left.LeftRrights.Remove(relation.First()); Db.SubmitChanges(); } Or do I have to do it on both parts? What's required here? Here is a 'little' extension method I wrote to simplify this problem: public static

Hibernate: many-to-many relationship table as entity

此生再无相见时 提交于 2019-12-01 20:50:25
问题 The question is in title: How can I make many-to-many relationship table as entity? 回答1: I would say, that your question is very reasonable. Take a look at this doc part: Chapter 24. Best Practices. An Extract: Do not use exotic association mappings: Practical test cases for real many-to-many associations are rare. Most of the time you need additional information stored in the "link table". In this case, it is much better to use two one-to-many associations to an intermediate link class. In

Many-to-Many Relationship (with properties) in Google App Engine for Java

倾然丶 夕夏残阳落幕 提交于 2019-12-01 20:16:36
问题 I understand from the official documentation on unowned relationships that the app must use sets of Key objects on either side of the relationship. This makes perfect sense. Coming from many years of RDBM-style programming, though, I'm pretty confused about how I can model properties of that relationship itself. For example, if I have entities Category and Entry in my many-to-many relationship and would like to persist a dateAdded property, or some other data that are only relevant when both

T-SQL - How to write query to get records that match ALL records in a many to many join

本秂侑毒 提交于 2019-12-01 19:47:33
(I don't think I have titled this question correctly - but I don't know how to describe it) Here is what I am trying to do: Let's say I have a Person table that has a PersonID field. And let's say that a Person can belong to many Groups. So there is a Group table with a GroupID field and a GroupMembership table that is a many-to-many join between the two tables and the GroupMembership table has a PersonID field and a GroupID field. So far, it is a simple many to many join. Given a list of GroupIDs I would like to be able to write a query that returns all of the people that are in ALL of those

Minimizing the performance issues of loading a many to many relationship

こ雲淡風輕ζ 提交于 2019-12-01 17:27:30
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 is my model code: comments = db.Table('ngrams', db.Column('unigram_id', db.String, db.ForeignKey(

Duplicate values in GROUP_CONCAT when using two many-to-many [duplicate]

∥☆過路亽.° 提交于 2019-12-01 16:55:28
问题 This question already has an answer here : MySQL Group_Concat Repeating Values (1 answer) Closed 5 years ago . I'm trying to get in a string two many-to-many associations. In this example, each team has an undetermined number of colours and an undetermined number won awards. This is the schema: And this is the query I'm using: SELECT teams.name AS name, GROUP_CONCAT(colours.name) AS colours, GROUP_CONCAT(awards.name) AS awards FROM teams -- join colours INNER JOIN teams_to_colours ON teams.id