Giter Site home page Giter Site logo

Comments (3)

benjie avatar benjie commented on August 27, 2024 1

Contrary to what I said yesterday, point 1 isn't actually a bug. Refs shouldn't inherit behaviors from the relations, they're explicit - e.g. you might @behavior -* a organization_members join table, but use a ref to allow going straight from organization to members.

So actually the bug was just point 2, which is fixed in #2149

from crystal.

benjie avatar benjie commented on August 27, 2024

Reproduction code:

DROP SCHEMA if EXISTS "dansdata" cascade;
CREATE SCHEMA "dansdata";
set search_path to dansdata;

--------------------------------------------------------------------------------

CREATE TYPE dansdata.profile_type AS ENUM('individual', 'organization');
comment on type dansdata.profile_type is '@name TypeOfProfile';

CREATE TABLE dansdata.profiles (
  id UUID DEFAULT gen_random_uuid () PRIMARY KEY,
  type dansdata.profile_type NOT NULL,
  name TEXT NOT NULL
);

comment ON TABLE dansdata.profiles IS
E'@interface mode:relational type:type\n'
'@type individual references:individuals\n'
'@type organization references:organizations\n'
'@name Profile\n'
'\n'
'Represents an entity with profile data.';

CREATE TABLE dansdata.individuals (
  id UUID PRIMARY KEY REFERENCES dansdata.profiles (id) ON DELETE cascade
);

comment ON TABLE dansdata.individuals IS E'@name Individual\nRepresents an individual person.';

CREATE TABLE dansdata.organizations (
  id UUID PRIMARY KEY REFERENCES dansdata.profiles (id) ON DELETE cascade
);

comment ON TABLE dansdata.organizations IS E'@name Organization\n\nRepresents an organization.';

--------------------------------------------------------------------------------

CREATE
OR REPLACE function dansdata.create_individual (name TEXT) returns dansdata.individuals AS $$
  WITH "profile" AS (
    INSERT INTO dansdata.profiles("type", "name") VALUES ('individual', name) RETURNING *
  ) INSERT INTO dansdata.individuals("id") (SELECT id from "profile") RETURNING *;
$$ language sql volatile strict security invoker;


CREATE
OR REPLACE function dansdata.create_organization (name TEXT) returns dansdata.organizations AS $$
  WITH "profile" AS (
    INSERT INTO dansdata.profiles("type", "name") VALUES ('organization', name) RETURNING *
  ) INSERT INTO dansdata.organizations("id") (SELECT id from "profile") RETURNING *;
$$ language sql volatile strict security invoker;

from crystal.

benjie avatar benjie commented on August 27, 2024

The bug is related to this code:

// TODO: normally we wouldn't call `getBehavior` anywhere
// except in an entityBehavior definition... Should this be
// solved a different way?
const behavior = getBehavior([
relationSpec.remoteResource.codec.extensions,
relationSpec.remoteResource.extensions,
relationSpec.extensions,
]);

Specifically the behaviors coming out of that are '' (which is not unexpected given how behaviors work); however, we are expecting the -single behavior to come out of it; the one that is added here:

return [behavior, "-connection -list -single"];

We know it's added because the relationship is not added to the interface type; and yet it is still added (via refs, incorrectly) to the child types.

Really there's two bugs here:

  1. The ref behaviors aren't correctly being influenced by the parts that make up the ref (see the TODO linked above - yes we're doing this the wrong way)
  2. These specific refs, independent of behaviours, shouldn't be added in the first place.

Solving either one of these bugs will fix the issue, but both should be solved.

from crystal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.