Skip to content

postgres connector not returning generated identifier value on create of entity for camelCased identifiers in table #3749

@basavarajvs

Description

@basavarajvs

If a Postgres table has camelCased identifier then auto-generated code of loopback does not return the identifier on creating the entity.

Steps to reproduce

  1. Create 2 tables in postgres with the identifier field with camel casing .
CREATE TABLE test."Customer" (
	"**customerId**" uuid NOT NULL DEFAULT gen_random_uuid(),
	"name" varchar(50) NOT NULL,
	CONSTRAINT "Customer_pkey" PRIMARY KEY ("customerId")
);
CREATE UNIQUE INDEX "PK_Customer" ON "Customer" USING btree ("customerId");

-- Drop table

-- DROP TABLE test."Order";

CREATE TABLE test."Order" (
	id uuid NOT NULL DEFAULT gen_random_uuid(),
	"customerId" uuid NOT NULL,
	"name" varchar(50) NOT NULL,
	"isDelivered" bool NOT NULL,
	CONSTRAINT "Order_pkey" PRIMARY KEY (id)
);
CREATE UNIQUE INDEX "PK_Order" ON "Order" USING btree (id);
CREATE INDEX "fkIdx_431" ON "Order" USING btree ("customerId");

ALTER TABLE test."Order" ADD CONSTRAINT "FK_431" FOREIGN KEY ("customerId") REFERENCES "Customer"("customerId");

Please note that the identifier field for Cutomer table is customerId in camelCasing

  1. Run loopback discover to create the models.
    loopback discover --schema test

  2. Generate repository and controller.

  3. Run "npm start"

  4. In Swagger execute a post request for Customer.

Current Behavior

The Customer entity is created but the response does not have the identifier field populated.

Expected Behavior

On creating an entity with a camelCased identifier the id should be returned in the post request response.

The problem is not reproduced when the identifiers are lowercased.

Link to reproduction sandbox

Additional information

lb4 --version
@loopback/cli version: 1.21.6

@loopback/* dependencies:
  - @loopback/authentication: ^3.0.0
  - @loopback/boot: ^1.5.5
  - @loopback/build: ^2.0.10
  - @loopback/context: ^1.22.1
  - @loopback/core: ^1.10.1
  - @loopback/metadata: ^1.3.1
  - @loopback/openapi-spec-builder: ^1.2.12
  - @loopback/openapi-v3: ^1.9.6
  - @loopback/repository-json-schema: ^1.9.7
  - @loopback/repository: ^1.13.1
  - @loopback/rest: ^1.18.1
  - @loopback/testlab: ^1.8.0
  - @loopback/docs: ^2.0.0
  - @loopback/example-hello-world: ^1.2.13
  - @loopback/example-log-extension: ^1.2.13
  - @loopback/example-rpc-server: ^1.2.13
  - @loopback/example-todo: ^1.7.6
  - @loopback/example-soap-calculator: ^1.6.14
  - @loopback/service-proxy: ^1.3.5
  - @loopback/http-caching-proxy: ^1.1.12
  - @loopback/http-server: ^1.4.12
  - @loopback/example-todo-list: ^1.9.6
  - @loopback/dist-util: ^0.4.0
  - @loopback/rest-explorer: ^1.3.6
  - @loopback/eslint-config: ^4.0.2
  - @loopback/example-express-composition: ^1.5.6
  - @loopback/example-greeter-extension: ^1.3.13
  - @loopback/booter-lb3app: ^1.2.13
  - @loopback/example-lb3-application: ^1.1.13
  - @loopback/example-greeting-app: ^1.1.13
  - @loopback/example-context: ^1.2.13
  - @loopback/repository-tests: ^0.4.4
  - @loopback/extension-health: ^0.2.5
  - @loopback/authorization: ^0.2.2
  - @loopback/rest-crud: ^0.2.0
  - @loopback/security: ^0.1.1

Related Issues

See Reporting Issues for more tips on writing good issues

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions