Problem using JOIN with UUID ids (uuid_generate_v4)
Summary
When using the id as a UUID (uuid_generate_v4) and try to make a JOIN, got an error: Cannot create property '_2677701375' on string '625429df-e9a9-490b-b0ec-3f9add962804'. This fixes this problem, checking the object before build it
Database setup
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE public.room (
id uuid NOT NULL DEFAULT uuid_generate_v4(),
CONSTRAINT room_pk PRIMARY KEY (id)
);
CREATE TABLE public.leaderboard (
id uuid NOT NULL DEFAULT uuid_generate_v4(),
room uuid NOT NULL,
CONSTRAINT leaderboard_pk PRIMARY KEY (id),
CONSTRAINT leaderboard_room_fk FOREIGN KEY (room) REFERENCES room(id)
);
Code demonstrating the behavior
db.leaderboard.join({
room: {
type: 'INNER',
relation: 'room',
pk: 'id',
on: { id: 'leaderboard.room' },
},
}).find({});
Expected behavior
Return the leaderboards and their room associated populated.
Actual behavior
Receives an error: Cannot create property '_2677701375' on string '625429df-e9a9-490b-b0ec-3f9add962804'.
Additional context
I fixed this problem by debugging and updating the "decompose.js" file:
const uuid = require('uuid');
...
const isUUID = uuid.validate(obj[strid][c]);
const descendant = build(obj[strid][c] && !isUUID ? obj[strid][c] : {}, objSchema[c]);