Skip to content

Defining relations results to error when the Mapper recordClass is set to false (POJO) #570

@XT-Martinez

Description

@XT-Martinez

Description

I'm implementing a Data Mapper Pattern structure for my project and would like to use POJOs instead of Record instances when dealing with data from a REST API.
However, defining relations results to error when the recordClass in the mapper is set to false (POJO).
I'm not encountering an error if the recordClass is not set.

Environment

  • js-data version: 3.0.8
  • node or browser version: Google Chrome Version 83.0.4103.106
  • operating system: Fedora 32 Silverblue

Steps to reproduce

  1. Use the code below.
import { DataStore } from "js-data";
import { HttpAdapter } from "js-data-http";

const BASE_PATH = "http://localhost:3000/api";
const Store = new DataStore();
const Adapter = new HttpAdapter({ basePath: BASE_PATH });

Store.registerAdapter("http", Adapter, { default: true });

Store.defineMapper("ProductVariation", {
  endpoint: "productVariation",
  schema: {
    type: "object",
    properties: {
      id: { type: "number" },
      productId: { type: "number", indexed: true },
      name: { type: "string" },
    },
  },
  relations: {
    belongsTo: {
      Product: {
        foreignKey: "productId",
        localField: "product",
      },
    },
  },
  recordClass: false,
});

Store.defineMapper("Product", {
  endpoint: "product",
  schema: {
    type: "object",
    properties: {
      id: { type: "number" },
      name: { type: "string" },
      description: { type: "string" },
      isActive: { type: "boolean" },
    },
  },
  relations: {
    hasMany: {
      ProductVariation: {
        foreignKey: "productId",
        localField: "variations",
      },
    },
  },
  recordClass: false,
});
  1. When executed, error encountered
DataStore.js:167 Uncaught TypeError: Cannot convert undefined or null to object
    at Function.getOwnPropertyDescriptor (<anonymous>)
    at DataStore.js:167

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions