Skip to content

Commit

Permalink
bugfix: fixing sorting of extended fields when dealing with mutiple t…
Browse files Browse the repository at this point in the history
…opic types. Should sort from ancestor->child properly now.
  • Loading branch information
Kieran Pilkington committed Oct 23, 2009
1 parent 301edb2 commit 8000c94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 1 addition & 3 deletions app/models/topic.rb
Expand Up @@ -199,9 +199,7 @@ def to_i
# All available extended field mappings for this topic instance, including those from ancestors
# of our TopicType.
def all_field_mappings
topic_type.topic_type_to_field_mappings.find(:all, :order => 'position ASC') + topic_type.ancestors.collect { |a| a.topic_type_to_field_mappings }.flatten
rescue
[]
topic_type.all_field_mappings
end

end
16 changes: 16 additions & 0 deletions app/models/topic_type.rb
Expand Up @@ -40,4 +40,20 @@ def <<(required_form_field)
def available_fields
@available_fields = ExtendedField.find_available_fields(self,'TopicType')
end

def self_and_ancestors_ids
@self_and_ancestors_ids ||= self_and_ancestors.collect { |a| a.id }
end

# MySQL ordering doesn't work well here so we do our own ordering
def all_field_mappings
@all_field_mappings ||= begin
mappings = TopicTypeToFieldMapping.find_all_by_topic_type_id(self_and_ancestors_ids, :order => 'position ASC')
self_and_ancestors_ids.collect do |id|
mappings.select { |mapping| mapping.topic_type_id == id }
end.flatten
end
rescue
[]
end
end

0 comments on commit 8000c94

Please sign in to comment.