Insert data in tables via Loopback API (Mysql Database)

459 views
Skip to first unread message

Raphaël Naegert

unread,
Feb 19, 2016, 9:06:17 AM2/19/16
to LoopbackJS
Hi everyone,

I am experiencing some troubles with Loopback. I think it's not difficult to achieve what i want but i can't :D

I hava Mysql database named audit and two tables one user et the other attack.

My aim is to be able to insert / show via the API fields in both tables at the same time. I guess i should use embedsMany but I can't find the correct structure.

Has someone a clue?

Raphaël Naegert

unread,
Mar 1, 2016, 10:41:02 AM3/1/16
to LoopbackJS
UP

Can someone help me?

Aurélie Violette

unread,
Mar 1, 2016, 11:22:45 AM3/1/16
to LoopbackJS
You can use relation between them I think.
See here https://docs.strongloop.com/display/public/LB/Creating+model+relations

Le mardi 1 mars 2016 16:41:02 UTC+1, Raphaël Naegert a écrit :
UP

Can someone help me?

Raphaël Naegert

unread,
Mar 1, 2016, 11:31:01 AM3/1/16
to LoopbackJS
 I tried but I can't get them work. Plus, I have no idea how to insert data in two endpoints via one request.

jo...@6river.com

unread,
Mar 3, 2016, 5:53:40 PM3/3/16
to LoopbackJS
I would like to know the answer to this too. According to the embedsMany documentation:

Treat embedsMany as an actual relation, no different from hasMany, for example. This means that you cannot just POST the full object with embedded/nested data to create everything all at once. So using the example above to add a Customer and multiple email addresses would require two POST operations, one for the Customer record and one for the multiple email address data.

Give this, I don't actually know what the difference between embedsMany and hasMany is.

-Josh
Reply all
Reply to author
Forward
0 new messages