lambdaisland / lambdaisland/facai

Custom JDBC table config lost when child relationships deferred

Open
#7 1 comment 0 reactions 1 assignee View on GitHub

@plexus is already working on this.

Since Jan 25, 2023.

Dominant language
Clojure
Stars
48
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Consider a typical foreign key relationship between two tables like this:

--Database tables:

create table child
(
    child_id    varchar(40) not null primary key,
    description varchar(200)
);

create table parent
(
    parent_id   varchar(40) not null
        primary key,
    child_id    varchar(40) not null
        references child,
    parent_desc varchar(500)
);

, with factories defined like so:

  (f/defactory child
    :lambdaisland.facai.next-jdbc/table "child"
    :facai.factoryory/primary-key :child-id
    {:child-id #(str (random-uuid))
     :description "This is the description"}
    :traits
    {:bar
     {:with {:description "bar"}}})

  (f/defactory parent
    :lambdaisland.facai.next-jdbc/table "parent"
    :facai.factoryory/primary-key :parent-id
    {:parent-id #(str (random-uuid))
     :child child
     :parent-desc  #(str (random-uuid))}
    :traits
    {:foo
     {:with {:parent-desc "foo"}}})

when attempting to create! sample data in Postgres using the lambdaisland.next.jdbc namespace like so:

(fnj/create! {::fnj/ds ds
                ::fnj/fk-col-fn #(keyword (str (name %) "-id"))}
                parent {
                        :with {:child (lambdaisland.facai.kernel/defer child {:traits [:bar]})}})

a Postgres Exception is thrown:

Execution error (PSQLException) at org.postgresql.core.v3.QueryExecutorImpl/receiveErrorResponse (QueryExecutorImpl.java:2676).
ERROR: relation "children" does not exist
  Position: 13
  Location: File: parse_relation.c, Routine: parserOpenTable, Line: 1376
  Server SQLState: 42P01

This implies that the
:lambdaisland.facai.next-jdbc/table value in the child factory is not being used, as would be expected in this configuration. This works for the standard case with no defer on the child factory, so it is probably related to the deferral.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.