Closed wyattisimo closed 11 years ago
Thank you sir.
Pulled into master.
I discovered that this commit is revealing a problem in Origin::Selector
. If a field is defined as an Array, the evolve
method recurses down to individual array elements and causes them to be coerced to arrays themselves.
For example, the following query (where the location
field is defined as an array):
Places.find_by(location: [73, 40])
produces the following selector:
{"$query"=>{"location"=>[[73], [40]]}}
Would it be a good idea to stop recursion when value
and serializer.type
are both arrays?
see: https://github.com/mongoid/origin/blob/master/lib/origin/selector.rb#L104-L113
@durran Not sure if you saw my comment from 2 months ago. Should I open a new pull request?
Yeah sorry, been all over the place. Please a new pull would be great or I'll get this fixed.
Other field values seem to coerce to their specified field type, but Array does not.
If
person.name
is specified as type String, thenperson.name = 75
results in"75"
.If
person.fake_names
is specified as type Array, thenperson.fake_names = "Jim"
results in"Jim"
, but the expected result should be["Jim"]
.NOTE: On line 160, you could alternatively do something like
evolve(object.split(/\s*,\s*/)) rescue evolve([object])
to make it assume that strings containing commas should be split into separate array elements. I did not include it in this pull request because it may be an unnecessary assumption.