rom-sql icon indicating copy to clipboard operation
rom-sql copied to clipboard

Command#update breaks under compound keys

Open robinetmiller opened this issue 9 years ago • 0 comments

Use case: table with a compound key relation (:user_id & :event_id)

Table Descriptions


/* user */
+------------+-------------+------+-----+---------+----------------+
| Field      | Type        | Null | Key | Default | Extra          |
+------------+-------------+------+-----+---------+----------------+
| id         | int(11)     | NO   | PRI | NULL    | auto_increment |
| first_name | varchar(50) | YES  |     | NULL    |                |
| last_name  | varchar(50) | YES  |     | NULL    |                |
| email      | varchar(50) | YES  |     | NULL    |                |
+------------+-------------+------+-----+---------+----------------+


/* event */
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | 0       | auto_increment |
| name       | varchar(255) | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

/* event_invitation */
+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| user_id    | int(11)      | NO   | PRI | 0       |       |
| event_id   | int(11)      | NO   | PRI | 0       |       |
| note       | varchar(255) | YES  |     | NULL    |       |
+------------+--------------+------+-----+---------+-------+
   # ... within ROM setup
   rom.relation(:event_invitation) do
      primary_key [:user_id, :event_id]
   end

Bug Running update:

rom_container.command(:event_invitation).update.call({
    user_id: 1, 
    event_id: 1, 
    note: 'Note update'
})

shows that primary key pair doesn't get handled properly in ROM::SQL::Commands::Update#update. Variable pks (as defined on https://github.com/rom-rb/rom-sql/blob/master/lib/rom/sql/commands/update.rb#L67) is assigned a value of [nil]

robinetmiller avatar Dec 23 '15 00:12 robinetmiller