提交 d341d166 编写于 作者: J José Valim

Merge pull request #1344 from jmileham/serialization_includes

AR Serialization shouldn't fall back to base opts for includes
......@@ -31,9 +31,6 @@ def serializable_hash(options = nil)
def serializable_add_includes(options = {})
return unless include_associations = options.delete(:include)
base_only_or_except = { :except => options[:except],
:only => options[:only] }
include_has_options = include_associations.is_a?(Hash)
associations = include_has_options ? include_associations.keys : Array.wrap(include_associations)
......@@ -46,9 +43,8 @@ def serializable_add_includes(options = {})
end
if records
association_options = include_has_options ? include_associations[association] : base_only_or_except
opts = options.merge(association_options)
yield(association, records, opts)
association_options = include_has_options ? include_associations[association] : {}
yield(association, records, association_options)
end
end
......
......@@ -161,6 +161,15 @@ def test_includes_fetches_nth_level_associations
assert_match %r{"tag":\{"name":"General"\}}, json
end
def test_includes_doesnt_merge_opts_from_base
json = @david.to_json(
:only => :id,
:include => :posts
)
assert_match %{"title":"Welcome to the weblog"}, json
end
def test_should_not_call_methods_on_associations_that_dont_respond
def @david.favorite_quote; "Constraints are liberating"; end
json = @david.to_json(:include => :posts, :methods => :favorite_quote)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册