-
Notifications
You must be signed in to change notification settings - Fork 91
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
data object within relationships object #47
Comments
Interesting...I looked through the code again too and I think you are probably right. I just pushed 63e1132 to a branch named |
Actually, it's probably something else, the line you referenced: Probably back to the drawing board here. |
I'll try your branch right now - thanks |
Have you implemented a custom |
Yes I am! Here is my base serializer which the others extend from. class BaseSerializer
include JSONAPI::Serializer
def base_url
ENV['API_HOST']
end
# By default, attribute names are dasherized per the spec naming recommendations, but
# we prefer to keep them underscores so that it's the same from front to back
def format_name(attribute_name)
attribute_name
end
# The opposite of format_name.
def unformat_name(attribute_name)
attribute_name
end
end |
It works! Thank you very much for your help - sorry that it did indeed turn out to be user error. class BaseSerializer
include JSONAPI::Serializer
def base_url
ENV['API_HOST']
end
# By default, attribute names are dasherized per the spec naming recommendations, but
# we prefer to keep them underscores so that it's the same from front to back
def format_name(attribute_name)
attribute_name.to_s
end
# The opposite of format_name.
def unformat_name(attribute_name)
attribute_name.to_s
end
end
|
Nice! That's an easy mistake to make, so we should just fix it by converting internally. Going to leave this open for that. |
Hello Mike,
First, thank you for this gem. I tried several before yours and this has been by far the best implementation and the easiest to work with.
I'm not entirely sure if this is user error, or a bug. But I am unable to get the data object within the relationships object to appear (as per your example output pasted below). I have tried referencing child objects as a
has_one :tutorial
andhas_many :tutorials
, and have been sure to include them withinclude: ['tutorials']
. I do get a relationships object, but it only contains links (no data object). Theincluded
object is coming back properly and contains the expected data.I checked out the gem source, and have started walking through the code. There are a few places where it seems that the symbol
:tutorial
might be incorrectly compared to the string'tutorial'
?https://github.com/fotinakis/jsonapi-serializers/blob/master/lib/jsonapi-serializers/serializer.rb#L104
(
@_include_linkages = ['tutorials]
butformatted_attribute_name = :tutorials
)Am I missing something obvious and this should in fact work?
Thanks very much
The text was updated successfully, but these errors were encountered: