-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Replace has_one with attribute in template #822
Conversation
@@ -3,6 +3,6 @@ class <%= class_name %>Serializer < <%= parent_class_name %> | |||
attributes <%= attributes_names.map(&:inspect).join(", ") %> | |||
end | |||
<% association_names.each do |attribute| -%> | |||
has_one :<%= attribute %> | |||
attribute :<%= attribute %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it should be belongs_to
, not attribute
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you say so. There's basically no usage tests around this code. Would you like me to change it?
The generator defines association_names as
def association_names
attributes.select { |attr| attr.reference? }.map { |a| a.name.to_sym }
end
# Defines an association in the object that should be rendered.
#
# The serializer object should implement the association name
# as a method which should return an object when invoked. If a method
# with the association name does not exist, the association name is
# dispatched to the serialized object.
def self.belongs_to(*attrs)
associate(:belongs_to, attrs)
end
Whereas attribute
def self.attribute(attr, options = {})
key = options.fetch(:key, attr)
@_attributes.concat [key]
define_method key do
object.read_attribute_for_serialization(attr)
end unless method_defined?(key)
end
I'm not really sure where reference?
comes from. Seems to be a schema definition for a has_many
, no?
Nevermind. I misread this PR before. |
Replace has_one with attribute in template
Thanks!
|
Yes, definitely. |
per rails-api#822 since it was readded in rails-api#725
Done |
per rails-api#822 since it was readded in rails-api#725
has_one is no longer supported
this way we generate valid templates