many-to-many

MVC 4 - Many-to-Many relation and checkboxes

吃可爱长大的小学妹 提交于 2019-11-27 14:28:58
I'm working with ASP.NET MVC 4 and Entity Framework. In my database, I have a table Subscription which represents a subscription to public transports. This subscription can provide access to several public transport companies (so a subscription could have 1, 2, 3, ... companies) then it is a Many-to-Many relation between these tables (I have an intermediate table between them). I want to allow the creation of a subscription throught a page which will contain a field Amount of the subscription and the available companies by checkboxes. Every checkbox represents an existing company (a company

SQL JOIN many-to-many

余生长醉 提交于 2019-11-27 13:46:27
问题 Sorry about the minimalistic title but I don't know how to describe it in short. I have three tables: The table of groups ID | Genre ----------------- 1 | Action 2 | Adventure 3 | Drama Many to many table GroupID | ElementID ----------------- 3 | 1 1 | 2 2 | 2 2 | 3 3 | 3 And the table of elements ID | Element ----------------- 1 | Pride and Prejudice 2 | Alice in Wonderland 3 | Curious Incident Of A Dog In The Night Time All is fine and very simple. The SELECT I am trying to achieve is the

MS SQL creating many-to-many relation with a junction table

允我心安 提交于 2019-11-27 11:34:36
问题 I'm using Microsoft SQL Server Management Studio and while creating a junction table should I create an ID column for the junction table, if so should I also make it the primary key and identity column? Or just keep 2 columns for the tables I'm joining in the many-to-many relation? For example if this would be the many-to many tables: MOVIE Movie_ID Name etc... CATEGORY Category_ID Name etc... Should I make the junction table: MOVIE_CATEGORY_JUNCTION Movie_ID Category_ID Movie_Category

getting the value of an extra pivot table column laravel

旧街凉风 提交于 2019-11-27 11:26:06
I have a phone_models, phone_problems, and a phone_model_phone_problem pivot table. The pivot table has an extra column 'price'. PhoneModel: class PhoneModel extends \Eloquent { public function problems() { return $this->belongsToMany('RL\Phones\Entities\PhoneProblem')->withPivot('price'); } } PhoneProblem: class PhoneProblem extends \Eloquent { public function models() { return $this->belongsToMany('PhoneModel')->withPivot('price'); } } What I'm trying to do is get the price of a specific phone with a specific problem. This is how I have it now but I feel like Laravel has a built in Eloquent

Doctrine's Many-To-Many Self-Referencing and reciprocity

半城伤御伤魂 提交于 2019-11-27 11:17:20
问题 By default, self-referencing ManyToMany relationships under Doctrine involve an owning side and an inverse side, as explained in the documentation. Is there a way to implement a reciprocal association whithout difference between both sides? Following the example in the docs: <?php /** @Entity **/ class User { // ... /** * @ManyToMany(targetEntity="User") **/ private $friends; public function __construct() { $this->friends = new \Doctrine\Common\Collections\ArrayCollection(); } // ... } So,

LINQ to entities - Building where clauses to test collections within a many to many relationship

三世轮回 提交于 2019-11-27 11:09:14
So, I am using the Linq entity framework. I have 2 entities: Content and Tag . They are in a many-to-many relationship with one another. Content can have many Tags and Tag can have many Contents . So I am trying to write a query to select all contents where any tags names are equal to blah The entities both have a collection of the other entity as a property(but no IDs). This is where I am struggling. I do have a custom expression for Contains (so, whoever may help me, you can assume that I can do a "contains" for a collection). I got this expression from: http://forums.microsoft.com/MSDN

Mysql join query for multiple “tags” (many-to-many relationship) that matches ALL tags?

匆匆过客 提交于 2019-11-27 11:09:12
I am trying to query for Objects that match ALL of a given set of Tags. Basically I want users to be able to add on more and more Tags to filter or "narrow down" their search results, kind of like newegg.com does. My table structure is a table of Objects, a table of Tags, and a MANY:MANY relation table ObjectsTags. So I have a JOIN query like so: SELECT * FROM Objects LEFT OUTER JOIN ObjectsTags ON (Objects.id=ObjectsTags.object_id) LEFT OUTER JOIN Tags ON (Tags.id=ObjectsTags.tag_id) I tried using an IN clause/condition, like this: SELECT * FROM Objects LEFT OUTER JOIN ObjectsTags ON (Objects

How to properly index a linking table for many-to-many connection in MySQL?

谁说我不能喝 提交于 2019-11-27 11:08:48
问题 Lets say I have a simple many-to-many table between tables "table1" and "table2" that consists from two int fields: "table1-id" and "table2-id". How should I index this linking table? I used to just make a composite primary index (table1-id,table2-id), but I read that this index might not work if you change order of the fields in the query. So what's the optimal solution then - make independent indexes for each field without a primary index? Thanks. 回答1: It depends on how you search. If you

Django removing object from ManyToMany relationship

被刻印的时光 ゝ 提交于 2019-11-27 10:03:33
问题 How would I delete an object from a Many-to-Many relationship without removing the actual object? Example: I have the models Moods and Interest . Mood has a many-to-many field interests (which is a models.ManyToManyField(Interest) ). I create an instance of Moods called my_mood . In my_moods 's interests field I have my_interest , meaning >>> my_mood.interests.all() [my_interest, ...] How do I remove my_interest from my_mood without deleting either model instance? In other words, how do I

Many to many relationship mapping in EF Core

旧巷老猫 提交于 2019-11-27 09:37:41
I have a problem with many to many relationship in EF core. I have the following model classes: public class Meal { public int Id { get; set; } [Required] public int Insulin { get; set; } public MealType Type { get; set; } public ICollection<MealFood> MealFoods { get; set; } public Meal() { MealFoods = new Collection<MealFood>(); } } public class Food { public int Id { get; set; } [StringLength(255)] public string Name { get; set; } [Required] public int Carbohydrates { get; set; } public ICollection<MealFood> MealFoods { get; set; } public Food() { MealFoods = new Collection<MealFood>(); } }