-
Notifications
You must be signed in to change notification settings - Fork 137
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
[JSON-API] Nested polymorphic representation #183
Comments
I have run into the same issue. I have a polymorphic relation: An I want to render the same properties for each account, but I need the Something like this: class AccountUserView < Roar::Decorator
include Roar::JSON::JSONAPI
type "account-users"
property :id
property :another_property
has_one :account do
type { |account| account.type } # <-- this must be variable depending on the type of account
property :id
property :some_other_property
end
end Can this be done somehow? |
I have messed around in the roar code and solved this so that def type(name=nil, &block) @apotonick, if you think this is a good idea, I will make some tests and a proper pull request ;) |
The example @caseymct gives is more complicated, @lasseebert! You only need the I believe it takes a bit more work to cover both of the cases. |
@apotonick, yes I see now that my issue is not related at all to the original issue posted here, since dynamically deciding the E.g. in my above example code, I could have an The use case for this is pretty thin, so I'll take down my suggestion again ;) |
This issue was moved to trailblazer/roar-jsonapi#10 |
Trying to transition from a standard representer format to json-api. I have a model, Notification, that has a polymorphic
target
- it can be one of many different types. How would I write thisas a JSON-API compliant response? or can I? Somehow I need to set a
has_one
with a class that is determined byrepresentable_target
, then have the block return that target's data.The text was updated successfully, but these errors were encountered: