Skip to content

Commit

Permalink
Always add :id to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Jun 5, 2012
1 parent 2139a6d commit 681bcf5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/generators/serializer/serializer_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create_serializer_file
private

def attributes_names
attributes.select { |attr| !attr.reference? }.map { |a| a.name.to_sym }
[:id] + attributes.select { |attr| !attr.reference? }.map { |a| a.name.to_sym }
end

def association_names
Expand Down
5 changes: 2 additions & 3 deletions lib/generators/serializer/templates/serializer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<% module_namespacing do -%>
class <%= class_name %>Serializer < <%= parent_class_name %>
<% if attributes.any? -%> attributes <%= attributes_names.map(&:inspect).join(", ") %>
<% end -%>
attributes <%= attributes_names.map(&:inspect).join(", ") %>
<% association_names.each do |attribute| -%>
has_one :<%= attribute %>
<% end -%>
end
<% end -%>
<% end -%>

1 comment on commit 681bcf5

@ahawkins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really do we have to do that? Wouldn't it be more correct to use an ApplicationSerializer superclass and declare it there? This is ActiveModel::Serializers. Not every ActiveModel class has a semantic use for ID. Seems to me this is more important for ActiveRecord. So now I have to go through all my non persisted classes and remove this attribute?

Please sign in to comment.