Permalink
Browse files

start adding in support for HABTM

  • Loading branch information...
1 parent adf7fc5 commit 7d03210d0532403d4184e4e57be5664f6f99b0a3 @jackdempsey jackdempsey committed with Sep 19, 2010
Showing with 12 additions and 3 deletions.
  1. +12 −3 lib/rails_admin/active_record_support.rb
@@ -49,6 +49,12 @@ def destroy_all!
end
end
+ def has_and_belongs_to_many_associations
+ associations.select do |association|
+ association[:type] == :has_and_belongs_to_many
+ end
+ end
+
def has_many_associations
associations.select do |association|
association[:type] == :has_many
@@ -106,8 +112,9 @@ def association_parent_model_lookup(association)
case association.macro
when :belongs_to
association.klass
- when :has_one, :has_many, :has_and_belongs_to_many
+ when :has_one, :has_many
association.active_record
+ when :has_and_belongs_to_many
else
raise "Unknown association type: #{association.macro.inspect}"
end
@@ -121,8 +128,9 @@ def association_child_model_lookup(association)
case association.macro
when :belongs_to
association.active_record
- when :has_one, :has_many, :has_and_belongs_to_many
+ when :has_one, :has_many
association.klass
+ when :has_and_belongs_to_many
else
raise "Unknown association type: #{association.macro.inspect}"
end
@@ -132,8 +140,9 @@ def association_child_key_lookup(association)
case association.macro
when :belongs_to
["#{association.class_name.underscore}_id".to_sym]
- when :has_one, :has_many, :has_and_belongs_to_many
+ when :has_one, :has_many
[association.primary_key_name.to_sym]
+ when :has_and_belongs_to_many
else
raise "Unknown association type: #{association.macro.inspect}"
end

0 comments on commit 7d03210

Please sign in to comment.