def to_hash
      serialized_attributes = attributes.dup

      self.class.expandable_attributes.each_pair.select do |attribute_name, expanded_class|
        if expanded_class === attributes[attribute_name]
          serialized_attributes[attribute_name] = serialized_attributes[attribute_name].id
        end
      end

      serialized_attributes
    end
def to_hash
      serialized_attributes = attributes.dup

      self.class.expandable_attributes.each_pair.select do |attribute_name, expanded_class|
        if expanded_class === attributes[attribute_name]
          serialized_attributes[attribute_name] = serialized_attributes[attribute_name].id
        end
      end

      serialized_attributes
    end
Attributes used for serialization