loopbackio / loopbackio/loopback-next

How to define model properties of `Object` type?

Open
#2,056 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Docs good first issue help wanted Repository
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

I have generated a model which results in `thing.model.ts`:

```
import {Entity, model, property} from '@loopback/repository';

@model()
export class Thing extends Entity {
@property({
type: 'string',
id: true,
required: true,
})
id: string;

@property({
type: 'string',
required: true,
})
name: string;

@property({
type: 'string',
required: true,
})
description: string;

@property({
type: 'object',
required: true,
})
attributes: object;

constructor(data?: Partial) {
super(data);
}
}

```

How do I go about defining the `attributes` object? Am I only able to do this by defining another `attributes` model? My searches provide information on doing this with LB3.x but that is using a .json file and not using `@property` decorators.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated thing.model.ts example and the @property decorator usage shown in the issue. Check the current LoopBack model-property documentation for supported object definitions and compare it with the older LB3 guidance. Done should be a clear documented answer or example explaining how to define attributes.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.