1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Merge pull request #759 from tubaxenor/patch-1

Relation#all is deprecated in Rails 4, use Relation#to_a instead

Conflicts:
	test/support/models.rb
This commit is contained in:
Carlos Antonio da Silva 2013-05-09 21:08:38 -03:00
parent c4c8c5c905
commit a52b3f32bd
2 changed files with 34 additions and 10 deletions

View file

@ -180,7 +180,7 @@ module SimpleForm
options[:as] ||= :select
options[:collection] ||= options.fetch(:collection) {
reflection.klass.all(reflection.options.slice(:conditions, :order))
reflection.klass.where(reflection.options[:conditions]).order(reflection.options[:order]).to_a
}
attribute = case reflection.macro

View file

@ -7,20 +7,37 @@ Column = Struct.new(:name, :type, :limit) do
end
end
class RelationArray < Array
def order(order='')
return [last] if order.present?
self
end
end
Company = Struct.new(:id, :name) do
extend ActiveModel::Naming
include ActiveModel::Conversion
def self.all(options={})
all = (1..3).map { |i| Company.new(i, "Company #{i}") }
def self.where(conditions={})
return RelationArray.new([all.first]) if conditions.present?
all
end
if options[:conditions]
[all.first]
elsif options[:order]
[all.last]
else
all
end
def self.includes(includes=[])
return RelationArray.new([all[0..1]]) if includes.present?
all
end
def self.joins(joins=[])
return RelationArray.new([all[1..2]]) if joins.present?
all
end
###just simple Relation#all
def self.all
all = RelationArray.new
(1..3).map{|i| all << Company.new(i, "Company #{i}")}
all
end
def persisted?
@ -32,6 +49,13 @@ class Tag < Company
def self.all(options={})
(1..3).map { |i| Tag.new(i, "Tag #{i}") }
end
def self.where(conditions={})
all = RelationArray.new
(1..3).map{|i| all << Tag.new(i, "Tag #{i}")}
return RelationArray.new(all.first) if conditions.present?
all
end
end
TagGroup = Struct.new(:id, :name, :tags)