many-to-many

Entity Framework Many to Many works but Include does not

五迷三道 提交于 2019-12-14 03:47:37
问题 I have a typical many-to-many relationship with these 3 tables [Post] ( [PostId] int, (PK) [Content] nvarchar(max) ... ) [Tag] ( [TagId] int, (PK) [Name] nvarchar ... ) [TagPost] ( [TagId] int, (PK, FK) [PostId] int (PK, FK) ) And, TagId and PostId are the PK and FK set on the tables accordingly etc. Then I have these classes and mapping in c# public class Post { public Post() { this.Tags = new HashSet<Tag>(); } [Key] public int PostId { get; set; } ... public virtual ICollection<Tag> Tags {

Many-to-Many with three tables relating with each other (SqlAlchemy)

北城以北 提交于 2019-12-14 03:44:58
问题 I've three tables User, Device and Role. I have created a many-to-many relation b/w User and Device like this; #Many-to-Many relation between User and Devices userDevices = db.Table("user_devices", db.Column("id", db.Integer, primary_key=True), db.Column("user_id", db.Integer, db.ForeignKey("user.id")), db.Column("device_id", db.Integer, db.ForeignKey("device.id")))) class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(60),

Prepopulate tabularinline with value from related lookup in manytomany field

前提是你 提交于 2019-12-14 03:10:39
问题 I have question to ask. I want to have my change_form to prepopulate the tabularinline from intances' value of related looks up (use manytomany field). So when I search kode_prod in change_form in class Order , I could get its instance and prepopulate all in my tabularinline (class Foo ). here is my model class Product(models.Model): product_name= models.CharField(max_length=50) price = models.DecimalField(max_digits=10, decimal_places=2, default=Decimal('0.00')) tax_per_item = models

How to map a ManyToMany reflexive relations ship with extra coloumn in JPA

会有一股神秘感。 提交于 2019-12-14 03:08:48
问题 I'm trying to map a USER/FRIEND relation ships using JPA over Hibernate. The ralation ship have an extra coloumn friendShipStatus that describe if the requested frien has accepted on not the friendship request. This is the data base model that i want to get by the mapping. User ===== Id Name etc... UserFriend =========== UserId ( foreign key --> user_id) FriendId ( foreign key --> user_id) userFriendStatus FriendShipRequestDate I also need an exemple of code using this relationShips. 回答1:

JPA ManyToMany persist

主宰稳场 提交于 2019-12-14 03:07:20
问题 I have a NOTIFICATION table who contains one ManyToMany association : @Entity @Table(name="NOTIFICATION") @NamedQuery(name="Notification.findAll", query="SELECT f FROM Notification f") public class Notification { /** SOME COLUMN DEFINITION NOT IMPORTANT FOR MY CASE COD, DATE, ID_THEME, ID_TYP, IC_ARCH, ID_CLIENT, INFOS, NAME, TITRE_NOT, ID_NOT **/ @ManyToMany @JoinTable( name="PJ_PAR_NOTIF" , joinColumns={ @JoinColumn(name="ID_NOTIF") } , inverseJoinColumns={ @JoinColumn(name="ID_PJ_GEN") } )

Polymorphic many-to-many relation

折月煮酒 提交于 2019-12-14 02:58:22
问题 I couldn't get related models in many-to-many polymorphic relation saved into database. $photo = Photo::find(1); $photo->articles()->attach(2); something like this wouldn't work and gives error: Call to undefined method Illuminate\Database\Query\Builder::articles()' How to do it the right way? Models class Tag extends Eloquent { public function articles() { return $this->morphedByMany('Article', 'taggable'); } public function photos() { return $this->morphedByMany('Photo', 'taggable'); } }

Entity framework 7 (core) RC2 many-to-many relationship with itself and query

混江龙づ霸主 提交于 2019-12-14 02:56:47
问题 Is it possible to create an entity Socket with many-to-many relationship for itself? The typical PostTag example I am familiar from the EF Core documentation. However, I'm not quite sure how to create this kind of relationship with only one entity and one intermediate table SocketSocket . Here's example: modelBuilder.Entity<SocketSocket>() .HasKey(ss => new { ss.SocketToId, ss.SocketFromId}); modelBuilder.Entity<SocketSocket>() .HasOne(ss => ss.SocketTo) .WithMany(s => s.ConnectedToSockets)

Many-to-many relationship select and order by

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-14 02:46:57
问题 I have a many-to-many relationship between two tables: person and favorites. I have three columns: person_id int(8) favorites_id int(8) is_main_favorite enum('y','n') as: person_id | favorite_id | is_main_favorite 2 | 1 | 'y' 2 | 2 | 'n' 3 | 1 | 'n' 3 | 2 | 'n' 1 | 1 | 'y' 1 | 2 | 'y' I'm using PHP and MySQL. How I can retrieve person_id that have ( favorite_id 1 and 2 together) and order the result by person id that have more is_main_favorite ='y' , so the result should be as: person_id 1

Django: Filter a model with multiple parameters for a single ManyToManyField

爷,独闯天下 提交于 2019-12-14 02:41:25
问题 I have following models. class Contents (models.Model): ... tags = models.ManyToManyField('Tag') class Tag (models.Model): ... name = models.CharField(max_length=20) Just to consider, I am trying to get contents which are tagged with both tag1 and tag2 . Is there a way in Django to do something like Contents.objects.filter(tags__name = ['tag1','tag2']) Here tag1,tag2,... are dynamically generated. Update: I have been using for loop . I am looking for an efficient solution. 回答1: If you're

How To Query Many-to-Many Table (one table's values becomes column headers)

独自空忆成欢 提交于 2019-12-14 02:16:19
问题 Given this table structure, I want to flatten out the many-to-many relationships and make the values in the Name field of one table into column headers and the quantities from the same table into column values. The current idea which will work is to put the values into a Dictionary (hashtable) and represent this data in code but im wondering if there is a SQL way to do this. I am also using Linq-to-SQL for data access so a Linq-to-SQL solution would be ideal. [TableA] (int Id) [TableB] (int