many-to-many

Entity Framework 4.1+ many-to-many relationships change tracking

瘦欲@ 提交于 2019-11-26 21:42:33
How can I detect changes of ICollection<> properties (many-to-many relationships)? public class Company { ... public virtual ICollection<Employee> Employees { get; set; } } using (DataContext context = new DataContext(Properties.Settings.Default.ConnectionString)) { Company company = context.Companies.First(); company.Employees.Add(context.Employees.First()); context.SaveChanges(); } public class DataContext : DbContext { public override int SaveChanges() { return base.SaveChanges(); // Company's entity state is "Unchanged" in this.ChangeTracker } } Here is how to find all the changed many-to

has_many :through nested_form that can build multiple instances

家住魔仙堡 提交于 2019-11-26 21:26:12
问题 I have the following code in my models: Class Farm < ActiveRecord::Base has_many :farm_products, :dependent => :destroy has_many :products, :through => :farm_products accepts_nested_attributes_for :farm_products end class Product < ActiveRecord::Base has_many :farm_products, :dependent => :destroy has_many :farms, :through => :farm_products end class FarmProduct < ActiveRecord::Base belongs_to :farm belongs_to :product end I have a form to create a new Farm, and I want to create farm_products

Difference Between One-to-Many, Many-to-One and Many-to-Many?

◇◆丶佛笑我妖孽 提交于 2019-11-26 21:09:56
Ok so this is probably a trivial question but I'm having trouble visualizing and understanding the differences and when to use each. I'm also a little unclear as to how concepts like uni-directional and bi-directional mappings affect the one-to-many/many-to-many relationships. I'm using Hibernate right now so any explanation that's ORM related will be helpful. As an example let's say I have the following set-up: public class Person{ private Long personId; private Set<Skill> skills; //Getters and setters } public class Skill{ private Long skillId; private String skillName; //Getters and setters

Many to Many Relationships with Ember, ember-data and Rails

。_饼干妹妹 提交于 2019-11-26 21:04:56
问题 I am having an issue with trying to save many to many relationships in Ember.js using ember-data and rails. The association works fine on the ember side of things, however when I try to commit the transaction it will not include the list of new associations when submitting to rails. Any help would be much appreciated, I've been tearing out my hair trying to find an example application that does something this simple on github but I can't seem to find one. Here is a dumbed down version of my

SQL: Many-To-Many table AND query

拥有回忆 提交于 2019-11-26 20:43:22
问题 First - apologies for the fuzzy title, I could not find a better one. I have table with the following structure (simplification): EmpID DeptID 1 1 1 2 2 1 3 2 4 5 5 2 This table represents a many-to-many relationship. I'm interested in finding all the EmpIDs that are related to a specific group of DeptIDs, for example I want all the EmpIDs that are related to DeptIDs 1, 2 and 3. Please note it's an AND relationship and not an OR relationship. For my case, the EmpID may be related to

Self-referencing many-to-many recursive relationship code first Entity Framework

此生再无相见时 提交于 2019-11-26 20:16:02
I can't seem to make this work at all class Member { public virtual IList<Member> Friends { get; set; } [Key] public int MemberId { get; set; } public string Name{ get; set; } } I tried adding Mappings but in vain. Is there a way to do so with CTP5? By convention, Code First will take uni-directional associations as one to many. Therefore you need to use fluent API to let Code First know that you want to have a many to many self referencing association: protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Member>().HasMany(m => m.Friends).WithMany(); } Note:

How to sort NULL values last using Eloquent in Laravel

蹲街弑〆低调 提交于 2019-11-26 20:11:23
问题 I've got a many to many relationship between my employees and groups table. I've created the pivot table, and all is working correctly with that. However, I've got a sortOrder column on my employees table that I use to determine the order in which they display. Employee with a value of 1 in the sortOrder column should be first, value of 2 should be second, so on. (Or backwards if sorted descending) The sortOrder column is a integer column that allows null values. I've set up my group model to

Querying ManyToMany relationship with Hibernate Criteria

走远了吗. 提交于 2019-11-26 20:02:54
问题 I'm not sure how to describe this problem, so I think an example is the best way to ask my question: I have two tables with a manyToMany relationship: DriversLicence <-> LicenceClass LicenceClass is things like "Car", "Motorbike", and "Medium Rigid". Using Hibernate Criteria, how can I find all licences that have both "Car" and "Motorbike" LicenceClasses? UPDATE 12/11/2008 I have discovered that this can easily be achieved by using a custom ResultTransformer. However the problem is that a

Django Many-to-Many (m2m) Relation to same model

纵然是瞬间 提交于 2019-11-26 19:56:49
问题 I'd like to create a many-to-many relationship from and to a user class object. I have something like this: class MyUser(models.Model): ... blocked_users = models.ManyToManyField(MyUser, blank=True, null=True) The question is if I can use the class reference inside itself. Or do I have to use "self" insead of "MyUser" in the ManyToManyField ? Or is there another (and better) way to do it? 回答1: Technically, I'm pretty sure "MyUser" or "self" will work, as long as it's a string in either case.

Django's ManyToMany Relationship with Additional Fields

梦想的初衷 提交于 2019-11-26 19:22:12
问题 I want to store some additional information in that, automatically created, ManyToMany join-table. How would I do that in Django? In my case I have two tables: "Employees" and "Projects". What I want to store is how much each of the employees receives per hour of work in each of the projects, since those values are not the same. So, how would I do that? What occurred to me was to, instead of the method "ManyToManyField", create explicitly a third class/table to store those new informations