Permalink
Browse files

fix for habtm Mongoid style (keys in arrays)

  • Loading branch information...
1 parent 8b737f7 commit b31adc341e0c4d42b32f9be96772ff467230f145 @bbenezech bbenezech committed Nov 23, 2012
Showing with 3 additions and 3 deletions.
  1. +1 −1 lib/rails_admin/config/fields/factories/association.rb
  2. +2 −2 spec/unit/config/fields_spec.rb
@@ -3,7 +3,7 @@
require 'rails_admin/config/fields/types/belongs_to_association'
RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
- if association = parent.abstract_model.associations.find {|a| a[:foreign_key] == properties[:name] && a[:type] == :belongs_to }
+ if association = parent.abstract_model.associations.find {|a| a[:foreign_key] == properties[:name] && [:belongs_to, :has_and_belongs_to_many].include?(a[:type]) }
field = RailsAdmin::Config::Fields::Types.load("#{association[:polymorphic] ? :polymorphic : association[:type]}_association").new(parent, association[:name], association)
fields << field
@@ -3,13 +3,13 @@
describe RailsAdmin::Config::Fields, :mongoid => true do
describe '.factory for self.referentials belongs_to' do
it 'associates belongs_to _id foreign_key to a belongs_to association' do
- class MongoBlog
+ class MongoTree
include Mongoid::Document
has_many :children, :class_name => self.name, :foreign_key => :parent_id
belongs_to :parent, :class_name => self.name
end
- expect(RailsAdmin.config(MongoBlog).fields.find{ |f| f.name == :parent }.type ).to eq :belongs_to_association
+ expect(RailsAdmin.config(MongoTree).fields.find{ |f| f.name == :parent }.type ).to eq :belongs_to_association
end
end
end

0 comments on commit b31adc3

Please sign in to comment.