Moderate has_many and has_one associations
parent
76ba4d22de
commit
539883ec67
|
@ -43,14 +43,29 @@ module TheModerator
|
||||||
|
|
||||||
def moderate_association(assoc, moderated_attributes)
|
def moderate_association(assoc, moderated_attributes)
|
||||||
assoc_fields = {}
|
assoc_fields = {}
|
||||||
send(assoc).each do |resource|
|
objects = send(assoc)
|
||||||
if respond_to?("#{assoc}_attributes=")
|
|
||||||
data = resource.moderation_data(*moderated_attributes)
|
if respond_to?("#{assoc}_attributes=")
|
||||||
assoc_fields[resource.id] = data.merge(id: resource.id) unless data.empty?
|
if objects.is_a?(Array)
|
||||||
|
assoc_fields = moderate_has_many_association(objects, moderated_attributes)
|
||||||
|
else
|
||||||
|
data = objects.moderation_data(*moderated_attributes)
|
||||||
|
assoc_fields = data.merge(id: objects.id) unless data.empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
assoc_fields
|
assoc_fields
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def moderate_has_many_association(objects, moderated_attributes)
|
||||||
|
assoc_fields = {}
|
||||||
|
|
||||||
|
objects.each do |resource|
|
||||||
|
data = resource.moderation_data(*moderated_attributes)
|
||||||
|
assoc_fields[resource.id] = data.merge(id: resource.id) unless data.empty?
|
||||||
|
end
|
||||||
|
|
||||||
|
assoc_fields
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue