many-to-many

MappedBy in bi-directional @ManyToMany : what is the reason

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 02:39:12
问题 What is the reason for setting MappedBy in bidirectional many-to-many relationships? When one table has significant amount of records, while other has a few, which side is better to put mappedBy? 回答1: It's actually a good question, and it helps to understand the concept of an "owning" entity. If you want to prevent both sides (in a bidirectional relationship) from having join tables , a good idea, then you need to have a mappedBy= element on one side. Whether or not there is a join table is

Generation query when the ManyToMany relationship is used by Spring Data Jpa project

China☆狼群 提交于 2019-12-06 02:26:45
问题 I've the following entities mapping: @Entity @Table(name = "books") public class Book implements Serializable { @ManyToMany @JoinTable(name="books2categories", joinColumns=@JoinColumn(name="book_id"), inverseJoinColumns=@JoinColumn(name="category_id")) Collection<Category> categories; ... @Entity @Table(name = "categories") public class Category implements Serializable { @ManyToMany(mappedBy="categories") private Collection<Book> books; BookRepository interface is looked: public interface

Code First Entity Framework Many-to-Many relationships

Deadly 提交于 2019-12-06 02:05:18
Can someone point out where I've got wrong!! I have created 2 simple classes, with many-to-many relationship. Works fine, all the tables are populated correctly. Except when I try and retrive any Students courses nothing is returned... public partial class Student { public Student() { Courses = new HashSet<Course>(); } public int StudentID { get; set; } [StringLength(50)] [Required] public string FirstName { get; set;} [StringLength(50)] [Required] public string LastName {get; set;} public DateTime? Enroled {get;set;} public ICollection<Course> Courses { get; set; } } public class Course {

EF5 Many To Many update disconnected scenario

爱⌒轻易说出口 提交于 2019-12-06 01:26:23
I didn't find yet a good solution to this problem (similar ticket here EF5 update disconnected graph (n-tier) one-to-many ). I found and followed this example: http://entityframeworktutorial.net/update-many-to-many-entities-in-entity-framework.aspx#.UTBeTDBhif8 . This works just fine, but it creates a duplicate of the related entities (with sql profiler I saw the Insert into RelatedEntities .. I would expected just an insert / update on the MyEntities_Related join table and I don't understand why EF makes an insert on the RelatedEntities table :( And here is my code: public void AddOrUpdate

Django - using Many-to-Many horizontal interface outside of admin

ⅰ亾dé卋堺 提交于 2019-12-06 01:05:13
I'm working in a form with a m2m field. I want that this field looks like the horizontal interface of the django admin site... ¿how i can do it? thanks... You need to use the FilteredSelectMultiple widget from django.contrib.admin.widgets import FilteredSelectMultiple from django import forms from .models import Person class PersonForm(forms.ModelForm): some_field = forms.ModelMultipleChoiceField(Person.objects.all(), widget=FilteredSelectMultiple("Person", False, attrs={'rows':'2'})) class Meta: model = Person You will also need to include the Javascript and CSS used in the admin. Here's an

Cascade on delete using unidirectional Many-To-Many mapping

非 Y 不嫁゛ 提交于 2019-12-06 00:23:57
I am using Fluent and NHibernate. I have two objects say A & B which has a many-to-many relationship between them. I am using a unidirectional many-to-many mapping when A HasMany B's. There is no reference in B about A (Unidirectional). This creates a third table (named ABMapping) in the Database which has the two columns relating to primary keys of A & B. If I delete the object A, the entries from the ABMapping table related to A are deleted. That's cool. But, now I am not able to delete an object B, as it has a FK constraint. How can I set it up so that on deleting B, all entries related to

Many to Many relationship using SQL and Linq (entity framework/to entities)

╄→гoц情女王★ 提交于 2019-12-06 00:03:23
I have two tables: - Attendees - Events Normally, I would create a mapping table ' EventAttendeeMap ' to link these tables into a many to many relationship. Is this the best way of doing so? Should I store the list of AttendeeId s in an xml column instead on the Events table? I am using .NET 3.5/4 with Linq as the DAL (although I think this is irrelevant to the design question being asked, possibly). Interested to see what people's opinions are. Thanks. Dave A mapping table is definitely the best way to do it - the Entity Framework will convert the mapping table into a collection of entities

Django query for many-to-many subset containment

て烟熏妆下的殇ゞ 提交于 2019-12-05 23:17:38
问题 Is there a way to query for subset or superset containment with many-to-many fields? Suppose each Person has a list of birds they want to see, and each Aviary houses a list of birds. How can I make a query to find, for a given Person instance, which Aviaries have every bird on the person's list? And similarly, for a given Person instance, how do I find which Aviaries have only birds on the person's list (but not necessarily all of them). Here are my Django 1.5 models: class Bird(models.Model)

MVC 4 Edit Controller/ View Many to Many relation and checkboxes

家住魔仙堡 提交于 2019-12-05 22:39:42
I'm working with ASP.NET MVC 4 and Entity Framework and I was searching for some way to make many to many relation and checkboxes from my db for a Create/Edit controller and view, I have found the answer with @Slauma answer for Create in MVC 4 - Many-to-Many relation and checkboxes but, I'd really like to see how this extends to Edit and Delete functionality as well like some other partners in this solution. Could someone please show how I would populate the ClassificationSelectViewModel in the Edit controller method to get both the "checked" and "unchecked" values? this is a Matt Flowers

Django admin: ManyToManyField in list_editable?

不羁的心 提交于 2019-12-05 21:07:08
In the Django admin, I would really like to be able to display an editable ManyToManyField in the list display. It doesn't necessarily need to be the full ManyToManyField control - being able to save just one value would be good enough for the purposes of the list display (though the underlying values are many-to-many in nature). My model looks like this: class Item(models.Model): name = models.CharField(max_length=500) colour = models.ManyToManyField(Colour, related_name='primary_colour') If I try this in admin.py : class ItemAdmin(admin.ModelAdmin): list_display = ('name', 'colour') list