handle include param for as_json and to_xml
This commit is contained in:
@@ -150,6 +150,8 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
def as_json(options = {})
|
def as_json(options = {})
|
||||||
options ||= {}
|
options ||= {}
|
||||||
|
|
||||||
|
options[:include] ||= []
|
||||||
|
|
||||||
options[:except] ||= []
|
options[:except] ||= []
|
||||||
options[:except] += hidden_attributes
|
options[:except] += hidden_attributes
|
||||||
|
|
||||||
@@ -166,6 +168,7 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
|
|
||||||
if options[:only]
|
if options[:only]
|
||||||
options[:methods] = options[:methods] & options[:only]
|
options[:methods] = options[:methods] & options[:only]
|
||||||
|
options[:include] = options[:include] & options[:only]
|
||||||
end
|
end
|
||||||
|
|
||||||
super(options)
|
super(options)
|
||||||
@@ -174,6 +177,8 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
def to_xml(options = {}, &block)
|
def to_xml(options = {}, &block)
|
||||||
options ||= {}
|
options ||= {}
|
||||||
|
|
||||||
|
options[:include] ||= []
|
||||||
|
|
||||||
options[:except] ||= []
|
options[:except] ||= []
|
||||||
options[:except] += hidden_attributes
|
options[:except] += hidden_attributes
|
||||||
|
|
||||||
@@ -190,6 +195,7 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
|
|
||||||
if options[:only]
|
if options[:only]
|
||||||
options[:methods] = options[:methods] & options[:only]
|
options[:methods] = options[:methods] & options[:only]
|
||||||
|
options[:include] = options[:include] & options[:only]
|
||||||
end
|
end
|
||||||
|
|
||||||
super(options, &block)
|
super(options, &block)
|
||||||
|
|||||||
Reference in New Issue
Block a user