Assuming your filter takes an hash as init param, you can do this.
class FilterArray < Array
def self.from_mongo(value)
value.map do |item|
Filter.new(item)
end
end
end
> --
> You received this message because you are subscribed to the Google
> Groups "MongoMapper" group.
> For more options, visit this group at
> http://groups.google.com/group/mongomapper?hl=en?hl=en
key :filters, Array, :typcast => 'Filter'
Other than that I don't see any reason why it shouldn't work. This is
what I do with Money attributes:
http://github.com/tjtuom/mm-money/blob/master/lib/mm-money.rb. I have
those ifs there cause for some reason the methods get called multiple
times and stuff that has been returned by to_mongo get passed again to
to_mongo. Also remember you might get nil passed into both methods.
- Toni
http://github.com/jnunemaker/mongomapper/blob/master/examples/keys.rb
I'm assuming that since John has put the typecast on an Array key in
the examples it is a valid approach.
- Toni