-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to override the url in has_many relation #59
Comments
I think you could do something like this parts: { hasMany: 'BikePart', path: 'parts'} |
awesome! thank's @blackjid |
I don't know if i'm doing something wrong or there's a little bug here. The attribute path works fine when the data from the api doesn't came with
But when |
If you set To tell restmod to use 'parts' as the attribute name you can use the parts: { hasMany: 'BikePart', path: 'bike_parts', source: 'parts' } |
After digging a little more I found out that actually if you use This should be fixed in a way that using |
Yeah!, thank's a lot @iobaixas |
Don't close it just yet, I need to check the naming thing first. |
sorry |
@iobaixas @bunzli: Guys, please, can you help me? I have huge problems getting to work this simple response with pre-inlined resource: {
id: 1,
productTags: {
data: [...], // we use {data: [], metadata: {}} structure for collections
metadata: {...}
},
...
} My model definition: ...
return restmod.model('/products').mix({
productTags: {
hasMany: 'Tag', mask: 'CU', path: 'tags', source: 'productTags.data'
// also tried: hasMany: 'Tag', mask: 'CU', path: 'tags', map: 'productTags.data'
},
... After fetching Does it only work with structures like: { id: 1, inlinedCollection: [...], ... } or I am missing something else here? Help really appreciated. Important note: I want to read and init from pre-inlined data, but creating and updating is performed on separate routes like |
Hi @smajl, this is probable because restmod expects create/update (POST/PUT) requests to respond with a structure similar to show (GET). Could you share with us some sample output from the create request triggered when a new tag is created? |
@iobaixas I am not trying to save |
The packer only works on the root of the request, not on each object that get decoded, so I don't think there is a problem there. From the error you pasted before ( I insist on you sharing the POST response, the problem is probably related to that. |
@iobaixas To be specific, I am updating, so it's PUT request and response is empty, our backend implementation is not sending any responses on PUT requests - sorry, I can't paste anything. The error is fired after The stacktrace is:
The problem is that the |
Could you try this: In your base model add the following hook: hooks: {
'after-request': function(_req) {
if(!_req.data) _req.data = {};
}
} |
Wow, thank you thousand times, seems like that did the trick!!! Final model looks like this: return restmod.model('/products').mix({
// I don't even need to mask this, it does not get send on updates
productTags: { hasMany: 'Tag', source: 'productTags.data' },
...
'$hooks': {
'after-request': function (_req) {
if(!_req.data) _req.data = {};
}
}
}); Awesome, thanks again, but this was a bit tricky. Is this normal behavior or is our JSON data from server or defined model somehow special? |
@smajl, it was a somewhat difficult to spot bug in the serialization module. Thanks for your feedback! |
@smajl, I'm not sure if the REST standard recommends that POST/PUT requests must return some content. At least in APIs made by us we always return the created/updated object in the response. |
the parent object was null. Relates to #59
I would like that my
request to
bikes/3/bike_parts
instead ofbikes/3/parts
The text was updated successfully, but these errors were encountered: