Problem when passing String element to activeRecord.find_by
fanantoxa opened this issue · 4 comments
el = Saxerator::Builder::StringElement.new("somestring")
SomeModel.find_by!(some_tag: el)
# I'll failt and not pass string
# but if
SomeModel.find_by!(some_tag: el.to_s)
# It'll work fine
So the problem is here:
https://github.com/rails/rails/blob/92703a9ea5d8b96f30e0b706b801c9185ef14f0e/activerecord/lib/active_record/relation/where_clause_factory.rb
Since we use Delegation we can't pass to where directly.
@soulcutter What do you think about it?
Should we do something to fix it or just update doc that StringElement !=String
I don't think the problem is in where_clause_factory.rb there - that's detecting where("foo = true")
sort of strings. It actually DOES work, it just doesn't do what you might expect if you think it's a String
- it serializes it into yaml (unsure where that code is in ActiveRecord, though I looked for a bit).
Anyway, I don't think we should do a lot of work to make it a String
. It's totally fair to document that it does not return a ruby String
, and that you should convert it if that's what you want.
@soulcutter ok then. I'll update a doc with this notice ))
Update Readme with warning that sax not return ruby objects like String
, Hash
and Array
and have to convert before use.
Updated readme