many-to-many

Is it possible to directly reference a many-to-many table using entity framework, code first

隐身守侯 提交于 2019-12-19 05:11:04
问题 I am using the entity framework and modelling a many-to-many relationship. I have created the relationship between the two entities using the fluent API (let's say users and groups): this.HasMany(t => t.Users) .WithMany(t => t.Groups) .Map( m => { m.ToTable("GroupMembers"); m.MapLeftKey("Group_Id"); m.MapRightKey("User_Id"); }); This works great, but I'd like to also be able to reference the GroupMembers table directly. To do that, I have something like: [Table("GroupMembers")] public class

Why does many-to-many data structure require two additional tables?

孤者浪人 提交于 2019-12-19 04:42:11
问题 This question is based on the thread. If we have one-to-many data structure, we need to have a "help-table" to store for instance phonenumbers for one person. Many person cannot have the same phonenumbers. I look forward for an explanation why we then need two "help-tables" between many-to-many relations. An example of this is a question-site where many users can add the same tags: alt text http://files.getdropbox.com/u/175564/db/db-55.png Why do we need to have the tables Question-Tag-xref

Many-to-many, self-referential, non-symmetrical relationship (twitter model) via Association Object in SqlAlchemy

烈酒焚心 提交于 2019-12-19 03:38:16
问题 How would one best implement a many-to-many, self-referential, non symmetrical relationship (think Twitter) in SqlAlchemy? I want to use an association object (let's call this class "Follow") so that I can have additional attributes associated with the relationship. I've seen plenty of examples which use an association tables, but none like I've describe above. Here's what I have so far: class UserProfile(Base): __tablename__ = 'user' id = Column(Integer, primary_key=True) full_name = Column

self referencing manytomany with hibernate and annotations

有些话、适合烂在心里 提交于 2019-12-19 03:37:08
问题 My brain is starting to hurt thinking about this, is it as simple as : @ManyToMany(mappedBy = "following", cascade = CascadeType.ALL) private Set<User> followers = new HashSet<User>(); @ManyToMany(mappedBy = "followers", cascade = CascadeType.ALL) private Set<User> following = new HashSet<User>(); 回答1: Something like: @ManyToMany(mappedBy = "following", cascade = CascadeType.ALL) @JoinTable(name="UserRel", joinColumns={@JoinColumn(name="ParentId")}, inverseJoinColumns={@JoinColumn(name=

SQLAlchemy order_by many to many relationship through association proxy

只谈情不闲聊 提交于 2019-12-19 03:14:43
问题 I have a many to many relationship setup in a Flask app in SQLAlchemy using a Association Object. I then have have assocation proxies setup between the the classes, to give more direct access rather than going via the association object. Here is an abbreviated example of the setup: class Person(Model): __tablename__ = 'persons' id = Column(Integer, primary_key=True) last_name = Column(Text, nullable=False) groups = association_proxy('group_memberships', 'group') # Other stuff class Group

Hibernate @ManyToMany joinTable - OrderBy using join table's field

北战南征 提交于 2019-12-19 03:09:55
问题 There are 3 tables: TABLE_A ID_A field1 fieldN TABLE_B ID_B field1 fieldN TABLE_A_B ID_A ID_B orderField public class A(){ @ManyToMany @JoinTable(name="TABLE_A_B", joinColumns={@JoinColumn(name="ID_A")}, inverseJoinColumns={@JoinColumn(name="ID_B")}) @OrderBy(value="orderField") private List<TABLE_B> BList; } But it isn't working, instead I get a runtime error: Caused by: org.postgresql.util.PSQLException: ERROR: column B1_.orderField doesn't exist Position: 1437 Hibernate searches the field

How to filter django model by its objects in many-to-many field (exact match)?

陌路散爱 提交于 2019-12-18 19:01:20
问题 I have this model in my code: class Conversation(models.Model): participants = models.ManyToManyField(User, related_name="message_participants") and I need to filter this "Conversation" model objects by the "participants" many-to-many field. meaning: I have for example 3 User objects, so I want to retrieve the only "Conversation" objects that has this 3 Users in it's "participants" field. I tried doing this: def get_exist_conv_or_none(sender,recipients): conv = Conversation.objects.filter

Save Many-to-Many in Spring MVC

我只是一个虾纸丫 提交于 2019-12-18 18:03:52
问题 I got relation many to many between Restaurant and Tag. Here are my entities: public class Restaurant { @Id @GeneratedValue private int id; (...) @ManyToMany @JoinTable(name="restaurant_tag", joinColumns={@JoinColumn(name="restaurant_id")}, inverseJoinColumns={@JoinColumn(name="tag_id")}) private List<Tag> tags; And: public class Tag { @Id private int id; private String name; @ManyToMany @JoinTable(name="restaurant_tag", joinColumns={@JoinColumn(name="tag_id")}, inverseJoinColumns={

Save Many-to-Many in Spring MVC

房东的猫 提交于 2019-12-18 18:01:14
问题 I got relation many to many between Restaurant and Tag. Here are my entities: public class Restaurant { @Id @GeneratedValue private int id; (...) @ManyToMany @JoinTable(name="restaurant_tag", joinColumns={@JoinColumn(name="restaurant_id")}, inverseJoinColumns={@JoinColumn(name="tag_id")}) private List<Tag> tags; And: public class Tag { @Id private int id; private String name; @ManyToMany @JoinTable(name="restaurant_tag", joinColumns={@JoinColumn(name="tag_id")}, inverseJoinColumns={

Automapper - Bestpractice of mapping a many-to-many association into a flat object

早过忘川 提交于 2019-12-18 17:04:12
问题 I have two entities: Employee and Team . What I want is an EmployeeForm that has the Name of the Team . How can I achieve this using AutoMapper ? My current "solution" is the following: Mapper.CreateMap<Employee, EmployeeForm>() .ForMember(dest => dest.TeamName, opt => opt.MapFrom(x => x.GetTeams().FirstOrDefault() != null ? string.Join(", ", x.GetTeams().Select(y=>y.Name)) : "n/a")); In my opinion this is bad readable. What I would like to have is a generic method where I can pass an entity,