many-to-many

Many to many relationship for same type entity

懵懂的女人 提交于 2019-12-24 00:16:42
问题 I have an entity as below. I am curious if it is possible to create a relationship as I will be describing with the example: I am creating 2 Person entities Michael and Julia . I am adding Julia to Michael's friends set. After that I am retrieving Michael as a JSON response and Julia is available in the response. But when I am retrieving Julia, her friends set is empty. I want to create the bidirectional friendship relation by saving just one side of the friendship. I would like to get

How should the following many to many relationship be modeled in MongoDB?

这一生的挚爱 提交于 2019-12-24 00:16:40
问题 Suppose I have Student and Teacher in a many to many relationship. If I just want to find out all the teachers for a given student or vice versa I generally model it by using embedded Object Ids. For example if teacher has a property studentIds which is an array of student Object Ids then that is enough information to do all the queries you need. However suppose that a student can give a teacher a rating. How should this rating fit into the model? At the moment I do the following: Inside

Entity Framework - adding the same entity twice in many-to-many relationships

北城余情 提交于 2019-12-24 00:05:00
问题 Ok. So here is the deal. I have two entities - "Product" and "Parts". The product consists of parts. And parts are reusable in other products. The relation between those entities is many-to-many. And it all works great. The problem is that I cannot add the same part to the same product twice. EF seems to force all the related entities to be unique. Consider the following code: var product = context.Create<Product>(); var part = GetSomePart(); Console.WriteLine(product.Parts.Count); // will

How to Access Many to many field in class based views in Django?

本秂侑毒 提交于 2019-12-23 23:02:16
问题 I have two models, Author & Book in models.py class Author(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=40) email = models.EmailField() age = models.IntegerField() def __str__(self): return '%s %s' %(self.first_name, self.last_name) def __unicode__(self): return '%s %s' %(self.first_name, self.last_name) class Book(models.Model): title = models.CharField(max_length=100) #name = title pages = models.IntegerField() price = models

Why can't I override GetHashCode on a many-to-many entity in EF4?

十年热恋 提交于 2019-12-23 21:32:18
问题 I have a many-to-many relationship in my Entity Framework 4 model (which works with a MS SQL Server Express): Patient-PatientDevice-Device. I'm using Poco, so my PatientDevice-class looks like this: public class PatientDevice { protected virtual Int32 Id { get; set; } protected virtual Int32 PatientId { get; set; } public virtual Int32 PhysicalDeviceId { get; set; } public virtual Patient Patient { get; set; } public virtual Device Device { get; set; } //public override int GetHashCode() //{

LEFT JOIN across three tables (with junction table)

依然范特西╮ 提交于 2019-12-23 20:51:26
问题 In Postgres, is there a way to perform a left join between tables linked by a junction table, with some filtering on the linked table? Say, I have two tables, humans and pets , and I want to perform a query where I have the human ID, and the pet name. If the human ID exists, but they don't have a pet with that name, I still want the human's row to be returned. If I had a FK relationship from pets to humans , this would work: select h.*, p.* from humans as h left join pets as p on p.human_id =

Mapping a Many-to-Many relationship with an Attribute in Entity Framework

一个人想着一个人 提交于 2019-12-23 18:35:53
问题 I'm always using Attributes to map the properties of my entities to their corresponding columns. Here's an example: [Table("news_entries")] public class News { [Key] public int Id { get; set; } [Column("d_date")] public DateTime Date { get; set; } [Column("m_text")] public string Text { get; set; } [Column("id_user")] public int UserId { get; set; } [ForeignKey("UserId")] public User User { get; set; } } But I still don't know, how I could map a Many-to-Many relationship, where the table and

Exclusion of rows with many-to-many relationships

旧城冷巷雨未停 提交于 2019-12-23 16:05:19
问题 I have three tables: posts, tags and posts_has_tags (which facilitate the many-to-many relationship between posts and tags). A post can have any number of tags. The 'posts' table has the following columns: idposts text The 'tags' table has these: idtags name As for the 'posts_has_tags' table: posts_idposts tags_idtags What I can't do is come up with a query to select all posts except for those which have a tag (or tags) with a certain value in the 'name' column assigned to them. It seems that

Exclusion of rows with many-to-many relationships

淺唱寂寞╮ 提交于 2019-12-23 16:03:08
问题 I have three tables: posts, tags and posts_has_tags (which facilitate the many-to-many relationship between posts and tags). A post can have any number of tags. The 'posts' table has the following columns: idposts text The 'tags' table has these: idtags name As for the 'posts_has_tags' table: posts_idposts tags_idtags What I can't do is come up with a query to select all posts except for those which have a tag (or tags) with a certain value in the 'name' column assigned to them. It seems that

How to populate a ManyToMany relationship using YAML on Play Framework 2.1.x

情到浓时终转凉″ 提交于 2019-12-23 12:54:40
问题 I have the following ManyToMany (bidirectional) relationship: @Entity public class Proposal extends Model { ... @ManyToMany public List<Tag> tags; } @Entity public class Tag extends Model { ... @ManyToMany(mappedBy="tags") public List<Proposal> taggedProposals; } And I want to populate my DB with some test data using a yaml file (to display later using a simple view). This is part of my yaml file: ... - &prop2 !!models.Proposal id: 2 title: Prop2 title proposer: *user2 - &prop3 !!models