Database

Problems using composite primary keys

I'm trying to model a many-to-many relationship with containers containing items which can belong to multiple containers with the help of a container_items table defined like so:

CREATE TABLE container_items (
    container_id UUID NOT NULL,
    item_id UUID NOT NULL,
    PRIMARY KEY (container_id, item_id)
);

But I get errors in the Generated/Types.hs file about Couldn't match type ‘Id' "items"’ with ‘UUID’ .

build/Generated/Types.hs:41:30: error:
    • Couldn't match type ‘Id' "items"’ with ‘UUID’
        arising from a use of ‘QueryBuilder.filterWhere’
    • In the third argument of ‘Item’, namely
        ‘(QueryBuilder.filterWhere
            (#itemId, id) (QueryBuilder.query @ContainerItem))’
      In the second argument of ‘($)’, namely
        ‘Item
           id
           name
           (QueryBuilder.filterWhere
              (#itemId, id) (QueryBuilder.query @ContainerItem))
           def’
      In a stmt of a 'do' block:
        pure
          $ Item
              id
              name
              (QueryBuilder.filterWhere
                 (#itemId, id) (QueryBuilder.query @ContainerItem))
              def
   |
41 |         pure $ Item id name (QueryBuilder.filterWhere (#itemId, id) (QueryBuilder.query @ContainerItem)) def
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^build/Generated/Types.hs:41:30: error:
    • Couldn't match type ‘Id' "items"’ with ‘UUID’
        arising from a use of ‘QueryBuilder.filterWhere’
    • In the third argument of ‘Item’, namely
        ‘(QueryBuilder.filterWhere
            (#itemId, id) (QueryBuilder.query @ContainerItem))’
      In the second argument of ‘($)’, namely
        ‘Item
           id
           name
           (QueryBuilder.filterWhere
              (#itemId, id) (QueryBuilder.query @ContainerItem))
           def’
      In a stmt of a 'do' block:
        pure
          $ Item
              id
              name
              (QueryBuilder.filterWhere
                 (#itemId, id) (QueryBuilder.query @ContainerItem))
              def
   |
41 |         pure $ Item id name (QueryBuilder.filterWhere (#itemId, id) (QueryBuilder.query @ContainerItem)) def
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I can get this to work if I have an id column as a pkey on container_items but should that be necessary? Not sure what I'm doing wrong here.

twahtera , in Database