Skip to content
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

Customize read/write BelongsToMany or HasMany #375

Open
ProTrent opened this issue Apr 2, 2016 · 1 comment
Open

Customize read/write BelongsToMany or HasMany #375

ProTrent opened this issue Apr 2, 2016 · 1 comment

Comments

@ProTrent
Copy link

ProTrent commented Apr 2, 2016

I'm working on creating a style for the BackAnd API Style and I'm running into an issue on how it returns collections on requests. Is there a way to config the BelongsToMany/HasMany (or attrAsReferenceToMany) reader for all restmod 'HasMany'-like model references?

The default is to read from an array like:
[2,4]

But the references I get come in a comma delimited string like this:
"2,4"

I've already setup to read from 'data', but I need some pointers on setting up

Example:
{ "totalRows": 1, "data": [ { "id": 3, "AssociatedData": "4,2", "name": "TestName" } ] }

Model Definition:
return restmod.model('/MyObjects').mix({ AssociatedData: { belongsToMany: 'MyObject', keys: 'AssociatedData' } });

@utf4
Copy link

utf4 commented Nov 3, 2016

You can add computed function first on the AssociatedData element which can explode comma separated ids into an array. Once it is done then beongsToMany relationship will load its references from related data element. I know it is late but if you are still in need of the answer. I can share the code if you need it to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants