Hope you kindly guys could help me to discuss some the questions about loopback.
For Nodejs and loopback, so far I had read the documentation and realized the basic concept and how it works. Now I am trying to build a backend server based on loopback but still got some confuses. Then wish you can lend me a hand to make me understand easier. Thanks so much!
Is that possible to override or rewrite the predefine method without change the path? (e.g. I have a Publisher model which contain username and password properties. Before create a new Publisher instance I would like to check the username if unique. But as I know the predefine method will directly create a instance after post a request.)
Could I disable all the predefine remote methods but only expose customized remote method? (e.g. In some of my models, for security reasons or simpliy the code I would like to disbale all the predefine mehod and only expose a few customized remote method. I know I could set the model's public property to false but it will lead to all APIs are not available to viste. And the disableRemoteMethod method looks won't work fine when models have relations.)
If there's better way to handle the model's relations? (e.g. I got two models called Publisher and Talk, The PublisherhasManyTalk and the foreign key called publisherId. When I try to create a new Talk, I need check the publisherId (ensure the publisher is existed) first before saved the instance. And then I am thinking about that what if the Talk have other foreign keys? YES! The callback hell come out!)
Any ideas to reformat the response to client? (e.g. When I query the Talk model data and it responsed {title:'ttt', description: 'dddd'}, I would like to add extra property which not belong to theTalk and the response shall look like {title:'ttt', description: 'dddd', voteCount: '1234'}. )
Any suggestions on organizing the code structure?(e.g. like controller, service folder, In my opinion it's not wisely to put all the code in the model.)
Still thanks for taking your precious time to read. I am really grateful.
Hi there,
Hope you kindly guys could help me to discuss some the questions about loopback.
For Nodejs and loopback, so far I had read the documentation and realized the basic concept and how it works. Now I am trying to build a backend server based on loopback but still got some confuses. Then wish you can lend me a hand to make me understand easier. Thanks so much!
Publisher
model which containusername
andpassword
properties. Before create a newPublisher
instance I would like to check theusername
if unique. But as I know the predefine method will directly create a instance after post a request.)public
property tofalse
but it will lead to all APIs are not available to viste. And thedisableRemoteMethod
method looks won't work fine when models have relations.)Publisher
andTalk
, ThePublisher
hasMany
Talk
and the foreign key calledpublisherId
. When I try to create a newTalk
, I need check thepublisherId
(ensure the publisher is existed) first before saved the instance. And then I am thinking about that what if theTalk
have other foreign keys? YES! The callback hell come out!)Talk
model data and it responsed{title:'ttt', description: 'dddd'}
, I would like to add extra property which not belong to theTalk
and the response shall look like{title:'ttt', description: 'dddd', voteCount: '1234'}
. )controller
,service
folder, In my opinion it's not wisely to put all the code in the model.)Still thanks for taking your precious time to read. I am really grateful.
MaYi