Skip to content

dynamic type #54

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

Closed
jamesdixon opened this issue Apr 16, 2018 · 11 comments
Closed

dynamic type #54

jamesdixon opened this issue Apr 16, 2018 · 11 comments
Assignees

Comments

@jamesdixon
Copy link

jamesdixon commented Apr 16, 2018

Hi there,

I can see that it's possible to change the type dynamically by passing in a configuration to the serializer itself. Is this possible with relationships?

My use case is that I have a campaign model that has a relationship recipients. These recipients can be of type staff or customer.

Is this possible with the current implementation?

Thanks!

@danivek
Copy link
Owner

danivek commented Apr 18, 2018

Hi,

Dynamic relationships are not currently possible. But I don't see any particular problems of implementing it.

@jamesdixon
Copy link
Author

@danivek thanks. I'll submit a PR for this as soon as I get some time. Cheers

@jamesdixon
Copy link
Author

@danivek oh wow, just saw that you had submitted a PR for this. Thanks!

@danivek
Copy link
Owner

danivek commented Apr 24, 2018

@jamesdixon 😉. Can you give it a try and give me a feedback ? Thanks

@jamesdixon
Copy link
Author

jamesdixon commented Apr 24, 2018 via email

@jamesdixon
Copy link
Author

@danivek sorry for the delay on testing this!

Is it possible to allow the function access to the entire record? Unfortunately, the id doesn't give me enough information to set the type dynamically.

For example, my campaign record has a type field, which can be either staff or customer. That field is what I'd like to use in order to set the type property on the response.

Thanks!

@jamesdixon
Copy link
Author

@danivek wanted to see if you had any thoughts on the above? Thank you!

@danivek
Copy link
Owner

danivek commented May 25, 2018

@jamesdixon you’re right ! I will change this to allow the entire record to be passed to the type resolver function.

Thank you for your feedback !

@jamesdixon
Copy link
Author

Thanks, @danivek! Much appreciated 👍

@danivek
Copy link
Owner

danivek commented May 28, 2018

Now the type resolver function has 2 arguments function(relationshipData, data) { ... }
Can you give it a try ?

Thanks @jamesdixon

@jamesdixon
Copy link
Author

works beautifully! thx @danivek

@danivek danivek closed this as completed in ed162e2 Jun 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants