Skip to content

Navigational properties are not allowed in model data #4354

@dexdinesh

Description

@dexdinesh

As I had already used relations in loop back4 project now when I tried to perform any crud operation it returns
500 Error: Navigational properties are not allowed in model data (model "UserDevice" property "user_id")

My models are as follows:

User Model:

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

@model({
  settings: {
    strictObjectIDCoercion: true,
    strict: false,
  }
})
export class Users extends Entity {
  @property({
    type: 'string',
    id: true,
    generated: true,
    mongodb: { dataType: 'ObjectID' },
  })
  id?: string;

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

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

  @property({
    type: 'string',
    required: false,
    default: null,
  })
  password: string;

  @property({
    type: 'string',
    required: false,
    default: null,
  })
  company: string;

  @property({
    type: 'string',
    required: false,
    default: null,
  })
  biography: string;

  @property({
    type: 'string',
    required: false,
    default: null,
  })
  job_position: string;

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

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

  @property({
    type: 'string',
    required: false,
    default: null,
  })
  profile_pic: string;

  @property({
    type: 'string',
    required: false,
    default: null,
  })
  profile_thumbnail: string;

  @property({
    type: 'string',
    required: false,
    default: null,
  })
  otp: string;

  @property({
    type: 'boolean',
    default: false,
  })
  login_status: boolean;

  @property({
    type: 'string',
    required: false,
    default: null,
  })
  tmp_password: string;

  @property({
    type: 'boolean',
    required: false,
    default: false,
  })
  receive_post_notification: boolean;

  @property({
    type: 'boolean',
    required: false,
    default: false,
  })
  receive_new_follower_notification: boolean;

  @property({
    type: 'string',
    default: null,
  })
  created_at: string;

  @property({
    type: 'string',
    default: null,
  })
  updated_at?: string;

  constructor(data?: Partial<Users>) {
    super(data);
  }
}

export interface UsersRelations {
  // describe navigational properties here
}

export type UsersWithRelations = Users & UsersRelations;

User Device Model:

import { Entity, model, property, belongsTo } from '@loopback/repository';
import { timeZone } from '../Helpers/TimeZone';
import { Users } from './users.model';

@model({
  settings: {
    strictObjectIDCoercion: true,
    strict: false,
  }
})
export class UserDevice extends Entity {
  @property({
    type: 'string',
    id: true,
    generated: true,
  })
  id?: string;
  @property({
    type: 'string',
    required: true,
  })
  device_id: string;

  @property({
    type: 'string',
  })
  device_name?: string;

  @property({
    type: 'number',
  })
  device_type: number;

  @property({
    type: 'string',
  })
  app_version: string;

  @property({
    type: 'string',
  })
  fcm_token: string;

  @property({
    type: 'number',
  })
  is_active: number;

  @property({
    type: 'string',
    default: timeZone(),
  })
  created_at?: string;

  @property({
    type: 'string',
    default: null
  })
  updated_at?: string;

  @belongsTo(() => Users)
  user_id: string;

  constructor(data?: Partial<UserDevice>) {
    super(data);
  }
}

export interface UserDeviceRelations {
  // describe navigational properties here
}

export type UserDeviceWithRelations = UserDevice & UserDeviceRelations;

Error I always receive on Create and Update operation:

Unhandled error in POST /users/login: 500 Error: Navigational properties are not allowed in model data (model "UserDevice" property "user_id")
at UserDeviceRepository.ensurePersistable (/home/abc/Downloads/mohit/node-apps/rosenberg/alumniapp-api2/node_modules/@loopback/repository/src/repositories/legacy-juggler-bridge.ts:585:15)
at UserDeviceRepository.entityToData (/home/abc/Downloads/mohit/node-apps/rosenberg/alumniapp-api2/node_modules/@loopback/repository/src/repositories/legacy-juggler-bridge.ts:554:17)
at UserDeviceRepository.updateAll (/home/abc/Downloads/mohit/node-apps/rosenberg/alumniapp-api2/node_modules/@loopback/repository/src/repositories/legacy-juggler-bridge.ts:434:38)
at UsersController.login (/home/abc/Downloads/mohit/node-apps/rosenberg/alumniapp-api2/src/controllers/users.controller.ts:169:41)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at MySequence.handle (/home/abc/Downloads/mohit/node-apps/rosenberg/alumniapp-api2/src/sequence.ts:44:22)
at HttpHandler._handleRequest (/home/abc/Downloads/mohit/node-apps/rosenberg/alumniapp-api2/node_modules/@loopback/rest/src/http-handler.ts:78:5)

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