junction-table

Select rows that have a specific set of items associated with them through a junction table

浪尽此生 提交于 2019-12-13 05:48:21
问题 Suppose we have the following schema: CREATE TABLE customers( id INTEGER PRIMARY KEY, name TEXT ); CREATE TABLE items( id INTEGER PRIMARY KEY, name TEXT ); CREATE TABLE customers_items( customerid INTEGER, itemid INTEGER, FOREIGN KEY(customerid) REFERENCES customers(id), FOREIGN KEY(itemid) REFERENCES items(id) ); Now we insert some example data: INSERT INTO customers(name) VALUES ('John'); INSERT INTO customers(name) VALUES ('Jane'); INSERT INTO items(name) VALUES ('duck'); INSERT INTO items

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

Delete row from Access junction table via form

微笑、不失礼 提交于 2019-12-11 11:44:34
问题 I set up a subform listing stored values from a junction and lookup table. This part is working nicely (I can view all stored entries or add new ones). Here are my relationships: And here's the layout of my form showing where I attempted to remove a previously saved association. If I simply delete the contents of the row in the form, Access returns this when I try to save the record: index or primary key cannot contain null value The SQL to remove a row from a console is straightforward:

Mysql working with comma separated list - Junction table

久未见 提交于 2019-12-11 10:39:35
问题 I have a Junction table with ProductID and Accessory column: TABLE1 ProductID Accessory 1 2 1 3 2 1 2 4 2 5 3 4 1 5 2 It means that for the ProductID 2, it has the Accessory ProductIDs 1,4 and 5 ... and i have THE TABLE 2 below which look like this THE GRP and ProductID is already provided, we need to fetch the accesories. TABLE2 GRP ProductID accessories a 2 b 3 c 1 d 4 e 5 so actually if using UPDATE it would be like this TABLE2 UPDATE table2 t2 set t2.accessories = (SELECT GROUP_CONCAT

Storing gene expression data in MySQL — junction tables needed?

好久不见. 提交于 2019-12-10 18:41:24
问题 I have several m x n matrices of gene expression data that I want to store in MySQL. m is approx 30,000 genes (uniquely identifiable) n is approx 3,000 samples (mostly uniquely identifiable) I'm not sure what the best way is to store these data. I initially read the matrices directly into MySQL tables, but I have since been told that this is not a great way to do things, since the number of columns (samples) is a variable quantity. I cannot transpose the matrices and store them that way

Yii2 Activerecord get fields from junction table and order by according to them

*爱你&永不变心* 提交于 2019-12-06 16:13:47
I have items and units table that have many to many relationship. In other words, the item has many units and the unit has many items. I managed the relation through a junction table item_units . The junction table has some extra field more than item_id and unit_id , i.e it has price, and weight (it is an integer to manage the order of units for each item for display purposes). I managed the relations in the models as follows: //In Items model /** * @return \yii\db\ActiveQuery */ public function getItemUnits() { return $this->hasMany(ItemUnits::className(), ['item_id' => 'id'])->orderBy(['item

Junction tables vs foreign key arrays?

折月煮酒 提交于 2019-11-30 04:40:16
I'm modeling many-to-many relationship where the relationship is accessed most of the time from one side only. It's more like a hierarchy, that is accessed top-down and not the other way around. Survey has and belongs to many Questions has and belongs to many Answers . Both relationships must be many-to-many because a same question can be re-used across different surveys and same answer in many questions. This is a requirement. The standard M2M implementation would use two junction tables, surveys_questions and questions_answers . Instead, I'm thinking about using PostgreSQL's integer arrays

In a join table, what's the best workaround for Rails' absence of a composite key?

谁说胖子不能爱 提交于 2019-11-28 16:23:28
create_table :categories_posts, :id => false do |t| t.column :category_id, :integer, :null => false t.column :post_id, :integer, :null => false end I have a join table (as above) with columns that refer to a corresponding categories table and a posts table. I wanted to enforce a unique constraint on the composite key category_id, post_id in the categories_posts join table. But Rails does not support this (I believe). To avoid the potential for duplicate rows in my data having the same combination of category_id and post_id, what's the best workaround for the absence of a composite key in Rails

How to configure a One-to-Many relationship in EF

二次信任 提交于 2019-11-28 13:24:51
I have the following model public class PageConfig : Base { // Properties Etc.. public ICollection<Image> ScrollerImages { get; set; } } My approach is to bind using a junction table { PageConfigID, ImageID }. In my model binder i tried the following.. modelBuilder.Entity<PageConfig>() .HasMany(x => x.ScrollerImages) .WithMany() .Map(x => { x.ToTable("junc_PageConfigScrollerImages"); x.MapLeftKey("PageConfigID"); x.MapRightKey("ImageID"); }); Which results in a null collection of images. How can i bind these Images to the PageConfig model? EDIT Most of the problem was due to user error. jic

Many to many relationship with junction table in Entity Framework?

坚强是说给别人听的谎言 提交于 2019-11-27 15:12:47
I'm trying to create a many-to-many relationship in Entity Framework (code first), according to the following post: Database design for limited number of choices in MVC and Entity Framework? However, I can't get it to work properly, and I'm sure I'm doing something very simple the wrong way. Here's the diagram I have no from my attempts: The point of the junction table is that I need to have an extra property, Level, in the relationship, so I can't just go with a direct relationship between Consultant and Program. I added the ConsultantProgramLink entity manually in the designer, and then