many-to-many

Many-to-many relation in yii2 activedataprovider

三世轮回 提交于 2021-01-28 05:01:07
问题 I have many-to-many relation with three tables: Category , Product , ProductCategory . Relation in Category : public function getProductCategories() { return $this->hasMany(ProductCategory::className(), ['category_id' => 'id']); } Relation in Product : public function getProductCategories() { return $this->hasMany(ProductCategory::ClassName(), ['product_id' => 'id']); } And in ProductCategory public function getProduct() { return $this->hasOne(Product::className(), ['id' => 'product_id']); }

MySQL: many to many relationship with multiple AND condition

强颜欢笑 提交于 2021-01-28 01:09:35
问题 I have a many-to-many relationship in my MySQL-database with three tables like this: TABLE item, TABLE relation (storing only ids of items and tags), TABLE tag Each item can have multiple tags also tags can be related to multiple items, e.g. the item "shoe" can have the tags "sport" and "leather" while the tag "sport" could be related to items "shoe" and "shirt". What I need to do now is select all items that have one or many tags combined by an AND-condition, so e.g. I'd like to find all

Fetching details of a group user belongs to in firebase

喜你入骨 提交于 2021-01-27 23:20:33
问题 Below is my database structure in firebase . I only have signed-in users Id. User -userId -Name -age -groups groupId1:true groupId2:true Group -groupId -name -desc -UserId -UserId1:true -UserId2:true I want to list the details of all the groups that user belongs to. My approach is, Find all the groups my user belongs to by checking the index from User. Using the list of groupid we got from step1, get details of group from Groups. Is there any other better suggestions? 回答1: With your current

ManyToMany Relationships. Returning fields in def __str__ method

本秂侑毒 提交于 2021-01-27 19:43:14
问题 I have two models: AffectedSegment model class AffectedSegment(models.Model): SEGMENTO_ESCAPULA = 'Escápula' SEGMENTO_HOMBRO = 'Hombro' SEGMENTO_CODO = 'Codo' SEGMENTO_ANTEBRAZO = 'Antebrazo' SEGMENTO_CARPO_MUNECA = 'Carpo/Muñeca' SEGMENTO_MANO = 'Mano' SEGMENT_CHOICES = ( (SEGMENTO_ESCAPULA, u'Escápula'), (SEGMENTO_HOMBRO, u'Hombro'), (SEGMENTO_CODO, u'Codo'), (SEGMENTO_ANTEBRAZO, u'Antebrazo'), (SEGMENTO_CARPO_MUNECA, u'Carpo/Muñeca'), (SEGMENTO_MANO, u'Mano'), ) affected_segment = models

ManyToMany Relationships. Returning fields in def __str__ method

爱⌒轻易说出口 提交于 2021-01-27 19:17:24
问题 I have two models: AffectedSegment model class AffectedSegment(models.Model): SEGMENTO_ESCAPULA = 'Escápula' SEGMENTO_HOMBRO = 'Hombro' SEGMENTO_CODO = 'Codo' SEGMENTO_ANTEBRAZO = 'Antebrazo' SEGMENTO_CARPO_MUNECA = 'Carpo/Muñeca' SEGMENTO_MANO = 'Mano' SEGMENT_CHOICES = ( (SEGMENTO_ESCAPULA, u'Escápula'), (SEGMENTO_HOMBRO, u'Hombro'), (SEGMENTO_CODO, u'Codo'), (SEGMENTO_ANTEBRAZO, u'Antebrazo'), (SEGMENTO_CARPO_MUNECA, u'Carpo/Muñeca'), (SEGMENTO_MANO, u'Mano'), ) affected_segment = models

MySQL Select Where In Many to Many

孤街浪徒 提交于 2021-01-27 04:12:07
问题 I'm having trouble with a SQL query. My schema describes a many to many relationship between articles in the articles table and categories in the categories table - with the intermediate table article_category which has an id , article_id and category_id field. I want to select all articles which only have the categories with id 1 and 2 . Unfortunately this query will also select any articles which have those categories in addition to any others. For example, this is a sample output from the

Add data to many-to-many relation with one SQL command

删除回忆录丶 提交于 2021-01-01 08:12:18
问题 I have a basic understanding of SQL databases and I might overlooked something, but I cannot figure out the following problem: there is a many-to-many relationship (for example: users - user_roles - roles). Is it possible to add (new) role to a (new) user with one SQL command (atomic operation)? Currently I use Sqlite. I am aware of the SELECT last_insert_rowid(); command and with this and several SQL commands I can achieve what I want. But I want to incorporate it into one command (so the

Add data to many-to-many relation with one SQL command

北城余情 提交于 2021-01-01 08:11:54
问题 I have a basic understanding of SQL databases and I might overlooked something, but I cannot figure out the following problem: there is a many-to-many relationship (for example: users - user_roles - roles). Is it possible to add (new) role to a (new) user with one SQL command (atomic operation)? Currently I use Sqlite. I am aware of the SELECT last_insert_rowid(); command and with this and several SQL commands I can achieve what I want. But I want to incorporate it into one command (so the

Django How to Serialize from ManyToManyField and List All

為{幸葍}努か 提交于 2020-12-29 07:01:32
问题 I'm developing a mobile application backend with Django 1.9.1 I implemented the follower model and now I want to list all of the followers of a user but I'm currently stuck to do that. I also use Django Rest Framework. This is my UserProfile model class UserProfile(models.Model): # Linking UserProfile to User model. user = models.OneToOneField(User) city = models.CharField(null=True, max_length=30, blank=True) gender = models.CharField(null=True, max_length=10, blank=True) # m for male, f for

Django How to Serialize from ManyToManyField and List All

六月ゝ 毕业季﹏ 提交于 2020-12-29 06:59:04
问题 I'm developing a mobile application backend with Django 1.9.1 I implemented the follower model and now I want to list all of the followers of a user but I'm currently stuck to do that. I also use Django Rest Framework. This is my UserProfile model class UserProfile(models.Model): # Linking UserProfile to User model. user = models.OneToOneField(User) city = models.CharField(null=True, max_length=30, blank=True) gender = models.CharField(null=True, max_length=10, blank=True) # m for male, f for