many-to-many

Should junction tables have more than one primary keys from another indentifying table?

扶醉桌前 提交于 2019-12-01 11:20:38
Here's an exmaple: Originally I have 3 tables. Table B references Table A. So now Table B has two primary keys. One used as the original primary key and the other one to enforce its relationship with Tabe A. Then I want Table B to have a many-to-many relationship with Table X. As I'm adding the relationship, MySQL Workbench added Table Y with both of Table B primary keys and one primary key in Table X. So Table Y now has three primary keys. It seems like the second primary key from Table B in the junction table is unnecessary since I can identify Table B with the original primary key. So do I

Dynamic finders with Grails many-to-many relationship

ⅰ亾dé卋堺 提交于 2019-12-01 11:02:03
I have 2 domain classes which are mapped by many-to-many relationship. I followed the instruction of Grails documentation, but I still have some problem when processing data on those domains. Here are my 2 domain classes: class User { String name int age String job static hasMany = [groups : Group] static belongsTo = [org : Organization] } class Group { String groupName String code static hasMany = [members : User] } My problems are: 1. The above relationship require one class hold belongsTo to be the "owner" of the relationship. In this context, the User belongs to the Group, but I do not

Django Tastypie, ManyToMany Saving Error

大憨熊 提交于 2019-12-01 10:15:51
问题 i got a problem when i'm saving an item, via tastypie api. (POST method) Here is my api.py code. from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS from tastypie.authorization import DjangoAuthorization from tastypie.authentication import BasicAuthentication from tastypie import fields from apps.clients.models import Client from django.contrib.auth.models import User class ClientAPI(ModelResource): users = fields.ToManyField('apps.clients.api.ClientUserAPI', 'users',related

JPA ManyToMany in case of users and groups?

主宰稳场 提交于 2019-12-01 10:09:48
问题 Same question here, but it didn't help me I've got three tables and many to many connections. In my JSF-application I am trying to add users. In my groups-table there is three different groups: admin, customer and user. What I have done: After inserting data to jsf-form user clicks save. ManagedBean called usersController fetches the group (customer-group) from groupsController usersController ManagedBean creates the new user and save it to the mySQL-db. PROBLEM is that groups_has_user-table

Updating extra attributes in a has_many, :through relationship using Rails

纵然是瞬间 提交于 2019-12-01 09:28:06
问题 I've managed to set up a many-to-many relationship between the following models Characters Skills PlayerSkills PlayerSkills, right now, has an attribute that Skills don't normally have: a level. The models look something like this (edited for conciseness): class PlayerSkill < ActiveRecord::Base belongs_to :character belongs_to :skill end class Skill < ActiveRecord::Base has_many :player_skills has_many :characters, :through => :player_skills attr_accessible :name, :description end class

@ManyToMany relation not save

老子叫甜甜 提交于 2019-12-01 08:27:10
I have some entities with @ManyToMany relation: @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name = "buses_drivers", joinColumns = @JoinColumn (name = "driver_id_inner", referencedColumnName = "driver_id"), inverseJoinColumns = @JoinColumn (name = "bus_id_inner", referencedColumnName = "bus_id")) private List<Bus> buses; and @ManyToMany(mappedBy = "buses", fetch = FetchType.EAGER, cascade = CascadeType.ALL) private List<Driver> drivers; When execute saving Driver model with some Bus models, all ok. Tables buses_drivers store all keys those entities. But when

Should junction tables have more than one primary keys from another indentifying table?

痞子三分冷 提交于 2019-12-01 08:16:09
问题 Here's an exmaple: Originally I have 3 tables. Table B references Table A. So now Table B has two primary keys. One used as the original primary key and the other one to enforce its relationship with Tabe A. Then I want Table B to have a many-to-many relationship with Table X. As I'm adding the relationship, MySQL Workbench added Table Y with both of Table B primary keys and one primary key in Table X. So Table Y now has three primary keys. It seems like the second primary key from Table B in

How to eagerly load a many to many relationship with the entity framework code first?

对着背影说爱祢 提交于 2019-12-01 07:04:40
I'll give the most basic example that I can think of for the purpose of clarity. Lets say that I have two entities of the following form: public class Student { public int Id {get;set} public string FullName {get;set;} public virtual ICollection<Course> Courses {get;set;} } public class Courses { public int Id {get;set;} public string FullName {get;set;} public virtual ICollection<Student> Students {get;set;} } Those two entities map to three tables, the third one being a table for the joins. When I query the Students like this var allStudents = context.Students; and then traverse the results

Select custom columns from Laravel belongsToMany relation

我只是一个虾纸丫 提交于 2019-12-01 06:52:44
Im trying to select only specific attributes on the many-to-many relation users , just like in one-to-one. But using select() on belongsToMany() seem to be ignored and i'm still getting all the User attributes. class Computer extends Eloquent { public function users() { return $this->belongsToMany("User")->select("email"); } public function admin() { return $this->hasOne("User")->select("email"); } } Computer::with("users")->get(); Is there a way of filtering only specified columns from related entity with belongsToMany() ? Mark Yes, you actually can . Computer::with("users")->get(array(

Hibernate Bidirectional ManyToMany delete issue

让人想犯罪 __ 提交于 2019-12-01 06:47:17
In my project I have entities for users and companies: @Entity @Table(name = "users") public class UserDetails { @Id @GeneratedValue @Column(name = "user_id") private int id; @Column(name = "first_name") @NotEmpty @Size(min = 2, max = 20) private String firstName; @ManyToMany(cascade = CascadeType.REFRESH) @JoinTable(name = "users_companies", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "company_id")) private Set<CompanyDetails> userCompanies = new HashSet(); //getters and setters of course... } @Entity @Table(name = "companies") public class