many-to-many

how to make a composite primary key (java persistence annotation)

痴心易碎 提交于 2019-11-26 09:39:49
问题 How to make it so that the table user_roles defines the two columns (userID, roleID) as a composite primary key. should be easy, just can\'t remember/find. In user entity: @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = \"user_roles\") public List<RoleDAO> getRoles() { return roles; } @Id @GeneratedValue(strategy = GenerationType.AUTO) public Integer getUserID() { return userID; } In roles entity: @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = \"user_roles\") public List<UserDAO>

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

不想你离开。 提交于 2019-11-26 08:01:14
问题 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(); //

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

爷,独闯天下 提交于 2019-11-26 07:33:09
问题 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? 回答1: 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

Rails find_or_create_by more than one attribute?

混江龙づ霸主 提交于 2019-11-26 06:55:40
问题 There is a handy dynamic attribute in active-record called find_or_create_by: Model.find_or_create_by_<attribute>(:<attribute> => \"\") But what if I need to find_or_create by more than one attribute? Say I have a model to handle a M:M relationship between Group and Member called GroupMember. I could have many instances where member_id = 4, but I don\'t ever want more than once instance where member_id = 4 and group_id = 7. I\'m trying to figure out if it\'s possible to do something like this

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

吃可爱长大的小学妹 提交于 2019-11-26 06:52:45
问题 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; /

Insert/Update Many to Many Entity Framework . How do I do it?

送分小仙女□ 提交于 2019-11-26 06:07:50
I'm using EF4 and new to it. I have a many to many in my project and cannot seem to work out how to insert or update. I have build a small project just to see how it should be coded. Suppose I have 3 tables Class : ClassID-ClassName Student : StudentID-FirstName-Surname StudentClass : StudentID-ClassID After adding all the relationship and updated the model via model browser I have noticed that StudentClass does not appear, this seems to be default behaviour. Now I need to do both an Insert and Update. How do you do it? Any code samples or link where I can download an example, or can you spare

Insert/Update Many to Many Entity Framework . How do I do it?

早过忘川 提交于 2019-11-26 05:49:25
问题 I\'m using EF4 and new to it. I have a many to many in my project and cannot seem to work out how to insert or update. I have build a small project just to see how it should be coded. Suppose I have 3 tables Class : ClassID-ClassName Student : StudentID-FirstName-Surname StudentClass : StudentID-ClassID After adding all the relationship and updated the model via model browser I have noticed that StudentClass does not appear, this seems to be default behaviour. Now I need to do both an Insert

How do I access the child classes of an object in django without knowing the name of the child class?

两盒软妹~` 提交于 2019-11-26 05:49:16
问题 In Django, when you have a parent class and multiple child classes that inherit from it you would normally access a child through parentclass.childclass1_set or parentclass.childclass2_set, but what if I don\'t know the name of the specific child class I want? Is there a way to get the related objects in the parent->child direction without knowing the child class name? 回答1: ( Update : For Django 1.2 and newer, which can follow select_related queries across reverse OneToOneField relations (and

Saving Many to Many relationship data on MVC Create view

懵懂的女人 提交于 2019-11-26 05:16:36
问题 I have some issues with a Many-to-many relationship saving the results of a create view. I want to do a create page for a new user profile that has a checklist that lets them choose courses (many to many relationship). My view takes the records from the Courses database and shows them all with checkboxes. Once the user posts the data, I want to update my userprofile model, and also the courses many-to-many relationship. That\'s the code that I have missing! I\'m new at MVC and I\'ve been

SQL - many-to-many table primary key

最后都变了- 提交于 2019-11-26 04:59:20
问题 This question comes up after reading a comment in this question: Database Design When you create a many-to-many table, should you create a composite primary key on the two foreign key columns, or create a auto-increment surrogate \"ID\" primary key, and just put indexes on your two FK columns (and maybe a unique constraint)? What are the implications on performance for inserting new records/re-indexing in each case? Basically, this: PartDevice ---------- PartID (PK/FK) DeviceID (PK/FK) vs.