many-to-many

Fluent NHibernate: Mapping HasManyToMany by convention

江枫思渺然 提交于 2020-01-02 10:15:46
问题 I'm using Fluent NHibernate's AutoMap feature to map my entities. Most of my entities inherit from a base class Entity which has a property public IList<Tag> Tags . The tags are in a separate table in the database, so I use a many-to-many relation. But Fluent NHibernate creates mappings for a one-to-many relation. I'd like to write a convention to override these mappings to use HasManyToMany(...) if the class inherits from Entity . Is this possible and how? The convention could either rely on

Laravel - Many-to-Many polymorphic relationships

﹥>﹥吖頭↗ 提交于 2020-01-02 08:48:48
问题 I'm banging my head against a polymorphic relationship definition within Laravel 5.7 Here's the data situation: I have a model for Users, a model for Products and a model for Merchandising I basically want to build a WishList for my user, that can contain both Merchandises and Products, and I want to have a polymorphic relationship there because I will have to add new types of things to sell at a later time. In my (simplified) current data schema, I have users -email -id products -id -name

Django select objects with empty ManyToManyField

痞子三分冷 提交于 2020-01-02 05:58:01
问题 Considering the following models, knowing a family, how do I select Kids with no buyers? class Family... class Kid(models.Model): name = models.CharField(max_length=255) family = models.ForeignKey(Family) buyer = models.ManyToManyField(Buyer, blank=True, null=True) family = get_object_or_404(Family, pk=1) for_sale = family.kid_set.filter(buyer... this screws my child trade business 回答1: family.kid_set.filter(buyer__isnull=True) should work. 回答2: @piquadrat's answer is correct. You can also do

Django select objects with empty ManyToManyField

人走茶凉 提交于 2020-01-02 05:57:09
问题 Considering the following models, knowing a family, how do I select Kids with no buyers? class Family... class Kid(models.Model): name = models.CharField(max_length=255) family = models.ForeignKey(Family) buyer = models.ManyToManyField(Buyer, blank=True, null=True) family = get_object_or_404(Family, pk=1) for_sale = family.kid_set.filter(buyer... this screws my child trade business 回答1: family.kid_set.filter(buyer__isnull=True) should work. 回答2: @piquadrat's answer is correct. You can also do

Queryset from a ManyToMany relation

此生再无相见时 提交于 2020-01-01 19:22:09
问题 I'm creating a little calendar app in Django. I have two model classes; Calendar and Event. An event can be in multiple calendars. Because of this I'm using a ManyToMany relation. This is my model from django.db import models class Calendar(models.Model): title = models.CharField(max_length = 255) def __unicode__(self): return self.title class Event(models.Model): title = models.CharField(max_length = 255) start_date = models.DateField() end_date = models.DateField(blank = True, null = True)

How do you create a model with categories that has subcategories (using Rails)?

老子叫甜甜 提交于 2020-01-01 19:14:32
问题 I am creating a blog through Rails. I am relating the posts and categories models through a many-to-many relationship. How do I incorporate subcategories in this model? 回答1: Hierarchy The best way is to use one of the hierarchy gems, typically Ancestry or Closure_Tree to create a "tree" type structure for your categories . You'll then be able to associate blogs with each category, creating the hierarchy functionality you need. We've achieved this before - using the Ancestry gem: Categories As

EF Core 2.0 migration - Many-to-Many with additional fields

别等时光非礼了梦想. 提交于 2020-01-01 17:13:31
问题 I'm using EF Core 2.0 and created a many-to-many relationship with a join entity. When I add a new migration EF always creates an additional Index/Id-field which is completely stupid. Here is my join entity: public class Team_Member { public int TeamId { get; set; } public Team Team { get; set; } public int MemberId { get; set; } public Member Member { get; set; } public MemberTypeEnum MemberType { get; set; } } This is the configuration of the join table (following several examples on the

EF Code first related entities context fail

China☆狼群 提交于 2020-01-01 16:49:29
问题 Dunno how to name this properly. I have two entities in m:n relationship: Member and Role. public class Role { public int Id { get; set; } public string Title { get; set; } public ICollection<Member> MembersInRole { get; set; } } public class Member { public int Id { get; set; } public string Name { get; set; } public string Password { get; set; } public string Email { get; set; } public ICollection<Role> Roles { get; set; } } I have made some seed data: http://i56.tinypic.com/2vjvj1w.png And

Creating many-to-many relationships on a nested rails form

旧街凉风 提交于 2020-01-01 14:07:13
问题 I am trying to create Groups, Users and Memberships (the many-to-many relationships) simultaneously. People can add users to the group as they create it and then I want it to route through to a view of the group with all the members. I can get the users to be created and the current user's membership to save to the database. However I'm struggling to get the id for the freshly created User objects in order to save the new memberships. Group.rb class Group < ActiveRecord::Base has_many

Primary key violation on adding of relationship from many to many linked tables in MVC 3 entity framework

匆匆过客 提交于 2020-01-01 09:44:25
问题 I've read through scores of questions on here that seem at first to have a similar problem but just don't seem quite the same. Massive apologies if this is answered somewhere but like I say I've read through loads and can't find an answer. I'm using Entity Framework and MVC 3. I'm trying to add tags to products in my entity framework, which have a many to many relationship and a table linking them with simply the two keys in the link table, so EF condenses the Tags into a property of Product.