soulcutter / saxerator

A SAX-based XML parser for parsing large files into manageable chunks
MIT License
128 stars 19 forks source link

Problem when passing String element to activeRecord.find_by #52

Closed fanantoxa closed 7 years ago

fanantoxa commented 7 years ago
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

soulcutter commented 7 years ago

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.

fanantoxa commented 7 years ago

@soulcutter ok then. I'll update a doc with this notice ))

fanantoxa commented 7 years ago

Update Readme with warning that sax not return ruby objects like String, Hash and Array and have to convert before use.

fanantoxa commented 7 years ago

Updated readme