reyesoft / ngx-jsonapi

JSON API client library for Angular 5+ 👌 :: Production Ready 🚀
https://ngx-jsonapi.reyesoft.com/
MIT License
101 stars 52 forks source link

Why do i get Empty relationship even-though the server is responding the relationship #150

Closed habatmu-birhanu closed 5 years ago

maxi7587 commented 5 years ago

Can you post the resource and service that you are using? I need more info...

junmar commented 5 years ago

I got similar issues. Below is data return from server { "data": [ { "attributes": { "accountId": 127, "location": "12654353 TARGET AUG", "fname": "XXXX", "lname": "xxxxxxxx", "mname": "A", "ssn": "008643091", "dln": "", "dls": "", "dob": "02/12/1972", "address": "32 Stacey st", "city": "Bath", "state": "ME", "zipCode": "04530", "preAddress": "", "preCity": "", "preState": "", "preZip": "", "statusId": 1, "addedOn": "2018-08-21T08:51:08.247", "isAb": "0", "hitType": "3", "isPrinted": false, "payment": false, "isOrderPrinted": true }, "relationships": { "account": { "links": { "self": "https://localhost:44314/orders/2237396/relationships/account", "related": "https://localhost:44314/orders/2237396/account" }, "data": { "type": "accounts", "id": "127" } }, "crimeClassification": { "links": { "self": "https://localhost:44314/orders/2237396/relationships/crimeClassification", "related": "https://localhost:44314/orders/2237396/crimeClassification" } }, "orderStatus": { "links": { "self": "https://localhost:44314/orders/2237396/relationships/orderStatus", "related": "https://localhost:44314/orders/2237396/orderStatus" }, "data": { "type": "orderStatuses", "id": "1" } }, "orderExt": { "links": { "self": "https://localhost:44314/orders/2237396/relationships/orderExt", "related": "https://localhost:44314/orders/2237396/orderExt" } }, "auto-reminder": { "links": { "self": "https://localhost:44314/orders/2237396/relationships/auto-reminder", "related": "https://localhost:44314/orders/2237396/auto-reminder" }, "data": [] }, "orderSearcHistory": { "links": { "self": "https://localhost:44314/orders/2237396/relationships/orderSearcHistory", "related": "https://localhost:44314/orders/2237396/orderSearcHistory" }, "data": [] }, "orderServices": { "links": { "self": "https://localhost:44314/orders/2237396/relationships/orderServices", "related": "https://localhost:44314/orders/2237396/orderServices" }, "data": [] } }, "type": "orders", "id": "2237396" } ], "links": { "last": "https://localhost:44314/orders?page[size]=10&page[number]=1&filter[id]=2237396" }, "included": [ { "attributes": { "statusName": "Open", "statusDesc": "Open" }, "relationships": { "orders": { "links": { "self": "https://localhost:44314/orderStatuses/1/relationships/orders", "related": "https://localhost:44314/orderStatuses/1/orders" }, "data": [ { "type": "orders", "id": "2237396" } ] } }, "type": "orderStatuses", "id": "1" }, { "attributes": { "firstname": "xxx", "lastname": "xxxx", "companyName": "xxx", "isCorporate": true, "address": "1575 HENTHORNE DRIVE\r\n", "city": "Maumee", "state": "OH", "zipCode": "43537", "phone": xxxxxx", "fax": "xxxxxxxx", "email": "sdfgsdfgsd@kbs-services.com", "corporateEmail": "", "extraEmail": "", "autoEmail": false, "instructions": "Use Tenant Screening for Nationwide Database. Note, This database does not cover all areas.

\r\nUse pre-employment Screening to process the fee for New York Statewide Search

\r\nUse Background Check Plus for to get an SSN trace and all counties where the subject resided.

\r\nUse Background Check Plus for to get an SSN trace and all counties where the subject resided plus the nationwide database scan
use associate screening plus for nationwide, federal, and ssn search with all counties included (wegmans)", "pricingBlurb": "", "isActive": true, "addedOn": "2001-10-30T00:00:00", "autoCriminalSearch": false, "nwdb": true, "nwdbAu": false }, "relationships": { "accountServices": { "links": { "self": "https://localhost:44314/accounts/127/relationships/accountServices", "related": "https://localhost:44314/accounts/127/accountServices" }, "data": [] }, "accountSettings": { "links": { "self": "https://localhost:44314/accounts/127/relationships/accountSettings", "related": "https://localhost:44314/accounts/127/accountSettings" }, "data": [] }, "accountUsers": { "links": { "self": "https://localhost:44314/accounts/127/relationships/accountUsers", "related": "https://localhost:44314/accounts/127/accountUsers" }, "data": [] }, "orders": { "links": { "self": "https://localhost:44314/accounts/127/relationships/orders", "related": "https://localhost:44314/accounts/127/orders" }, "data": [ { "type": "orders", "id": "2237396" } ] }, "printGroupAccount": { "links": { "self": "https://localhost:44314/accounts/127/relationships/printGroupAccount", "related": "https://localhost:44314/accounts/127/printGroupAccount" }, "data": [] } }, "type": "accounts", "id": "127" } ], "meta": { "total-records": 1 } }


------------------order definition import { Resource, DocumentCollection, DocumentResource } from 'ngx-jsonapi'; import { OrderStatus } from './order-status.model';

import { Account } from "./account.model"; import { OrderServiceModel } from './order-service.model';

export class Order extends Resource { public attributes = { accountId: '', location: '', employeeCode:'', fname:'', lname:'', mname:'', ssn:'', dln:'', dls:'', dob:'', address:'', city:'', state:'', zipCode:'', preAddress:'', PreCity:'', preState:'', preZip:'', addedOn:'', isAb:false, hitType:'', isPrinted:false, payment:'', ccType:'', ccMonth:'', ccYear:'', ccZip:'', fcraIssue:false, fcraDate:'', completeDate:'', isOrderPrinted:false, email:'', statusId:0 };

public relationships = {
    orderStatus: new DocumentResource<OrderStatus>(),
    account: new DocumentResource<Account>(),
    orderServices: new DocumentCollection<OrderServiceModel>()
};

}

--------------OrderStatus Definition -------------------------------------

import { Resource, DocumentCollection, DocumentResource } from 'ngx-jsonapi'; import { Order } from './order.model';

export class OrderStatus extends Resource {

public attributes = {
    statusName:'',
    statusDesc: ''

}
public relationships = {
    orders: new DocumentCollection<Order>(),

};

}

---------------------OrderService ---------------------- import { Injectable } from '@angular/core'; import { Autoregister, Service } from 'ngx-jsonapi';

import { Order } from "../models/jsonapi/order.model";

@Injectable() @Autoregister() export class OrderService extends Service { public resource = Order; public type = 'orders'; }

----function that calls the orderService methos all, get was used at first but same issue. There was a suggestion to use .all but same issue. Both Account and OrderStatus relationships are empty

loadOrder(id){ this.orderService.all({ remotefilter : { 'id': id }, include: ['orderStatus','account'] }).subscribe(order => { this.order = order.data[0] ; console.log(this.order); }); }