-
Notifications
You must be signed in to change notification settings - Fork 139
Open
Description
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
- 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,
});
- 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
Labels
No labels