Skip to content

Commit

Permalink
Merge pull request #177 from hmsimple/fix-id-methods
Browse files Browse the repository at this point in the history
use _ids method instead of pluck to embed ids
  • Loading branch information
steveklabnik committed Dec 21, 2012
2 parents a74fc6c + be005c6 commit b5b3923
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/active_model/serializer/associations.rb
Expand Up @@ -109,8 +109,10 @@ def serializables
def serialize_ids
# Use pluck or select_columns if available
# return collection.ids if collection.respond_to?(:ids)
if !option(:include) && associated_object.respond_to?(:pluck)
associated_object.pluck(:id)
ids_key = "#{key.to_s.singularize}_ids"

if !option(:include) && source_serializer.object.respond_to?(ids_key)
source_serializer.object.send(ids_key)
else
associated_object.map do |item|
item.read_attribute_for_serialization(:id)
Expand Down

0 comments on commit b5b3923

Please sign in to comment.