-
Notifications
You must be signed in to change notification settings - Fork 18
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 #10
Comments
From @lasseebert on April 15, 2016 8:40 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? |
From @lasseebert on April 15, 2016 9:23 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 ;) |
From @apotonick on April 16, 2016 2:29 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. |
From @lasseebert on April 17, 2016 20:45 @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 ;) |
Any news on this topic ? Polymorphism is mandatory in any non basic api. (and I don't say that because I'm working on a huge/urgent project that needs this feature 😅) |
From @caseymct on January 22, 2016 2:22
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.Copied from original issue: trailblazer/roar#183
The text was updated successfully, but these errors were encountered: