You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
link method not attaching fk to url, failing to create relationship #78
where obviously xxxxxxxxx should be the id from the related model (promotionAfterCreation.id).
It may be an async issue, where you try to do the link before you actually get the promotionAfterCreation, make sure in your flow, you link after you get the promotionAfterCreation and make sure the promotionAfterCreation.id exists before you try to link.
In fact no. I am passing the Id and it is not empty.
My solution (workaround) is to hook on beforeRemote and afterRemote events of the create method of my model and do the work there in the server and it worked with the same data I was trying to pass to the REST service.
@erikverheij I think that's a generic problem of ngResource. All POST actions take four arguments (params, data, successCb, errorCb), with the first parameter being optional. In other words, if you provide only one object argument, then it's treated as POST data by the framework. I think this is another argument why we should drop ngResource and generate isomorphic-like API instead - see #133
@bajtos - would it not be possible to generate a wrapper function for the link methods, which simply nulls the third parameter before passing it on to Resource?
@csvan would it not be possible to generate a wrapper function for the link methods, which simply nulls the third parameter before passing it on to Resource?
It is possible, although I don't like that. Let me explain why: at the moment, lb-services have the same API as ngResource. You are proposing to subtly deviate from that API and provide custom function signatures for certain model methods. I think that would create even more confusion than we have right now.
I think the best solution is to bite the bullet, drop ngResource and rewrite the code generator to produce the same API as is on the server. See #133 for more details.
@bajtos - I realise I was vague in my previous comment, I did not mean to imply API breakage wrt Resource, just a utility function with the same API which nulls the third parameter if it is not provided by the user, in order to avoid this issue. I realise that this still deviates slightly from the expected API behavior, but it is preferable to passing null (which really makes no sense).
Activity
BerkeleyTrue commentedon Sep 23, 2014
After some playing around, this is the only way to get this to work.
This may be an issue with ngResource, as I had the same issue defining my own service.
I am using angular 1.2.23
bajtos commentedon Sep 24, 2014
Thanks @BerkeleyTrue for investigating issue and sharing the workaround.
Would you mind filling an issue in the Angular project? https://github.com/angular/angular.js
jonathan-casarrubias commentedon Dec 2, 2014
You don't necessary need to duplicate the object, you can also send an empty object or null in the second parameter and it will work
bajtos commentedon Dec 3, 2014
Thank you @jonathan-casarrubias for sharing the solution. I am closing this issue as resolved then.
@BerkeleyTrue feel to reopen if the approach outlined above does not work for you.
ahmed-abdulmoniem commentedon Mar 17, 2015
This is not working.
Tried to pass null, empty, duplicate objects and always I receive 404.
Any solution please?
or should I call the api myself using $http?
ahmed-abdulmoniem commentedon Mar 17, 2015
Still I am trying to do the workaround of passing null, empty, duplicate object to the link method but it is not working.
Here is my code:
.MallBranch.customPromotions.link({ id: item.id, fk: promotionAfterCreation.id }, null);or even
.MallBranch.customPromotions.link({ id: item.id, fk: promotionAfterCreation.id }, { id: item.id, fk: promotionAfterCreation.id });or even more
.MallBranch.customPromotions.link({ id: item.id, fk: promotionAfterCreation.id },{ mallBranchId: item.id, customPromotionId: promotionAfterCreation.id });Always gives me an error in the browser console:
PUT http://localhost:3000/api/MallBranches/55027ad139cb44c8431e4e83/customPromotions/rel 404 (Not Found)any solutions please?
jonathan-casarrubias commentedon Mar 25, 2015
The result error says that there is not "http://localhost:3000/api/MallBranches/55027ad139cb44c8431e4e83/customPromotions/rel" path, so in my understanding you are not passing the FK, even I see you actually try to pass it, no body can assure that promotionAfterCreation.id has a value.
My assumption is that promotionAfterCreation.id is in fact empty, because your route should be something like "http://localhost:3000/api/MallBranches/55027ad139cb44c8431e4e83/customPromotions/rel/xxxxxxxxx"
where obviously xxxxxxxxx should be the id from the related model (promotionAfterCreation.id).
It may be an async issue, where you try to do the link before you actually get the promotionAfterCreation, make sure in your flow, you link after you get the promotionAfterCreation and make sure the promotionAfterCreation.id exists before you try to link.
Cheers.
Jon
ahmed-abdulmoniem commentedon Mar 25, 2015
In fact no. I am passing the Id and it is not empty.
My solution (workaround) is to hook on beforeRemote and afterRemote events of the create method of my model and do the work there in the server and it worked with the same data I was trying to pass to the REST service.
Still, I can't solve the REST issue!
14 remaining items
Fixes strongloop#78, add params to resource action
erikverheij commentedon Jul 10, 2015
I still have to add null to get it working;
When null is omitted, data is added to the payload.
In some cases this results in an error in the back-end.
I'm using grunt-loopback-sdk-angular 1.1.2 which installs loopback-sdk-angular 1.4.0.
bajtos commentedon Jul 10, 2015
@erikverheij I think that's a generic problem of ngResource. All POST actions take four arguments (params, data, successCb, errorCb), with the first parameter being optional. In other words, if you provide only one object argument, then it's treated as POST data by the framework. I think this is another argument why we should drop ngResource and generate isomorphic-like API instead - see #133
erikverheij commentedon Jul 11, 2015
@bajtos isn't it possible to let the .link() method set the optional argument to null by default?
bajtos commentedon Aug 5, 2015
@erikverheij I am not aware of any solution. You can take a look at ngResource implementation yourself, it's possible that I just did not spot the way: https://github.com/angular/angular.js/blob/dc0b856e9c540fc8453d83f1be12bdfa1662b013/src/ngResource/resource.js#L520-L554
erikverheij commentedon Aug 15, 2015
@bajtos, thanks for your reply. I'm quite busy right now, but I'll try to figure out a a solution in a few weeks.
csvan commentedon Aug 25, 2015
@bajtos - would it not be possible to generate a wrapper function for the
linkmethods, which simply nulls the third parameter before passing it on to Resource?bajtos commentedon Aug 25, 2015
It is possible, although I don't like that. Let me explain why: at the moment, lb-services have the same API as ngResource. You are proposing to subtly deviate from that API and provide custom function signatures for certain model methods. I think that would create even more confusion than we have right now.
I think the best solution is to bite the bullet, drop ngResource and rewrite the code generator to produce the same API as is on the server. See #133 for more details.
csvan commentedon Aug 25, 2015
@bajtos - I realise I was vague in my previous comment, I did not mean to imply API breakage wrt Resource, just a utility function with the same API which nulls the third parameter if it is not provided by the user, in order to avoid this issue. I realise that this still deviates slightly from the expected API behavior, but it is preferable to passing null (which really makes no sense).
That said, I agree that your proposal is better.
erikverheij commentedon Sep 7, 2015
I was also thinking of a wrapper. I'll stick with the workaround for the moment.
fix actions vs indicator link, based on strongloop/loopback-sdk-angul…
nzmedet commentedon Jan 13, 2016
I tried to define many-to-many relation with my Lead and Tag models
Lead model
Tag model
First request works
Second request gives error: Duplicate entry for LeadTag.id
This is kinda weird tho, any ideas?
karladler commentedon Jul 1, 2016
@vko-online I guess this is intensional, since the link is already set by the first request. Try to change the id or fk.