Monday 12 June 2017

Replacing object id with coresponding name from other object

Im very new to angular so ill try to describe the problem as cleary as i can. Im tring to make and single page app with some information about trading between people. AS for backend im using MySQL database + nodejs as a backed server and angular as frontend.

The problem is i have a person table with ID and a Name, Balance for each person. Then i have a table where i store all the transactions between the people ( Id, Giver ID , Taker ID , Amount ).

At the frontend when i get the information about the transactions i get IDS of the giver and taker, but i want to replace them with the coresponding name from persons table / object.

I have clearly no idea how to manag this. I thought about looping trought the transactions objects and replace each ID in the array with a name. Something like in this post

The Transaction object:

[Object]0:  id: 1  giver_id: 1 taker_id: 5 amount: 50 

Persons object:

[Object]0: balance:"-50" id:1 name:"Edgars"[Object]1: balance:"0" id:2 name:"Jānis"

So i want to replace the giver_id 1 with the name Edgars because as FK for giver id maches the persons id.

I dont want a clear answear but atleast a way to dig in.



via Edgars Karķis

No comments:

Post a Comment