Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tables that relate to themselves #33

Open
mitswan opened this issue Jan 29, 2020 · 3 comments
Open

Tables that relate to themselves #33

mitswan opened this issue Jan 29, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@mitswan
Copy link

mitswan commented Jan 29, 2020

I have noticed tables that reference themselves will only work one way with this plugin.

In the example scenario, you can nested insert Child -> Parent OR Parent -> Child

create table app.parent (
  id serial primary key,
  name text not null
);

create table app.child (
  id serial primary key,
  parent_id integer,
  name text not null,
  constraint child_parent_fkey foreign key (parent_id)
    references app.parent (id)
);

But if you make it a single person table it will only let you nested insert Child -> Parent

create table app.person (
  id serial primary key,
  parent_id integer,
  name text not null,
  constraint person_parent_fkey foreign key (parent_id)
    references app.person(id)
);
@wafokevin
Copy link

I am facing the same problem, it must come from an inflection issue, I'll try to look into it.

@Eldow
Copy link
Contributor

Eldow commented Dec 22, 2020

I digged a little bit into this.
I modified the package with https://www.npmjs.com/package/patch-package.
Inside PostgraphileNestedTypesPlugin l.177, I modified the isForward condition. It was masking some reverse relations when their constraints were related to themselves, eg :
const isForward = constraint.classId === table.id
I switched it to :
const isForward = constraint.classId === table.id && constraint.classId !== constraint.foreignClassId;
To allow these special kind of constraints to work.

Untested, use at your own risk.

I would be glad to make a PR but the repo owner doesn't seem to be maintaining it.

JesseVelden added a commit to JesseVelden/postgraphile-plugin-nested-mutations that referenced this issue Dec 24, 2020
ChrisKitching pushed a commit to ChrisKitching/postgraphile-plugin-nested-mutations that referenced this issue Jan 9, 2021
@mlipscombe
Copy link
Owner

Sorry for the delay. Changing the test for isForward just swaps the problem around -- you now get the the parent > child nested mutation, but lose the child > parent nested mutation. To fix this properly needs a bit of a refactor of the code I think. I've added a test for the currently working direction (child > parent), and I'll do some refactoring to make the other direction work right.

mlipscombe added a commit that referenced this issue Mar 26, 2021
@mlipscombe mlipscombe added the bug Something isn't working label Mar 26, 2021
Js-Brecht pushed a commit to autocorp-old/postgraphile-plugin-nested-mutations that referenced this issue May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants