many-to-many

Entity Framework: Many to Many Relationship

人盡茶涼 提交于 2019-12-11 17:44:38
问题 I have two tables with a Many-To-Many relationship like this: User( emailaddress , Name) UserAlerts( emailaddress , AlertId ) Alert( AlertId ,Title) Alerts have already been added to the database. When inserting a new user, I am doing a lookup on the AlertRepository . The problem is, Instead of creating a record in the User and the UsertAlerts tables only, its also adding an extra Alert record. I am using the following code: public ActionResult Register(UserModel model, int[] Alerts) User

Insert into junction table with relationship many to many in symfony 4

房东的猫 提交于 2019-12-11 17:24:04
问题 I have a next tables: quiz , question and junction table question_quiz . I have a many-to-many relationship. Insert is working for the tables quiz and questions but I don't understand how insert in junction table. Entity quiz. class Quiz { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=191) */ private $name; /** * @ORM\ManyToMany(targetEntity="App\Entity\Question", mappedBy="quiz", cascade={"persist"}) */ private

Weird ephemeral error for ManyToMany fields during Django migrations

青春壹個敷衍的年華 提交于 2019-12-11 17:14:39
问题 There's this weird error that my company has been facing since the last few months. We have a ton of model s in our code and a lot of them have ManyToMany fields in them. For ex - class TypeMapping(models.Model): name = models.TextField(null=True, blank=True) from_config_type = models.ManyToManyField(Type, blank=True, related_name="from_config_type") to_config_type = models.ManyToManyField(Type, blank=True, related_name="to_config_type") Sometimes, and only sometimes, after a deployment, we

How to implement a form to add a video using M2M model with through_fields?

点点圈 提交于 2019-12-11 16:22:16
问题 I have this model from this question: class Category(models.Model): category = models.CharField(max_length=50) def __str__(self): return self.category class Tag(models.Model): tag = models.CharField(max_length=50) def __str__(self): return self.tag class Video(models.Model): title = models.CharField(max_length=255) categories = models.ManyToManyField(Category, through='Taxonomy', through_fields=('video', 'category')) tags = models.ManyToManyField(Tag, through='Taxonomy', through_fields=(

With database table design, Is there an advantage of using special naming convention for a Many-to-many table (a junction table)?

痞子三分冷 提交于 2019-12-11 16:15:22
问题 Whenever there is a many-to-many relationship, I think there will be immediately a many-to-many table needed (also called a junction table). Is there any advantage of using special naming convention for these tables, as opposed to the other 1 to many tables? Or are there popular special naming conventions used by companies designing database tables? 回答1: i tend to follow a pattern like this: 1. Table names are singular nouns 2. Link tables are nouns connected by underscore 3. a synonym can be

Many-to-Many hibernate mapping and mysql script - persistence problem

徘徊边缘 提交于 2019-12-11 16:14:45
问题 For some reason this is not persisting anything into tag_item table : Tag tag = new Tag(); tag.setName("test"); tag = (Tag) tagService.save(tag); Set<Tag> tags = new HashSet<Tag>(); tags.add(tag); Item item = itemService.getByStringId(2); item.setTags(tags); itemService.save(item); MySQL: CREATE TABLE `tags` ( `tag_id` bigint(20) NOT NULL auto_increment, `name` varchar(50) NOT NULL, PRIMARY KEY (`tag_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; CREATE TABLE `tag_item` ( `tag_id

How to get Title, Description and Price stored in a pivot table between users and services in Laravel

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 16:08:47
问题 I want to get the title, description, and price which are stored in a pivot table between users and services called userservices. I want to be able to display this information I'll get from the userservices table, inside the user profile view page. I have 4 tables for that which include, A User table with id, name, surname, email, phone, area_id. A Service table with id, name, description, and category_id. A category table with id, name, description and I have pivot table btw users and

Laravel Eloquent relation issue for multiple tables

 ̄綄美尐妖づ 提交于 2019-12-11 15:42:27
问题 In Laravel 5.5 I try to create a small application to manage products of a couple of sellers/stores. Therefore, I have four different models like this: Seller.php class Attribute extends Model { public function items() { return $this->belongsToMany(Item::class); } } Item.php class Item extends Model { public function seller() { return $this->belongsTo(Seller::class); } public function category() { return $this->belongsTo(Category::class); } public function attributes() { return $this-

How to add a where clause to a Hibernate @OneToMany explicit join table entity?

此生再无相见时 提交于 2019-12-11 15:29:04
问题 Given two entities: Card PurchaseProductGroup , which has a ppg_status column (field named as status on the entity) that can be 'A' (active) or 'D' (deleted) These conceptually have a many-to-many relationship but an explicitly defined join table entity named PurchaseProductGroupCard is used (so an external ID can be assigned for each mapping). So both Card and PurchaseProductGroup have a @OneToMany relationship to PurchaseProductGroupCard , e.g. in Card there is the following: @OneToMany

Spring Boot many to many post method not updating data

ε祈祈猫儿з 提交于 2019-12-11 15:23:00
问题 My User class looks like this : @Data @Entity public class User { @Id Long userID; @ManyToMany(mappedBy = "admins") private List<ClassRoom> classRooms = new ArrayList<>(); } And my ClassRoom class like this : @Data @Entity public class ClassRoom { @Id @GeneratedValue(strategy = GenerationType.AUTO) Long classRoomID; @ManyToMany @JoinTable(name ="classroom_user", joinColumns = @JoinColumn(name = "classroom_id"), inverseJoinColumns = @JoinColumn(name = "user_id")) private List<User> admins =